diff options
| author | Serhiy Storchaka <storchaka@gmail.com> | 2015-01-18 22:36:33 +0200 |
|---|---|---|
| committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-01-18 22:36:33 +0200 |
| commit | 5f38f5c5028d5c015e67ffa8463bf42c66ad2e05 (patch) | |
| tree | 1e06dd83a544f25e81de0c1d562efa1e65df786e /Lib/test | |
| parent | 3b225d8bfb748a02d4bada14d4498e9b6aa4e162 (diff) | |
| download | cpython-git-5f38f5c5028d5c015e67ffa8463bf42c66ad2e05.tar.gz | |
Issue #23133: Pickling of ipaddress objects now produces more compact and
portable representation.
Diffstat (limited to 'Lib/test')
| -rw-r--r-- | Lib/test/test_ipaddress.py | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py index 1fbd2d5323..02028bfe65 100644 --- a/Lib/test/test_ipaddress.py +++ b/Lib/test/test_ipaddress.py @@ -8,6 +8,7 @@ import unittest import re import contextlib import operator +import pickle import ipaddress @@ -82,6 +83,13 @@ class CommonTestMixin: self.assertRaises(TypeError, hex, self.factory(1)) self.assertRaises(TypeError, bytes, self.factory(1)) + def pickle_test(self, addr): + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + with self.subTest(proto=proto): + x = self.factory(addr) + y = pickle.loads(pickle.dumps(x, proto)) + self.assertEqual(y, x) + class CommonTestMixin_v4(CommonTestMixin): @@ -247,6 +255,9 @@ class AddressTestCase_v4(BaseTestCase, CommonTestMixin_v4): assertBadOctet("257.0.0.0", 257) assertBadOctet("192.168.0.999", 999) + def test_pickle(self): + self.pickle_test('192.0.2.1') + class AddressTestCase_v6(BaseTestCase, CommonTestMixin_v6): factory = ipaddress.IPv6Address @@ -379,6 +390,9 @@ class AddressTestCase_v6(BaseTestCase, CommonTestMixin_v6): assertBadPart("02001:db8::", "02001") assertBadPart('2001:888888::1', "888888") + def test_pickle(self): + self.pickle_test('2001:db8::') + class NetmaskTestMixin_v4(CommonTestMixin_v4): """Input validation on interfaces and networks is very similar""" @@ -446,6 +460,11 @@ class NetmaskTestMixin_v4(CommonTestMixin_v4): class InterfaceTestCase_v4(BaseTestCase, NetmaskTestMixin_v4): factory = ipaddress.IPv4Interface + def test_pickle(self): + self.pickle_test('192.0.2.0/27') + self.pickle_test('192.0.2.0/31') # IPV4LENGTH - 1 + self.pickle_test('192.0.2.0') # IPV4LENGTH + class NetworkTestCase_v4(BaseTestCase, NetmaskTestMixin_v4): factory = ipaddress.IPv4Network @@ -500,6 +519,11 @@ class NetmaskTestMixin_v6(CommonTestMixin_v6): assertBadNetmask("::1", "pudding") assertBadNetmask("::", "::") + def test_pickle(self): + self.pickle_test('2001:db8::1000/124') + self.pickle_test('2001:db8::1000/127') # IPV6LENGTH - 1 + self.pickle_test('2001:db8::1000') # IPV6LENGTH + class InterfaceTestCase_v6(BaseTestCase, NetmaskTestMixin_v6): factory = ipaddress.IPv6Interface @@ -774,13 +798,6 @@ class IpaddrUnitTest(unittest.TestCase): self.assertEqual(128, ipaddress._count_righthand_zero_bits(0, 128)) self.assertEqual("IPv4Network('1.2.3.0/24')", repr(self.ipv4_network)) - def testMissingAddressVersion(self): - class Broken(ipaddress._BaseAddress): - pass - broken = Broken('127.0.0.1') - with self.assertRaisesRegex(NotImplementedError, "Broken.*version"): - broken.version - def testMissingNetworkVersion(self): class Broken(ipaddress._BaseNetwork): pass |
