blob: d74f300f48f5294fb98c6862b1228590f14aebe0 [file] [log] [blame]
Neil Schemenauerfd288c72001-01-02 16:30:31 +00001import sys
2
3from test_support import *
4
5class Empty:
6 def __repr__(self):
7 return '<Empty>'
8
9class Coerce:
10 def __init__(self, arg):
11 self.arg = arg
12
13 def __repr__(self):
14 return '<Coerce %s>' % self.arg
15
16 def __coerce__(self, other):
17 if isinstance(other, Coerce):
18 return self.arg, other.arg
19 else:
20 return (self.arg, other)
21
22class Cmp:
23 def __init__(self,arg):
24 self.arg = arg
25
26 def __repr__(self):
27 return '<Cmp %s>' % self.arg
28
29 def __cmp__(self, other):
30 return cmp(self.arg, other)
31
32class RCmp:
33 def __init__(self,arg):
34 self.arg = arg
35
36 def __repr__(self):
37 return '<RCmp %s>' % self.arg
38
39 def __rcmp__(self, other):
40 return cmp(other, self.arg)
41
42
43candidates = [2, 2.2, 2L, 2+4j, [1], (2,), None, Empty(), Coerce(3),
44 Cmp(4), RCmp(5)]
45
46def test():
47 for a in candidates:
48 for b in candidates:
49 print "cmp(%s, %s)" % (a, b),
50 try:
51 x = cmp(a, b)
52 except:
53 print '... %s' % sys.exc_info(0)
54 else:
55 print '=', x
56
57test()