summaryrefslogtreecommitdiff
path: root/Lib/test/test_ipaddress.py
diff options
context:
space:
mode:
authorInada Naoki <songofacandy@gmail.com>2019-04-16 08:32:28 +0900
committerGitHub <noreply@github.com>2019-04-16 08:32:28 +0900
commit6fa84bd12c4b83bee6a41b989363230d5c03b96c (patch)
tree846220dfd35742385323c4dc2742edc3b6ed7a29 /Lib/test/test_ipaddress.py
parent74125a60b7a477451ff2b8385bfbce3fdaee8dbc (diff)
downloadcpython-git-6fa84bd12c4b83bee6a41b989363230d5c03b96c.tar.gz
bpo-27860: ipaddress: fix Interface missed some attributes (GH-12836)
IPv4Interface and IPv6Interface did not has netmask and hostmask attributes when its argument is bytes or int. This commit extracts method for constructors of Network and Interface, and ensure Interface class always provides them.
Diffstat (limited to 'Lib/test/test_ipaddress.py')
-rw-r--r--Lib/test/test_ipaddress.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py
index 15317c9446..20316f15f8 100644
--- a/Lib/test/test_ipaddress.py
+++ b/Lib/test/test_ipaddress.py
@@ -399,7 +399,13 @@ class NetmaskTestMixin_v4(CommonTestMixin_v4):
"""Input validation on interfaces and networks is very similar"""
def test_no_mask(self):
- self.assertEqual(str(self.factory('1.2.3.4')), '1.2.3.4/32')
+ for address in ('1.2.3.4', 0x01020304, b'\x01\x02\x03\x04'):
+ net = self.factory(address)
+ self.assertEqual(str(net), '1.2.3.4/32')
+ self.assertEqual(str(net.netmask), '255.255.255.255')
+ self.assertEqual(str(net.hostmask), '0.0.0.0')
+ # IPv4Network has prefixlen, but IPv4Interface doesn't.
+ # Should we add it to IPv4Interface too? (bpo-36392)
def test_split_netmask(self):
addr = "1.2.3.4/32/24"
@@ -527,6 +533,15 @@ class NetworkTestCase_v4(BaseTestCase, NetmaskTestMixin_v4):
class NetmaskTestMixin_v6(CommonTestMixin_v6):
"""Input validation on interfaces and networks is very similar"""
+ def test_no_mask(self):
+ for address in ('::1', 1, b'\x00'*15 + b'\x01'):
+ net = self.factory(address)
+ self.assertEqual(str(net), '::1/128')
+ self.assertEqual(str(net.netmask), 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff')
+ self.assertEqual(str(net.hostmask), '::')
+ # IPv6Network has prefixlen, but IPv6Interface doesn't.
+ # Should we add it to IPv4Interface too? (bpo-36392)
+
def test_split_netmask(self):
addr = "cafe:cafe::/128/190"
with self.assertAddressError("Only one '/' permitted in %r" % addr):