Skip to content

Commit 0d20189

Browse files
committed
Merge: python#20973: add total ordering tests for ipaddress
2 parents 59ae8ec + 947ff38 commit 0d20189

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

‎Lib/test/test_ipaddress.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,16 @@ class ComparisonTests(unittest.TestCase):
587587
v4_objects = v4_addresses + [v4net]
588588
v6_addresses = [v6addr, v6intf]
589589
v6_objects = v6_addresses + [v6net]
590+
590591
objects = v4_objects + v6_objects
591592

593+
v4addr2 = ipaddress.IPv4Address(2)
594+
v4net2 = ipaddress.IPv4Network(2)
595+
v4intf2 = ipaddress.IPv4Interface(2)
596+
v6addr2 = ipaddress.IPv6Address(2)
597+
v6net2 = ipaddress.IPv6Network(2)
598+
v6intf2 = ipaddress.IPv6Interface(2)
599+
592600
def test_foreign_type_equality(self):
593601
# __eq__ should never raise TypeError directly
594602
other = object()
@@ -607,6 +615,31 @@ def test_mixed_type_equality(self):
607615
continue
608616
self.assertNotEqual(lhs, rhs)
609617

618+
def test_same_type_equality(self):
619+
for obj in self.objects:
620+
self.assertEqual(obj, obj)
621+
self.assertLessEqual(obj, obj)
622+
self.assertGreaterEqual(obj, obj)
623+
624+
def test_same_type_ordering(self):
625+
for lhs, rhs in (
626+
(self.v4addr, self.v4addr2),
627+
(self.v4net, self.v4net2),
628+
(self.v4intf, self.v4intf2),
629+
(self.v6addr, self.v6addr2),
630+
(self.v6net, self.v6net2),
631+
(self.v6intf, self.v6intf2),
632+
):
633+
self.assertNotEqual(lhs, rhs)
634+
self.assertLess(lhs, rhs)
635+
self.assertLessEqual(lhs, rhs)
636+
self.assertGreater(rhs, lhs)
637+
self.assertGreaterEqual(rhs, lhs)
638+
self.assertFalse(lhs > rhs)
639+
self.assertFalse(rhs < lhs)
640+
self.assertFalse(lhs >= rhs)
641+
self.assertFalse(rhs <= lhs)
642+
610643
def test_containment(self):
611644
for obj in self.v4_addresses:
612645
self.assertIn(obj, self.v4net)

‎Misc/ACKS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ Michael R Bax
102102
Anthony Baxter
103103
Mike Bayer
104104
Samuel L. Bayer
105+
Tommy Beadle
105106
Donald Beaudry
106107
David Beazley
107108
John Beck

0 commit comments

Comments
 (0)