diff options
| author | Bob Halley <halley@dnspython.org> | 2020-05-23 15:18:05 -0700 |
|---|---|---|
| committer | Bob Halley <halley@dnspython.org> | 2020-05-23 15:18:05 -0700 |
| commit | 33f3935fc3a0dd585a0b621bd42813b1f69a820f (patch) | |
| tree | 5f2a7cdf9ef8999d558cc2901486c1c82176bdf6 /tests/test_ntoaaton.py | |
| parent | 8bb39d33ff5bc834773ee8e83bc62c4daa9e4372 (diff) | |
| download | dnspython-33f3935fc3a0dd585a0b621bd42813b1f69a820f.tar.gz | |
increase test coverage for various things
Diffstat (limited to 'tests/test_ntoaaton.py')
| -rw-r--r-- | tests/test_ntoaaton.py | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/tests/test_ntoaaton.py b/tests/test_ntoaaton.py index ba6cc30..e1d8a15 100644 --- a/tests/test_ntoaaton.py +++ b/tests/test_ntoaaton.py @@ -71,6 +71,11 @@ class NtoAAtoNTestCase(unittest.TestCase): aton6('1:2:3:4:5:6:7:8:9') self.assertRaises(dns.exception.SyntaxError, bad) + def test_bad_aton4(self): + def bad(): + aton4('001.002.003.004') + self.assertRaises(dns.exception.SyntaxError, bad) + def test_aton6(self): a = aton6('::') self.assertEqual(a, b'\x00' * 16) @@ -159,14 +164,21 @@ class NtoAAtoNTestCase(unittest.TestCase): def test_bad_ntoa1(self): def bad(): - ntoa6('') + ntoa6(b'') self.assertRaises(ValueError, bad) def test_bad_ntoa2(self): def bad(): - ntoa6('\x00' * 17) + ntoa6(b'\x00' * 17) self.assertRaises(ValueError, bad) + def test_bad_ntoa3(self): + def bad(): + ntoa4(b'\x00' * 5) + # Ideally we'd have been consistent and raised ValueError as + # we do for IPv6, but oh well! + self.assertRaises(dns.exception.SyntaxError, bad) + def test_good_v4_aton(self): pairs = [('1.2.3.4', b'\x01\x02\x03\x04'), ('255.255.255.255', b'\xff\xff\xff\xff'), @@ -226,6 +238,11 @@ class NtoAAtoNTestCase(unittest.TestCase): self.assertFalse(dns.inet.is_multicast(t5)) self.assertTrue(dns.inet.is_multicast(t6)) + def test_is_multicast_bad_input(self): + def bad(): + dns.inet.is_multicast('hello world') + self.assertRaises(ValueError, bad) + def test_ignore_scope(self): t1 = 'fe80::1%lo0' t2 = 'fe80::1' @@ -243,5 +260,20 @@ class NtoAAtoNTestCase(unittest.TestCase): aton6(t1, True) self.assertRaises(dns.exception.SyntaxError, bad) + def test_ptontop(self): + for (af, a) in [(dns.inet.AF_INET, '1.2.3.4'), + (dns.inet.AF_INET6, '2001:db8:0:1:1:1:1:1')]: + self.assertEqual(dns.inet.inet_ntop(af, dns.inet.inet_pton(af, a)), + a) + + def test_isaddress(self): + for (t, e) in [('1.2.3.4', True), + ('2001:db8:0:1:1:1:1:1', True), + ('hello world', False), + ('http://www.dnspython.org', False), + ('1.2.3.4a', False), + ('2001:db8:0:1:1:1:1:q1', False)]: + self.assertEqual(dns.inet.is_address(t), e) + if __name__ == '__main__': unittest.main() |
