bpo-37685: Fixed comparisons of datetime.timedelta and datetime.timezone. (GH-14996)

There was a discrepancy between the Python and C implementations.

Add singletons ALWAYS_EQ, LARGEST and SMALLEST in test.support
to test mixed type comparison.
This commit is contained in:
Serhiy Storchaka 2019-08-04 12:38:46 +03:00 committed by GitHub
parent 5c72badd06
commit 17e52649c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 107 additions and 84 deletions

View file

@ -12,6 +12,7 @@ import operator
import pickle
import ipaddress
import weakref
from test.support import LARGEST, SMALLEST
class BaseTestCase(unittest.TestCase):
@ -673,20 +674,6 @@ class FactoryFunctionErrors(BaseTestCase):
self.assertFactoryError(ipaddress.ip_network, "network")
@functools.total_ordering
class LargestObject:
def __eq__(self, other):
return isinstance(other, LargestObject)
def __lt__(self, other):
return False
@functools.total_ordering
class SmallestObject:
def __eq__(self, other):
return isinstance(other, SmallestObject)
def __gt__(self, other):
return False
class ComparisonTests(unittest.TestCase):
v4addr = ipaddress.IPv4Address(1)
@ -775,8 +762,6 @@ class ComparisonTests(unittest.TestCase):
def test_foreign_type_ordering(self):
other = object()
smallest = SmallestObject()
largest = LargestObject()
for obj in self.objects:
with self.assertRaises(TypeError):
obj < other
@ -786,14 +771,14 @@ class ComparisonTests(unittest.TestCase):
obj <= other
with self.assertRaises(TypeError):
obj >= other
self.assertTrue(obj < largest)
self.assertFalse(obj > largest)
self.assertTrue(obj <= largest)
self.assertFalse(obj >= largest)
self.assertFalse(obj < smallest)
self.assertTrue(obj > smallest)
self.assertFalse(obj <= smallest)
self.assertTrue(obj >= smallest)
self.assertTrue(obj < LARGEST)
self.assertFalse(obj > LARGEST)
self.assertTrue(obj <= LARGEST)
self.assertFalse(obj >= LARGEST)
self.assertFalse(obj < SMALLEST)
self.assertTrue(obj > SMALLEST)
self.assertFalse(obj <= SMALLEST)
self.assertTrue(obj >= SMALLEST)
def test_mixed_type_key(self):
# with get_mixed_type_key, you can sort addresses and network.