diff options
Diffstat (limited to 'Lib/test/datetimetester.py')
-rw-r--r-- | Lib/test/datetimetester.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 2f8975d..5814417 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -53,6 +53,19 @@ OTHERSTUFF = (10, 34.5, "abc", {}, [], ()) INF = float("inf") NAN = float("nan") + +class ComparesEqualClass(object): + """ + A class that is always equal to whatever you compare it to. + """ + + def __eq__(self, other): + return True + + def __ne__(self, other): + return False + + ############################################################################# # module tests @@ -399,6 +412,13 @@ class HarmlessMixedComparison: self.assertIn(me, [1, 20, [], me]) self.assertIn([], [me, 1, 20, []]) + # Comparison to objects of unsupported types should return + # NotImplemented which falls back to the right hand side's __eq__ + # method. In this case, ComparesEqualClass.__eq__ always returns True. + # ComparesEqualClass.__ne__ always returns False. + self.assertTrue(me == ComparesEqualClass()) + self.assertFalse(me != ComparesEqualClass()) + def test_harmful_mixed_comparison(self): me = self.theclass(1, 1, 1) |