import operator
import ipaddress
+
class BaseTestCase(unittest.TestCase):
# One big change in ipaddress over the original ipaddr module is
# error reporting that tries to assume users *don't know the rules*
def assertAddressError(self, details, *args):
"""Ensure a clean AddressValueError"""
return self.assertCleanError(ipaddress.AddressValueError,
- details, *args)
+ details, *args)
def assertNetmaskError(self, details, *args):
"""Ensure a clean NetmaskValueError"""
return self.assertCleanError(ipaddress.NetmaskValueError,
- details, *args)
+ details, *args)
def assertInstancesEqual(self, lhs, rhs):
"""Check constructor arguments produce equivalent instances"""
self.assertEqual(self.factory(lhs), self.factory(rhs))
+
class CommonTestMixin:
def test_empty_address(self):
assertBadLength(3)
assertBadLength(5)
+
class CommonTestMixin_v6(CommonTestMixin):
def test_leading_zeros(self):
def test_empty_octet(self):
def assertBadOctet(addr):
with self.assertAddressError("Empty octet not permitted in %r",
- addr):
+ addr):
ipaddress.IPv4Address(addr)
assertBadOctet("42..42.42")
class InterfaceTestCase_v4(BaseTestCase, NetmaskTestMixin_v4):
factory = ipaddress.IPv4Interface
+
class NetworkTestCase_v4(BaseTestCase, NetmaskTestMixin_v4):
factory = ipaddress.IPv4Network
assertBadNetmask("::1", "pudding")
assertBadNetmask("::", "::")
+
class InterfaceTestCase_v6(BaseTestCase, NetmaskTestMixin_v6):
factory = ipaddress.IPv6Interface
+
class NetworkTestCase_v6(BaseTestCase, NetmaskTestMixin_v6):
factory = ipaddress.IPv6Network
self.assertRaises(TypeError, v6net.__gt__, v4net)
-
class IpaddrUnitTest(unittest.TestCase):
def setUp(self):