summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_ipaddress.py
diff options
context:
space:
mode:
authorXiang Zhang <angwerzx@126.com>2018-03-21 00:25:13 (GMT)
committerGitHub <noreply@github.com>2018-03-21 00:25:13 (GMT)
commit10b134a07c898c2fbc5fd3582503680a54ed80a2 (patch)
tree32ce163bf6c42d52dcbf62a6479de258c014ea04 /Lib/test/test_ipaddress.py
parent5609b78392d59c7362ef8aa5c4a4529325f01f27 (diff)
downloadcpython-10b134a07c898c2fbc5fd3582503680a54ed80a2.zip
cpython-10b134a07c898c2fbc5fd3582503680a54ed80a2.tar.gz
cpython-10b134a07c898c2fbc5fd3582503680a54ed80a2.tar.bz2
bpo-27683: Fix a regression for host() of ipaddress network objects (GH-6016)
The result of host() was not empty when the network is constructed by a tuple containing an integer mask and only 1 bit left for addresses.
Diffstat (limited to 'Lib/test/test_ipaddress.py')
-rw-r--r--Lib/test/test_ipaddress.py26
1 files changed, 23 insertions, 3 deletions
diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py
index a5aeb79..0e0753f 100644
--- a/Lib/test/test_ipaddress.py
+++ b/Lib/test/test_ipaddress.py
@@ -1127,10 +1127,30 @@ class IpaddrUnitTest(unittest.TestCase):
self.assertEqual(ipaddress.IPv4Address('1.2.3.1'), hosts[0])
self.assertEqual(ipaddress.IPv4Address('1.2.3.254'), hosts[-1])
+ ipv6_network = ipaddress.IPv6Network('2001:658:22a:cafe::/120')
+ hosts = list(ipv6_network.hosts())
+ self.assertEqual(255, len(hosts))
+ self.assertEqual(ipaddress.IPv6Address('2001:658:22a:cafe::1'), hosts[0])
+ self.assertEqual(ipaddress.IPv6Address('2001:658:22a:cafe::ff'), hosts[-1])
+
# special case where only 1 bit is left for address
- self.assertEqual([ipaddress.IPv4Address('2.0.0.0'),
- ipaddress.IPv4Address('2.0.0.1')],
- list(ipaddress.ip_network('2.0.0.0/31').hosts()))
+ addrs = [ipaddress.IPv4Address('2.0.0.0'),
+ ipaddress.IPv4Address('2.0.0.1')]
+ str_args = '2.0.0.0/31'
+ tpl_args = ('2.0.0.0', 31)
+ self.assertEqual(addrs, list(ipaddress.ip_network(str_args).hosts()))
+ self.assertEqual(addrs, list(ipaddress.ip_network(tpl_args).hosts()))
+ self.assertEqual(list(ipaddress.ip_network(str_args).hosts()),
+ list(ipaddress.ip_network(tpl_args).hosts()))
+
+ addrs = [ipaddress.IPv6Address('2001:658:22a:cafe::'),
+ ipaddress.IPv6Address('2001:658:22a:cafe::1')]
+ str_args = '2001:658:22a:cafe::/127'
+ tpl_args = ('2001:658:22a:cafe::', 127)
+ self.assertEqual(addrs, list(ipaddress.ip_network(str_args).hosts()))
+ self.assertEqual(addrs, list(ipaddress.ip_network(tpl_args).hosts()))
+ self.assertEqual(list(ipaddress.ip_network(str_args).hosts()),
+ list(ipaddress.ip_network(tpl_args).hosts()))
def testFancySubnetting(self):
self.assertEqual(sorted(self.ipv4_network.subnets(prefixlen_diff=3)),