2
from test import support
9
def __init__(self,arg):
13
return '<Cmp %s>' % self.arg
15
def __eq__(self, other):
16
return self.arg == other
19
def __eq__(self, other):
22
def __ne__(self, other):
25
class ComparisonTest(unittest.TestCase):
26
set1 = [2, 2.0, 2, 2+0j, Cmp(2.0)]
27
set2 = [[1], (3,), None, Empty()]
28
candidates = set1 + set2
30
def test_comparisons(self):
31
for a in self.candidates:
32
for b in self.candidates:
33
if ((a in self.set1) and (b in self.set1)) or a is b:
34
self.assertEqual(a, b)
36
self.assertNotEqual(a, b)
38
def test_id_comparisons(self):
39
# Ensure default comparison compares id() of args
42
L.insert(len(L)//2, Empty())
45
self.assertEqual(a == b, id(a) == id(b),
46
'a=%r, b=%r' % (a, b))
48
def test_ne_defaults_to_not_eq(self):
51
self.assertTrue(a == b)
52
self.assertFalse(a != b)
54
def test_issue_1393(self):
56
self.assertEqual(x, Anything())
57
self.assertEqual(Anything(), x)
59
self.assertEqual(y, Anything())
60
self.assertEqual(Anything(), y)
64
support.run_unittest(ComparisonTest)
66
if __name__ == '__main__':