2 from test
import test_support
9 def __init__(self
, arg
):
13 return '<Coerce %s>' % self
.arg
15 def __coerce__(self
, other
):
16 if isinstance(other
, Coerce
):
17 return self
.arg
, other
.arg
19 return self
.arg
, other
22 def __init__(self
,arg
):
26 return '<Cmp %s>' % self
.arg
28 def __cmp__(self
, other
):
29 return cmp(self
.arg
, other
)
31 class ComparisonTest(unittest
.TestCase
):
32 set1
= [2, 2.0, 2L, 2+0j
, Coerce(2), Cmp(2.0)]
33 set2
= [[1], (3,), None, Empty()]
34 candidates
= set1
+ set2
36 def test_comparisons(self
):
37 for a
in self
.candidates
:
38 for b
in self
.candidates
:
39 if ((a
in self
.set1
) and (b
in self
.set1
)) or a
is b
:
40 self
.assertEqual(a
, b
)
42 self
.assertNotEqual(a
, b
)
44 def test_id_comparisons(self
):
45 # Ensure default comparison compares id() of args
48 L
.insert(len(L
)//2, Empty())
51 self
.assertEqual(cmp(a
, b
), cmp(id(a
), id(b
)),
52 'a=%r, b=%r' % (a
, b
))
55 test_support
.run_unittest(ComparisonTest
)
57 if __name__
== '__main__':