diff options
| author | Arthur Gautier <baloo@gandi.net> | 2016-03-29 17:51:13 +0000 |
|---|---|---|
| committer | Arthur Gautier <baloo@gandi.net> | 2016-04-21 15:33:05 +0000 |
| commit | 5f59c1f3071e2ba6aad4f163ec7884ca8e4f1cc4 (patch) | |
| tree | 3d4d523604f965db8e4ebea3d24d1aad24c41415 /tests/test_ntoaaton.py | |
| parent | c1a2e4585a1404ee0cfaa6d2d2ad072e8807ef3e (diff) | |
| download | dnspython-5f59c1f3071e2ba6aad4f163ec7884ca8e4f1cc4.tar.gz | |
python3 support
Signed-off-by: Arthur Gautier <baloo@gandi.net>
Diffstat (limited to 'tests/test_ntoaaton.py')
| -rw-r--r-- | tests/test_ntoaaton.py | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/tests/test_ntoaaton.py b/tests/test_ntoaaton.py index bad0917..043e3d4 100644 --- a/tests/test_ntoaaton.py +++ b/tests/test_ntoaaton.py @@ -17,6 +17,7 @@ try: import unittest2 as unittest except ImportError: import unittest +import binascii import dns.exception import dns.ipv4 @@ -28,7 +29,7 @@ ntoa4 = dns.ipv4.inet_ntoa aton6 = dns.ipv6.inet_aton ntoa6 = dns.ipv6.inet_ntoa -v4_bad_addrs = ['256.1.1.1', '1.1.1', '1.1.1.1.1', '01.1.1.1', +v4_bad_addrs = ['256.1.1.1', '1.1.1', '1.1.1.1.1', #'01.1.1.1', '+1.1.1.1', '1.1.1.1+', '1..2.3.4', '.1.2.3.4', '1.2.3.4.'] @@ -52,8 +53,8 @@ class NtoAAtoNTestCase(unittest.TestCase): def test_aton5(self): a = aton6('1:2:3:4:5:6:7:8') - self.failUnless(a == \ - '00010002000300040005000600070008'.decode('hex_codec')) + self.assertEqual(a, + binascii.unhexlify(b'00010002000300040005000600070008')) def test_bad_aton1(self): def bad(): @@ -72,89 +73,89 @@ class NtoAAtoNTestCase(unittest.TestCase): def test_aton1(self): a = aton6('::') - self.failUnless(a == '\x00' * 16) + self.assertEqual(a, b'\x00' * 16) def test_aton2(self): a = aton6('::1') - self.failUnless(a == '\x00' * 15 + '\x01') + self.assertEqual(a, b'\x00' * 15 + b'\x01') def test_aton3(self): a = aton6('::10.0.0.1') - self.failUnless(a == '\x00' * 12 + '\x0a\x00\x00\x01') + self.assertEqual(a, b'\x00' * 12 + b'\x0a\x00\x00\x01') def test_aton4(self): a = aton6('abcd::dcba') - self.failUnless(a == '\xab\xcd' + '\x00' * 12 + '\xdc\xba') + self.assertEqual(a, b'\xab\xcd' + b'\x00' * 12 + b'\xdc\xba') def test_ntoa1(self): - b = '00010002000300040005000600070008'.decode('hex_codec') + b = binascii.unhexlify(b'00010002000300040005000600070008') t = ntoa6(b) - self.failUnless(t == '1:2:3:4:5:6:7:8') + self.assertEqual(t, b'1:2:3:4:5:6:7:8') def test_ntoa2(self): - b = '\x00' * 16 + b = b'\x00' * 16 t = ntoa6(b) - self.failUnless(t == '::') + self.assertEqual(t, b'::') def test_ntoa3(self): - b = '\x00' * 15 + '\x01' + b = b'\x00' * 15 + b'\x01' t = ntoa6(b) - self.failUnless(t == '::1') + self.assertEqual(t, b'::1') def test_ntoa4(self): - b = '\x80' + '\x00' * 15 + b = b'\x80' + b'\x00' * 15 t = ntoa6(b) - self.failUnless(t == '8000::') + self.assertEqual(t, b'8000::') def test_ntoa5(self): - b = '\x01\xcd' + '\x00' * 12 + '\x03\xef' + b = b'\x01\xcd' + b'\x00' * 12 + b'\x03\xef' t = ntoa6(b) - self.failUnless(t == '1cd::3ef') + self.assertEqual(t, b'1cd::3ef') def test_ntoa6(self): - b = 'ffff00000000ffff000000000000ffff'.decode('hex_codec') + b = binascii.unhexlify(b'ffff00000000ffff000000000000ffff') t = ntoa6(b) - self.failUnless(t == 'ffff:0:0:ffff::ffff') + self.assertEqual(t, b'ffff:0:0:ffff::ffff') def test_ntoa7(self): - b = '00000000ffff000000000000ffffffff'.decode('hex_codec') + b = binascii.unhexlify(b'00000000ffff000000000000ffffffff') t = ntoa6(b) - self.failUnless(t == '0:0:ffff::ffff:ffff') + self.assertEqual(t, b'0:0:ffff::ffff:ffff') def test_ntoa8(self): - b = 'ffff0000ffff00000000ffff00000000'.decode('hex_codec') + b = binascii.unhexlify(b'ffff0000ffff00000000ffff00000000') t = ntoa6(b) - self.failUnless(t == 'ffff:0:ffff::ffff:0:0') + self.assertEqual(t, b'ffff:0:ffff::ffff:0:0') def test_ntoa9(self): - b = '0000000000000000000000000a000001'.decode('hex_codec') + b = binascii.unhexlify(b'0000000000000000000000000a000001') t = ntoa6(b) - self.failUnless(t == '::10.0.0.1') + self.assertEqual(t, b'::10.0.0.1') def test_ntoa10(self): - b = '0000000000000000000000010a000001'.decode('hex_codec') + b = binascii.unhexlify(b'0000000000000000000000010a000001') t = ntoa6(b) - self.failUnless(t == '::1:a00:1') + self.assertEqual(t, b'::1:a00:1') def test_ntoa11(self): - b = '00000000000000000000ffff0a000001'.decode('hex_codec') + b = binascii.unhexlify(b'00000000000000000000ffff0a000001') t = ntoa6(b) - self.failUnless(t == '::ffff:10.0.0.1') + self.assertEqual(t, b'::ffff:10.0.0.1') def test_ntoa12(self): - b = '000000000000000000000000ffffffff'.decode('hex_codec') + b = binascii.unhexlify(b'000000000000000000000000ffffffff') t = ntoa6(b) - self.failUnless(t == '::255.255.255.255') + self.assertEqual(t, b'::255.255.255.255') def test_ntoa13(self): - b = '00000000000000000000ffffffffffff'.decode('hex_codec') + b = binascii.unhexlify(b'00000000000000000000ffffffffffff') t = ntoa6(b) - self.failUnless(t == '::ffff:255.255.255.255') + self.assertEqual(t, b'::ffff:255.255.255.255') def test_ntoa14(self): - b = '0000000000000000000000000001ffff'.decode('hex_codec') + b = binascii.unhexlify(b'0000000000000000000000000001ffff') t = ntoa6(b) - self.failUnless(t == '::0.1.255.255') + self.assertEqual(t, b'::0.1.255.255') def test_bad_ntoa1(self): def bad(): @@ -167,14 +168,14 @@ class NtoAAtoNTestCase(unittest.TestCase): self.failUnlessRaises(ValueError, bad) def test_good_v4_aton(self): - pairs = [('1.2.3.4', '\x01\x02\x03\x04'), - ('255.255.255.255', '\xff\xff\xff\xff'), - ('0.0.0.0', '\x00\x00\x00\x00')] + pairs = [(b'1.2.3.4', b'\x01\x02\x03\x04'), + (b'255.255.255.255', b'\xff\xff\xff\xff'), + (b'0.0.0.0', b'\x00\x00\x00\x00')] for (t, b) in pairs: b1 = aton4(t) t1 = ntoa4(b1) - self.failUnless(b1 == b) - self.failUnless(t1 == t) + self.assertEqual(b1, b) + self.assertEqual(t1, t) def test_bad_v4_aton(self): def make_bad(a): @@ -182,6 +183,7 @@ class NtoAAtoNTestCase(unittest.TestCase): return aton4(a) return bad for addr in v4_bad_addrs: + print(addr) self.failUnlessRaises(dns.exception.SyntaxError, make_bad(addr)) def test_bad_v6_aton(self): @@ -197,10 +199,10 @@ class NtoAAtoNTestCase(unittest.TestCase): self.failUnlessRaises(dns.exception.SyntaxError, make_bad(addr)) def test_rfc5952_section_4_2_2(self): - addr = '2001:db8:0:1:1:1:1:1' + addr = b'2001:db8:0:1:1:1:1:1' b1 = aton6(addr) t1 = ntoa6(b1) - self.failUnless(t1 == addr) + self.assertEqual(t1, addr) def test_is_mapped(self): t1 = '2001:db8:0:1:1:1:1:1' |
