|
10 | 10 | import operator |
11 | 11 | import ipaddress |
12 | 12 |
|
| 13 | + |
13 | 14 | class BaseTestCase(unittest.TestCase): |
14 | 15 | # One big change in ipaddress over the original ipaddr module is |
15 | 16 | # error reporting that tries to assume users *don't know the rules* |
@@ -52,17 +53,18 @@ def assertCleanError(self, exc_type, details, *args): |
52 | 53 | def assertAddressError(self, details, *args): |
53 | 54 | """Ensure a clean AddressValueError""" |
54 | 55 | return self.assertCleanError(ipaddress.AddressValueError, |
55 | | - details, *args) |
| 56 | + details, *args) |
56 | 57 |
|
57 | 58 | def assertNetmaskError(self, details, *args): |
58 | 59 | """Ensure a clean NetmaskValueError""" |
59 | 60 | return self.assertCleanError(ipaddress.NetmaskValueError, |
60 | | - details, *args) |
| 61 | + details, *args) |
61 | 62 |
|
62 | 63 | def assertInstancesEqual(self, lhs, rhs): |
63 | 64 | """Check constructor arguments produce equivalent instances""" |
64 | 65 | self.assertEqual(self.factory(lhs), self.factory(rhs)) |
65 | 66 |
|
| 67 | + |
66 | 68 | class CommonTestMixin: |
67 | 69 |
|
68 | 70 | def test_empty_address(self): |
@@ -115,6 +117,7 @@ def assertBadLength(length): |
115 | 117 | assertBadLength(3) |
116 | 118 | assertBadLength(5) |
117 | 119 |
|
| 120 | + |
118 | 121 | class CommonTestMixin_v6(CommonTestMixin): |
119 | 122 |
|
120 | 123 | def test_leading_zeros(self): |
@@ -195,7 +198,7 @@ def assertBadSplit(addr): |
195 | 198 | def test_empty_octet(self): |
196 | 199 | def assertBadOctet(addr): |
197 | 200 | with self.assertAddressError("Empty octet not permitted in %r", |
198 | | - addr): |
| 201 | + addr): |
199 | 202 | ipaddress.IPv4Address(addr) |
200 | 203 |
|
201 | 204 | assertBadOctet("42..42.42") |
@@ -443,6 +446,7 @@ def assertBadNetmask(addr, netmask): |
443 | 446 | class InterfaceTestCase_v4(BaseTestCase, NetmaskTestMixin_v4): |
444 | 447 | factory = ipaddress.IPv4Interface |
445 | 448 |
|
| 449 | + |
446 | 450 | class NetworkTestCase_v4(BaseTestCase, NetmaskTestMixin_v4): |
447 | 451 | factory = ipaddress.IPv4Network |
448 | 452 |
|
@@ -496,9 +500,11 @@ def assertBadNetmask(addr, netmask): |
496 | 500 | assertBadNetmask("::1", "pudding") |
497 | 501 | assertBadNetmask("::", "::") |
498 | 502 |
|
| 503 | + |
499 | 504 | class InterfaceTestCase_v6(BaseTestCase, NetmaskTestMixin_v6): |
500 | 505 | factory = ipaddress.IPv6Interface |
501 | 506 |
|
| 507 | + |
502 | 508 | class NetworkTestCase_v6(BaseTestCase, NetmaskTestMixin_v6): |
503 | 509 | factory = ipaddress.IPv6Network |
504 | 510 |
|
@@ -608,7 +614,6 @@ def test_incompatible_versions(self): |
608 | 614 | self.assertRaises(TypeError, v6net.__gt__, v4net) |
609 | 615 |
|
610 | 616 |
|
611 | | - |
612 | 617 | class IpaddrUnitTest(unittest.TestCase): |
613 | 618 |
|
614 | 619 | def setUp(self): |
|
0 commit comments