aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_compare.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_compare.py')
-rw-r--r--Lib/test/test_compare.py47
1 files changed, 28 insertions, 19 deletions
diff --git a/Lib/test/test_compare.py b/Lib/test/test_compare.py
index 13da80d2d4d..ee3794ae9a3 100644
--- a/Lib/test/test_compare.py
+++ b/Lib/test/test_compare.py
@@ -1,23 +1,10 @@
import unittest
-from test import test_support
+from test import support
class Empty:
def __repr__(self):
return '<Empty>'
-class Coerce:
- def __init__(self, arg):
- self.arg = arg
-
- def __repr__(self):
- return '<Coerce %s>' % self.arg
-
- def __coerce__(self, other):
- if isinstance(other, Coerce):
- return self.arg, other.arg
- else:
- return self.arg, other
-
class Cmp:
def __init__(self,arg):
self.arg = arg
@@ -25,11 +12,18 @@ class Cmp:
def __repr__(self):
return '<Cmp %s>' % self.arg
- def __cmp__(self, other):
- return cmp(self.arg, other)
+ def __eq__(self, other):
+ return self.arg == other
+
+class Anything:
+ def __eq__(self, other):
+ return True
+
+ def __ne__(self, other):
+ return False
class ComparisonTest(unittest.TestCase):
- set1 = [2, 2.0, 2L, 2+0j, Coerce(2), Cmp(2.0)]
+ set1 = [2, 2.0, 2, 2+0j, Cmp(2.0)]
set2 = [[1], (3,), None, Empty()]
candidates = set1 + set2
@@ -48,11 +42,26 @@ class ComparisonTest(unittest.TestCase):
L.insert(len(L)//2, Empty())
for a in L:
for b in L:
- self.assertEqual(cmp(a, b), cmp(id(a), id(b)),
+ self.assertEqual(a == b, id(a) == id(b),
'a=%r, b=%r' % (a, b))
+ def test_ne_defaults_to_not_eq(self):
+ a = Cmp(1)
+ b = Cmp(1)
+ self.assertTrue(a == b)
+ self.assertFalse(a != b)
+
+ def test_issue_1393(self):
+ x = lambda: None
+ self.assertEqual(x, Anything())
+ self.assertEqual(Anything(), x)
+ y = object()
+ self.assertEqual(y, Anything())
+ self.assertEqual(Anything(), y)
+
+
def test_main():
- test_support.run_unittest(ComparisonTest)
+ support.run_unittest(ComparisonTest)
if __name__ == '__main__':
test_main()