Beispiel #1
0
    def test_lock_data(self):

        k = zkutil.lock_data('a')
        elts = k.split('-')

        self.assertEqual(3, len(elts))

        self.assertEqual('a', elts[0])
        self.assertTrue(net.is_ip4(elts[1]))
        self.assertEqual(os.getpid(), int(elts[2]))
    def test_lock_id(self):

        k = zkutil.lock_id('a')
        dd(k)
        elts = k.split('-')

        self.assertEqual(4, len(elts))

        self.assertEqual('a', elts[0])
        self.assertTrue(net.is_ip4(elts[1]))
        self.assertEqual(os.getpid(), int(elts[2]))
Beispiel #3
0
    def test_is_ip4_true(self):

        cases_ip4 = (
            '0.0.0.0',
            '0.0.0.1',
            '0.0.1.0',
            '0.1.0.0',
            '1.0.0.0',
            '127.0.0.1',
            '255.255.255.255',
        )

        for inp in cases_ip4:
            self.assertEqual(True, net.is_ip4(inp), inp)
    def test_is_ip4_true(self):

        cases_ip4 = (
            '0.0.0.0',
            '0.0.0.1',
            '0.0.1.0',
            '0.1.0.0',
            '1.0.0.0',

            '127.0.0.1',

            '255.255.255.255',
        )

        for inp in cases_ip4:
            self.assertEqual(True, net.is_ip4(inp), inp)
    def test_get_host_ip4(self):

        ips = net.get_host_ip4(iface_prefix='')
        self.assertNotEqual([], ips)

        for ip in ips:
            self.assertIsInstance(ip, str)
            self.assertTrue(net.is_ip4(ip))

        ips2 = net.get_host_ip4(exclude_prefix='')
        self.assertEqual([], ips2, 'exclude any')

        self.assertEqual(ips, net.get_host_ip4(
            exclude_prefix=[]), 'exclude nothing')

        self.assertEqual(ips, net.get_host_ip4(
            exclude_prefix=None), 'exclude nothing')
Beispiel #6
0
    def test_get_host_ip4(self):

        ips = net.get_host_ip4(iface_prefix='')
        self.assertNotEqual([], ips)

        for ip in ips:
            self.assertIsInstance(ip, str)
            self.assertTrue(net.is_ip4(ip))

        ips2 = net.get_host_ip4(exclude_prefix='')
        self.assertEqual([], ips2, 'exclude any')

        self.assertEqual(ips, net.get_host_ip4(exclude_prefix=[]),
                         'exclude nothing')

        self.assertEqual(ips, net.get_host_ip4(exclude_prefix=None),
                         'exclude nothing')
    def test_is_ip4_false(self):

        cases_not_ip4 = (
            None,
            True,
            False,
            1,
            0,
            '',
            '1',
            (),
            [],
            {},
            '1.',
            '1.1',
            '1.1.',
            '1.1.1',
            '1.1.1.',

            '.1.1.1',

            'x.1.1.1',
            '1.x.1.1',
            '1.1.x.1',
            '1.1.1.x',

            '1.1.1.1.',
            '.1.1.1.1',
            '1:1.1.1',
            '1:1:1.1',

            '256.1.1.1',
            '1.256.1.1',
            '1.1.256.1',
            '1.1.1.256',

            '1.1.1.1.',
            '1.1.1.1.1',
            '1.1.1.1.1.',
            '1.1.1.1.1.1',
        )

        for inp in cases_not_ip4:
            self.assertEqual(False, net.is_ip4(inp), inp)
Beispiel #8
0
    def test_is_ip4_false(self):

        cases_not_ip4 = (
            None,
            True,
            False,
            1,
            0,
            '',
            '1',
            (),
            [],
            {},
            '1.',
            '1.1',
            '1.1.',
            '1.1.1',
            '1.1.1.',
            '.1.1.1',
            'x.1.1.1',
            '1.x.1.1',
            '1.1.x.1',
            '1.1.1.x',
            '1.1.1.1.',
            '.1.1.1.1',
            '1:1.1.1',
            '1:1:1.1',
            '256.1.1.1',
            '1.256.1.1',
            '1.1.256.1',
            '1.1.1.256',
            '1.1.1.1.',
            '1.1.1.1.1',
            '1.1.1.1.1.',
            '1.1.1.1.1.1',
        )

        for inp in cases_not_ip4:
            self.assertEqual(False, net.is_ip4(inp), inp)
Beispiel #9
0
from pykit import net

if __name__ == '__main__':

    ip1 = '192.168.24.56'
    ip2 = '192.23.4.2.3.5'
    ip3 = 'dada'
    print net.is_ip4(ip1)
    print net.is_ip4(ip2)
    print net.is_ip4(ip3)