Skip to content

Commit 7168518

Browse files
committed
add tests
1 parent d83b56d commit 7168518

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

Lib/test/test_ipaddress.py

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,12 +2585,42 @@ def testExplodeShortHandIpStr(self):
25852585
self.assertEqual('192.168.178.1', addr4.exploded)
25862586

25872587
def testReversePointer(self):
2588-
addr1 = ipaddress.IPv4Address('127.0.0.1')
2589-
addr2 = ipaddress.IPv6Address('2001:db8::1')
2590-
self.assertEqual('1.0.0.127.in-addr.arpa', addr1.reverse_pointer)
2591-
self.assertEqual('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.' +
2592-
'b.d.0.1.0.0.2.ip6.arpa',
2593-
addr2.reverse_pointer)
2588+
for addr_v4, expected in [
2589+
('127.0.0.1', '1.0.0.127.in-addr.arpa'),
2590+
# test vector: https://www.rfc-editor.org/rfc/rfc1035, §3.5
2591+
('10.2.0.52', '52.0.2.10.in-addr.arpa'),
2592+
]:
2593+
with self.subTest('ipv4_reverse_pointer', addr=addr_v4):
2594+
addr = ipaddress.IPv4Address(addr_v4)
2595+
self.assertEqual(addr.reverse_pointer, expected)
2596+
2597+
for addr_v6, expected in [
2598+
(
2599+
'2001:db8::1', (
2600+
'1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.'
2601+
'0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.'
2602+
'ip6.arpa'
2603+
)
2604+
),
2605+
(
2606+
'::FFFF:192.168.1.35', (
2607+
'3.2.1.0.8.a.0.c.f.f.f.f.0.0.0.0.'
2608+
'0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.'
2609+
'ip6.arpa'
2610+
)
2611+
),
2612+
# test vector: https://www.rfc-editor.org/rfc/rfc3596, §2.5
2613+
(
2614+
'4321:0:1:2:3:4:567:89ab', (
2615+
'b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.'
2616+
'2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.'
2617+
'ip6.arpa'
2618+
)
2619+
)
2620+
]:
2621+
with self.subTest('ipv6_reverse_pointer', addr=addr_v6):
2622+
addr = ipaddress.IPv6Address(addr_v6)
2623+
self.assertEqual(addr.reverse_pointer, expected)
25942624

25952625
def testIntRepresentation(self):
25962626
self.assertEqual(16909060, int(self.ipv4_address))

0 commit comments

Comments
 (0)