annotate Lib/test/test_coercion.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents 7527da2b05e8
children 2dc0b7131c72 6768b2350c57
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15687
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
1 import copy
23069
bbab3a17b4cf Reduce the number of test-suite DeprecationWarnings; start adding
Tim Peters <tim.peters@gmail.com>
parents: 15699
diff changeset
2 import warnings
37277
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
3 import unittest
38809
ece8a6751db7 Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed.
Brett Cannon <bcannon@gmail.com>
parents: 37307
diff changeset
4 from test.test_support import run_unittest, TestFailed
15687
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
5
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
6 # Fake a number that implements numeric methods through __coerce__
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
7 class CoerceNumber:
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
8 def __init__(self, arg):
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
9 self.arg = arg
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
10
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
11 def __repr__(self):
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
12 return '<CoerceNumber %s>' % repr(self.arg)
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
13
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
14 def __coerce__(self, other):
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
15 if isinstance(other, CoerceNumber):
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
16 return self.arg, other.arg
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
17 else:
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
18 return (self.arg, other)
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
19
37277
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
20 # New-style class version of CoerceNumber
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
21 class CoerceTo(object):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
22 def __init__(self, arg):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
23 self.arg = arg
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
24 def __coerce__(self, other):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
25 if isinstance(other, CoerceTo):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
26 return self.arg, other.arg
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
27 else:
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
28 return self.arg, other
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
29
15687
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
30
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
31 # Fake a number that implements numeric ops through methods.
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
32 class MethodNumber:
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
33 def __init__(self,arg):
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
34 self.arg = arg
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
35
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
36 def __repr__(self):
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
37 return '<MethodNumber %s>' % repr(self.arg)
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
38
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
39 def __add__(self,other):
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
40 return self.arg + other
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
41
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
42 def __radd__(self,other):
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
43 return other + self.arg
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
44
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
45 def __sub__(self,other):
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
46 return self.arg - other
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
47
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
48 def __rsub__(self,other):
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
49 return other - self.arg
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
50
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
51 def __mul__(self,other):
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
52 return self.arg * other
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
53
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
54 def __rmul__(self,other):
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
55 return other * self.arg
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
56
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
57 def __div__(self,other):
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
58 return self.arg / other
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
59
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
60 def __rdiv__(self,other):
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
61 return other / self.arg
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
62
37277
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
63 def __truediv__(self,other):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
64 return self.arg / other
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
65
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
66 def __rtruediv__(self,other):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
67 return other / self.arg
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
68
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
69 def __floordiv__(self,other):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
70 return self.arg // other
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
71
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
72 def __rfloordiv__(self,other):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
73 return other // self.arg
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
74
15687
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
75 def __pow__(self,other):
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
76 return self.arg ** other
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
77
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
78 def __rpow__(self,other):
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
79 return other ** self.arg
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
80
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
81 def __mod__(self,other):
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
82 return self.arg % other
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
83
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
84 def __rmod__(self,other):
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
85 return other % self.arg
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
86
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
87 def __cmp__(self, other):
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
88 return cmp(self.arg, other)
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
89
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
90
37277
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
91 candidates = [2, 2L, 4.0, 2+0j, [1], (2,), None,
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
92 MethodNumber(2), CoerceNumber(2)]
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
93
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
94 infix_binops = [ '+', '-', '*', '**', '%', '//', '/' ]
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
95
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
96 TE = TypeError
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
97 # b = both normal and augmented give same result list
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
98 # s = single result lists for normal and augmented
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
99 # e = equals other results
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
100 # result lists: ['+', '-', '*', '**', '%', '//', ('classic /', 'new /')]
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
101 # ^^^^^^^^^^^^^^^^^^^^^^
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
102 # 2-tuple if results differ
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
103 # else only one value
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
104 infix_results = {
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
105 # 2
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
106 (0,0): ('b', [4, 0, 4, 4, 0, 1, (1, 1.0)]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
107 (0,1): ('e', (0,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
108 (0,2): ('b', [6.0, -2.0, 8.0, 16.0, 2.0, 0.0, 0.5]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
109 (0,3): ('b', [4+0j, 0+0j, 4+0j, 4+0j, 0+0j, 1+0j, 1+0j]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
110 (0,4): ('b', [TE, TE, [1, 1], TE, TE, TE, TE]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
111 (0,5): ('b', [TE, TE, (2, 2), TE, TE, TE, TE]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
112 (0,6): ('b', [TE, TE, TE, TE, TE, TE, TE]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
113 (0,7): ('e', (0,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
114 (0,8): ('e', (0,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
115
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
116 # 2L
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
117 (1,0): ('e', (0,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
118 (1,1): ('e', (0,1)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
119 (1,2): ('e', (0,2)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
120 (1,3): ('e', (0,3)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
121 (1,4): ('e', (0,4)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
122 (1,5): ('e', (0,5)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
123 (1,6): ('e', (0,6)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
124 (1,7): ('e', (0,7)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
125 (1,8): ('e', (0,8)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
126
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
127 # 4.0
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
128 (2,0): ('b', [6.0, 2.0, 8.0, 16.0, 0.0, 2.0, 2.0]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
129 (2,1): ('e', (2,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
130 (2,2): ('b', [8.0, 0.0, 16.0, 256.0, 0.0, 1.0, 1.0]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
131 (2,3): ('b', [6+0j, 2+0j, 8+0j, 16+0j, 0+0j, 2+0j, 2+0j]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
132 (2,4): ('b', [TE, TE, TE, TE, TE, TE, TE]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
133 (2,5): ('e', (2,4)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
134 (2,6): ('e', (2,4)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
135 (2,7): ('e', (2,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
136 (2,8): ('e', (2,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
137
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
138 # (2+0j)
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
139 (3,0): ('b', [4+0j, 0+0j, 4+0j, 4+0j, 0+0j, 1+0j, 1+0j]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
140 (3,1): ('e', (3,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
141 (3,2): ('b', [6+0j, -2+0j, 8+0j, 16+0j, 2+0j, 0+0j, 0.5+0j]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
142 (3,3): ('b', [4+0j, 0+0j, 4+0j, 4+0j, 0+0j, 1+0j, 1+0j]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
143 (3,4): ('b', [TE, TE, TE, TE, TE, TE, TE]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
144 (3,5): ('e', (3,4)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
145 (3,6): ('e', (3,4)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
146 (3,7): ('e', (3,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
147 (3,8): ('e', (3,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
148
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
149 # [1]
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
150 (4,0): ('b', [TE, TE, [1, 1], TE, TE, TE, TE]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
151 (4,1): ('e', (4,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
152 (4,2): ('b', [TE, TE, TE, TE, TE, TE, TE]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
153 (4,3): ('b', [TE, TE, TE, TE, TE, TE, TE]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
154 (4,4): ('b', [[1, 1], TE, TE, TE, TE, TE, TE]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
155 (4,5): ('s', [TE, TE, TE, TE, TE, TE, TE], [[1, 2], TE, TE, TE, TE, TE, TE]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
156 (4,6): ('b', [TE, TE, TE, TE, TE, TE, TE]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
157 (4,7): ('e', (4,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
158 (4,8): ('e', (4,0)),
15687
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
159
37277
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
160 # (2,)
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
161 (5,0): ('b', [TE, TE, (2, 2), TE, TE, TE, TE]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
162 (5,1): ('e', (5,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
163 (5,2): ('b', [TE, TE, TE, TE, TE, TE, TE]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
164 (5,3): ('e', (5,2)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
165 (5,4): ('e', (5,2)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
166 (5,5): ('b', [(2, 2), TE, TE, TE, TE, TE, TE]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
167 (5,6): ('b', [TE, TE, TE, TE, TE, TE, TE]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
168 (5,7): ('e', (5,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
169 (5,8): ('e', (5,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
170
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
171 # None
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
172 (6,0): ('b', [TE, TE, TE, TE, TE, TE, TE]),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
173 (6,1): ('e', (6,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
174 (6,2): ('e', (6,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
175 (6,3): ('e', (6,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
176 (6,4): ('e', (6,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
177 (6,5): ('e', (6,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
178 (6,6): ('e', (6,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
179 (6,7): ('e', (6,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
180 (6,8): ('e', (6,0)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
181
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
182 # MethodNumber(2)
37307
e58a71a8550e whitespace normalisation
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37277
diff changeset
183 (7,0): ('e', (0,0)),
37277
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
184 (7,1): ('e', (0,1)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
185 (7,2): ('e', (0,2)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
186 (7,3): ('e', (0,3)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
187 (7,4): ('e', (0,4)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
188 (7,5): ('e', (0,5)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
189 (7,6): ('e', (0,6)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
190 (7,7): ('e', (0,7)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
191 (7,8): ('e', (0,8)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
192
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
193 # CoerceNumber(2)
37307
e58a71a8550e whitespace normalisation
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37277
diff changeset
194 (8,0): ('e', (0,0)),
37277
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
195 (8,1): ('e', (0,1)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
196 (8,2): ('e', (0,2)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
197 (8,3): ('e', (0,3)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
198 (8,4): ('e', (0,4)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
199 (8,5): ('e', (0,5)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
200 (8,6): ('e', (0,6)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
201 (8,7): ('e', (0,7)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
202 (8,8): ('e', (0,8)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
203 }
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
204
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
205 def process_infix_results():
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
206 for key in sorted(infix_results):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
207 val = infix_results[key]
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
208 if val[0] == 'e':
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
209 infix_results[key] = infix_results[val[1]]
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
210 else:
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
211 if val[0] == 's':
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
212 res = (val[1], val[2])
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
213 elif val[0] == 'b':
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
214 res = (val[1], val[1])
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
215 for i in range(1):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
216 if isinstance(res[i][6], tuple):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
217 if 1/2 == 0:
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
218 # testing with classic (floor) division
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
219 res[i][6] = res[i][6][0]
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
220 else:
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
221 # testing with -Qnew
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
222 res[i][6] = res[i][6][1]
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
223 infix_results[key] = res
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
224
37307
e58a71a8550e whitespace normalisation
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37277
diff changeset
225
e58a71a8550e whitespace normalisation
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37277
diff changeset
226
37277
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
227 process_infix_results()
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
228 # now infix_results has two lists of results for every pairing.
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
229
15687
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
230 prefix_binops = [ 'divmod' ]
37277
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
231 prefix_results = [
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
232 [(1,0), (1L,0L), (0.0,2.0), ((1+0j),0j), TE, TE, TE, TE, (1,0)],
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
233 [(1L,0L), (1L,0L), (0.0,2.0), ((1+0j),0j), TE, TE, TE, TE, (1L,0L)],
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
234 [(2.0,0.0), (2.0,0.0), (1.0,0.0), ((2+0j),0j), TE, TE, TE, TE, (2.0,0.0)],
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
235 [((1+0j),0j), ((1+0j),0j), (0j,(2+0j)), ((1+0j),0j), TE, TE, TE, TE, ((1+0j),0j)],
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
236 [TE, TE, TE, TE, TE, TE, TE, TE, TE],
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
237 [TE, TE, TE, TE, TE, TE, TE, TE, TE],
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
238 [TE, TE, TE, TE, TE, TE, TE, TE, TE],
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
239 [TE, TE, TE, TE, TE, TE, TE, TE, TE],
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
240 [(1,0), (1L,0L), (0.0,2.0), ((1+0j),0j), TE, TE, TE, TE, (1,0)]
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
241 ]
15687
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
242
31637
1253f6e20cde Make test_coercion.py less sensitive to platform fp quirks. Closes
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 24442
diff changeset
243 def format_float(value):
1253f6e20cde Make test_coercion.py less sensitive to platform fp quirks. Closes
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 24442
diff changeset
244 if abs(value) < 0.01:
1253f6e20cde Make test_coercion.py less sensitive to platform fp quirks. Closes
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 24442
diff changeset
245 return '0.0'
1253f6e20cde Make test_coercion.py less sensitive to platform fp quirks. Closes
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 24442
diff changeset
246 else:
1253f6e20cde Make test_coercion.py less sensitive to platform fp quirks. Closes
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 24442
diff changeset
247 return '%.1f' % value
1253f6e20cde Make test_coercion.py less sensitive to platform fp quirks. Closes
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 24442
diff changeset
248
1253f6e20cde Make test_coercion.py less sensitive to platform fp quirks. Closes
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 24442
diff changeset
249 # avoid testing platform fp quirks
1253f6e20cde Make test_coercion.py less sensitive to platform fp quirks. Closes
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 24442
diff changeset
250 def format_result(value):
1253f6e20cde Make test_coercion.py less sensitive to platform fp quirks. Closes
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 24442
diff changeset
251 if isinstance(value, complex):
1253f6e20cde Make test_coercion.py less sensitive to platform fp quirks. Closes
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 24442
diff changeset
252 return '(%s + %sj)' % (format_float(value.real),
1253f6e20cde Make test_coercion.py less sensitive to platform fp quirks. Closes
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 24442
diff changeset
253 format_float(value.imag))
1253f6e20cde Make test_coercion.py less sensitive to platform fp quirks. Closes
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 24442
diff changeset
254 elif isinstance(value, float):
1253f6e20cde Make test_coercion.py less sensitive to platform fp quirks. Closes
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 24442
diff changeset
255 return format_float(value)
1253f6e20cde Make test_coercion.py less sensitive to platform fp quirks. Closes
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 24442
diff changeset
256 return str(value)
1253f6e20cde Make test_coercion.py less sensitive to platform fp quirks. Closes
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 24442
diff changeset
257
37277
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
258 class CoercionTest(unittest.TestCase):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
259 def test_infix_binops(self):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
260 for ia, a in enumerate(candidates):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
261 for ib, b in enumerate(candidates):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
262 results = infix_results[(ia, ib)]
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
263 for op, res, ires in zip(infix_binops, results[0], results[1]):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
264 if res is TE:
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
265 self.assertRaises(TypeError, eval,
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
266 'a %s b' % op, {'a': a, 'b': b})
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
267 else:
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
268 self.assertEquals(format_result(res),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
269 format_result(eval('a %s b' % op)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
270 '%s %s %s == %s failed' % (a, op, b, res))
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
271 try:
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
272 z = copy.copy(a)
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
273 except copy.Error:
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
274 z = a # assume it has no inplace ops
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
275 if ires is TE:
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
276 try:
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
277 exec 'z %s= b' % op
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
278 except TypeError:
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
279 pass
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
280 else:
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
281 self.fail("TypeError not raised")
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
282 else:
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
283 exec('z %s= b' % op)
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
284 self.assertEquals(ires, z)
15687
e8f5e61a8b94 Add more tests for compare and coercion in preparation for the coercion
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff changeset
285
37277
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
286 def test_prefix_binops(self):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
287 for ia, a in enumerate(candidates):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
288 for ib, b in enumerate(candidates):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
289 for op in prefix_binops:
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
290 res = prefix_results[ia][ib]
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
291 if res is TE:
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
292 self.assertRaises(TypeError, eval,
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
293 '%s(a, b)' % op, {'a': a, 'b': b})
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
294 else:
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
295 self.assertEquals(format_result(res),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
296 format_result(eval('%s(a, b)' % op)),
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
297 '%s(%s, %s) == %s failed' % (op, a, b, res))
34248
86c3a7c6b00a Dima Dorfman's patch for coercion/comparison of C types (patch #995939), with
Armin Rigo <arigo@tunes.org>
parents: 31637
diff changeset
298
37277
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
299 def test_cmptypes(self):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
300 # Built-in tp_compare slots expect their arguments to have the
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
301 # same type, but a user-defined __coerce__ doesn't have to obey.
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
302 # SF #980352
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
303 evil_coercer = CoerceTo(42)
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
304 # Make sure these don't crash any more
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
305 self.assertNotEquals(cmp(u'fish', evil_coercer), 0)
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
306 self.assertNotEquals(cmp(slice(1), evil_coercer), 0)
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
307 # ...but that this still works
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
308 class WackyComparer(object):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
309 def __cmp__(slf, other):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
310 self.assert_(other == 42, 'expected evil_coercer, got %r' % other)
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
311 return 0
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 45468
diff changeset
312 __hash__ = None # Invalid cmp makes this unhashable
37277
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
313 self.assertEquals(cmp(WackyComparer(), evil_coercer), 0)
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
314 # ...and classic classes too, since that code path is a little different
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
315 class ClassicWackyComparer:
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
316 def __cmp__(slf, other):
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
317 self.assert_(other == 42, 'expected evil_coercer, got %r' % other)
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
318 return 0
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
319 self.assertEquals(cmp(ClassicWackyComparer(), evil_coercer), 0)
34248
86c3a7c6b00a Dima Dorfman's patch for coercion/comparison of C types (patch #995939), with
Armin Rigo <arigo@tunes.org>
parents: 31637
diff changeset
320
38809
ece8a6751db7 Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed.
Brett Cannon <bcannon@gmail.com>
parents: 37307
diff changeset
321 def test_infinite_rec_classic_classes(self):
ece8a6751db7 Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed.
Brett Cannon <bcannon@gmail.com>
parents: 37307
diff changeset
322 # if __coerce__() returns its arguments reversed it causes an infinite
ece8a6751db7 Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed.
Brett Cannon <bcannon@gmail.com>
parents: 37307
diff changeset
323 # recursion for classic classes.
ece8a6751db7 Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed.
Brett Cannon <bcannon@gmail.com>
parents: 37307
diff changeset
324 class Tester:
ece8a6751db7 Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed.
Brett Cannon <bcannon@gmail.com>
parents: 37307
diff changeset
325 def __coerce__(self, other):
ece8a6751db7 Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed.
Brett Cannon <bcannon@gmail.com>
parents: 37307
diff changeset
326 return other, self
ece8a6751db7 Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed.
Brett Cannon <bcannon@gmail.com>
parents: 37307
diff changeset
327
ece8a6751db7 Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed.
Brett Cannon <bcannon@gmail.com>
parents: 37307
diff changeset
328 exc = TestFailed("__coerce__() returning its arguments reverse "
ece8a6751db7 Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed.
Brett Cannon <bcannon@gmail.com>
parents: 37307
diff changeset
329 "should raise RuntimeError")
ece8a6751db7 Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed.
Brett Cannon <bcannon@gmail.com>
parents: 37307
diff changeset
330 try:
ece8a6751db7 Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed.
Brett Cannon <bcannon@gmail.com>
parents: 37307
diff changeset
331 Tester() + 1
ece8a6751db7 Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed.
Brett Cannon <bcannon@gmail.com>
parents: 37307
diff changeset
332 except (RuntimeError, TypeError):
ece8a6751db7 Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed.
Brett Cannon <bcannon@gmail.com>
parents: 37307
diff changeset
333 return
ece8a6751db7 Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed.
Brett Cannon <bcannon@gmail.com>
parents: 37307
diff changeset
334 except:
ece8a6751db7 Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed.
Brett Cannon <bcannon@gmail.com>
parents: 37307
diff changeset
335 raise exc
ece8a6751db7 Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed.
Brett Cannon <bcannon@gmail.com>
parents: 37307
diff changeset
336 else:
ece8a6751db7 Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed.
Brett Cannon <bcannon@gmail.com>
parents: 37307
diff changeset
337 raise exc
ece8a6751db7 Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed.
Brett Cannon <bcannon@gmail.com>
parents: 37307
diff changeset
338
37277
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
339 def test_main():
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
340 warnings.filterwarnings("ignore",
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
341 r'complex divmod\(\), // and % are deprecated',
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
342 DeprecationWarning,
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
343 r'test.test_coercion$')
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
344 run_unittest(CoercionTest)
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
345
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
346 if __name__ == "__main__":
efd141cbf6cb Make test_coercion pass with -Qnew. Converted to unittest on the occasion.
Georg Brandl <georg@python.org>
parents: 36751
diff changeset
347 test_main()