diff options
author | R David Murray <rdmurray@bitdance.com> | 2016-06-02 19:46:04 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2016-06-02 19:46:04 (GMT) |
commit | 947ff3872520c5a05f3fcf4131d551347c9e546f (patch) | |
tree | 291f3d099d62c9d58465d096f030083f4e7a3598 /Lib/test/test_ipaddress.py | |
parent | f5854148138280c69fdc9d350636dc2140d57753 (diff) | |
download | cpython-947ff3872520c5a05f3fcf4131d551347c9e546f.zip cpython-947ff3872520c5a05f3fcf4131d551347c9e546f.tar.gz cpython-947ff3872520c5a05f3fcf4131d551347c9e546f.tar.bz2 |
#20973: add total ordering tests for ipaddress
Patch by Tommy Beadle.
Diffstat (limited to 'Lib/test/test_ipaddress.py')
-rw-r--r-- | Lib/test/test_ipaddress.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py index 643d742..3edea08 100644 --- a/Lib/test/test_ipaddress.py +++ b/Lib/test/test_ipaddress.py @@ -587,8 +587,16 @@ class ComparisonTests(unittest.TestCase): v4_objects = v4_addresses + [v4net] v6_addresses = [v6addr, v6intf] v6_objects = v6_addresses + [v6net] + objects = v4_objects + v6_objects + v4addr2 = ipaddress.IPv4Address(2) + v4net2 = ipaddress.IPv4Network(2) + v4intf2 = ipaddress.IPv4Interface(2) + v6addr2 = ipaddress.IPv6Address(2) + v6net2 = ipaddress.IPv6Network(2) + v6intf2 = ipaddress.IPv6Interface(2) + def test_foreign_type_equality(self): # __eq__ should never raise TypeError directly other = object() @@ -607,6 +615,31 @@ class ComparisonTests(unittest.TestCase): continue self.assertNotEqual(lhs, rhs) + def test_same_type_equality(self): + for obj in self.objects: + self.assertEqual(obj, obj) + self.assertLessEqual(obj, obj) + self.assertGreaterEqual(obj, obj) + + def test_same_type_ordering(self): + for lhs, rhs in ( + (self.v4addr, self.v4addr2), + (self.v4net, self.v4net2), + (self.v4intf, self.v4intf2), + (self.v6addr, self.v6addr2), + (self.v6net, self.v6net2), + (self.v6intf, self.v6intf2), + ): + self.assertNotEqual(lhs, rhs) + self.assertLess(lhs, rhs) + self.assertLessEqual(lhs, rhs) + self.assertGreater(rhs, lhs) + self.assertGreaterEqual(rhs, lhs) + self.assertFalse(lhs > rhs) + self.assertFalse(rhs < lhs) + self.assertFalse(lhs >= rhs) + self.assertFalse(rhs <= lhs) + def test_containment(self): for obj in self.v4_addresses: self.assertIn(obj, self.v4net) |