Exceptions raised during renaming in rotating file handlers are now passed to handleE...
[python.git] / Lib / test / test_compare.py
blob6899926facd1d782a3899481571174a5f34f0335
1 import sys
3 class Empty:
4 def __repr__(self):
5 return '<Empty>'
7 class Coerce:
8 def __init__(self, arg):
9 self.arg = arg
11 def __repr__(self):
12 return '<Coerce %s>' % self.arg
14 def __coerce__(self, other):
15 if isinstance(other, Coerce):
16 return self.arg, other.arg
17 else:
18 return self.arg, other
20 class Cmp:
21 def __init__(self,arg):
22 self.arg = arg
24 def __repr__(self):
25 return '<Cmp %s>' % self.arg
27 def __cmp__(self, other):
28 return cmp(self.arg, other)
31 candidates = [2, 2.0, 2L, 2+0j, [1], (3,), None, Empty(), Coerce(2), Cmp(2.0)]
33 def test():
34 for a in candidates:
35 for b in candidates:
36 try:
37 x = a == b
38 except:
39 print 'cmp(%s, %s) => %s' % (a, b, sys.exc_info()[0])
40 else:
41 if x:
42 print "%s == %s" % (a, b)
43 else:
44 print "%s != %s" % (a, b)
45 # Ensure default comparison compares id() of args
46 L = []
47 for i in range(10):
48 L.insert(len(L)//2, Empty())
49 for a in L:
50 for b in L:
51 if cmp(a, b) != cmp(id(a), id(b)):
52 print "ERROR:", cmp(a, b), cmp(id(a), id(b)), id(a), id(b)
54 test()