annotate Lib/test/test_class.py @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents 1d84bf5f9478
children 51102abdec50 7caf54ce529e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1 "Test the functionality of Python classes implementing operators."
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
3 import unittest
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
4
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
5 from test import test_support
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
6
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
7 testmeths = [
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
8
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
9 # Binary operations
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
10 "add",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
11 "radd",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
12 "sub",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
13 "rsub",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
14 "mul",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
15 "rmul",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
16 "div",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
17 "rdiv",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
18 "mod",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
19 "rmod",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
20 "divmod",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
21 "rdivmod",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
22 "pow",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
23 "rpow",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
24 "rshift",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
25 "rrshift",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
26 "lshift",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
27 "rlshift",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
28 "and",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
29 "rand",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
30 "or",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
31 "ror",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
32 "xor",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
33 "rxor",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
34
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
35 # List/dict operations
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
36 "contains",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
37 "getitem",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
38 "getslice",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
39 "setitem",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
40 "setslice",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
41 "delitem",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
42 "delslice",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
43
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
44 # Unary operations
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
45 "neg",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
46 "pos",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
47 "abs",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
48
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
49 # generic operations
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
50 "init",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
51 ]
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
52
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
53 # These need to return something other than None
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
54 # "coerce",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
55 # "hash",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
56 # "str",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
57 # "repr",
32759
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
58 # "int",
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
59 # "long",
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
60 # "float",
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
61 # "oct",
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
62 # "hex",
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
63
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
64 # These are separate because they can influence the test of other methods.
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
65 # "getattr",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
66 # "setattr",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
67 # "delattr",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
68
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
69 callLst = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
70 def trackCall(f):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
71 def track(*args, **kwargs):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
72 callLst.append((f.__name__, args))
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
73 return f(*args, **kwargs)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
74 return track
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
75
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
76 class AllTests:
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
77 trackCall = trackCall
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
78
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
79 @trackCall
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
80 def __coerce__(self, *args):
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 15014
diff changeset
81 return (self,) + args
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
82
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
83 @trackCall
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
84 def __hash__(self, *args):
15014
b0d1dec2353a Fix for test_class.py on Win64. id(self), which on Win64 returns a
Trent Mick <trentm@activestate.com>
parents: 14037
diff changeset
85 return hash(id(self))
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
86
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
87 @trackCall
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
88 def __str__(self, *args):
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
89 return "AllTests"
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
90
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
91 @trackCall
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
92 def __repr__(self, *args):
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
93 return "AllTests"
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
94
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
95 @trackCall
32759
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
96 def __int__(self, *args):
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
97 return 1
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
98
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
99 @trackCall
32759
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
100 def __float__(self, *args):
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
101 return 1.0
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
102
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
103 @trackCall
32759
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
104 def __long__(self, *args):
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
105 return 1L
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
106
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
107 @trackCall
32759
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
108 def __oct__(self, *args):
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
109 return '01'
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
110
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
111 @trackCall
32759
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
112 def __hex__(self, *args):
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
113 return '0x1'
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
114
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
115 @trackCall
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
116 def __cmp__(self, *args):
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
117 return 0
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
118
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
119 # Synthesize all the other AllTests methods from the names in testmeths.
21351
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
120
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
121 method_template = """\
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
122 @trackCall
21351
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
123 def __%(method)s__(self, *args):
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
124 pass
21351
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
125 """
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
126
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
127 for method in testmeths:
21351
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
128 exec method_template % locals() in AllTests.__dict__
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
129
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
130 del method, method_template
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
131
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
132 class ClassTests(unittest.TestCase):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
133 def setUp(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
134 callLst[:] = []
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
135
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
136 def assertCallStack(self, expected_calls):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
137 actualCallList = callLst[:] # need to copy because the comparison below will add
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
138 # additional calls to callLst
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
139 if expected_calls != actualCallList:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
140 self.fail("Expected call list:\n %s\ndoes not match actual call list\n %s" %
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
141 (expected_calls, actualCallList))
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
142
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
143 def testInit(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
144 foo = AllTests()
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
145 self.assertCallStack([("__init__", (foo,))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
146
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
147 def testBinaryOps(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
148 testme = AllTests()
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
149 # Binary operations
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
150
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
151 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
152 testme + 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
153 self.assertCallStack([("__coerce__", (testme, 1)), ("__add__", (testme, 1))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
154
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
155 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
156 1 + testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
157 self.assertCallStack([("__coerce__", (testme, 1)), ("__radd__", (testme, 1))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
158
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
159 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
160 testme - 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
161 self.assertCallStack([("__coerce__", (testme, 1)), ("__sub__", (testme, 1))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
162
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
163 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
164 1 - testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
165 self.assertCallStack([("__coerce__", (testme, 1)), ("__rsub__", (testme, 1))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
166
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
167 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
168 testme * 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
169 self.assertCallStack([("__coerce__", (testme, 1)), ("__mul__", (testme, 1))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
170
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
171 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
172 1 * testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
173 self.assertCallStack([("__coerce__", (testme, 1)), ("__rmul__", (testme, 1))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
174
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
175 if 1/2 == 0:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
176 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
177 testme / 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
178 self.assertCallStack([("__coerce__", (testme, 1)), ("__div__", (testme, 1))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
179
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
180
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
181 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
182 1 / testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
183 self.assertCallStack([("__coerce__", (testme, 1)), ("__rdiv__", (testme, 1))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
184
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
185 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
186 testme % 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
187 self.assertCallStack([("__coerce__", (testme, 1)), ("__mod__", (testme, 1))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
188
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
189 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
190 1 % testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
191 self.assertCallStack([("__coerce__", (testme, 1)), ("__rmod__", (testme, 1))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
192
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
193
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
194 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
195 divmod(testme,1)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
196 self.assertCallStack([("__coerce__", (testme, 1)), ("__divmod__", (testme, 1))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
197
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
198 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
199 divmod(1, testme)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
200 self.assertCallStack([("__coerce__", (testme, 1)), ("__rdivmod__", (testme, 1))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
201
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
202 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
203 testme ** 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
204 self.assertCallStack([("__coerce__", (testme, 1)), ("__pow__", (testme, 1))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
205
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
206 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
207 1 ** testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
208 self.assertCallStack([("__coerce__", (testme, 1)), ("__rpow__", (testme, 1))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
209
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
210 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
211 testme >> 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
212 self.assertCallStack([("__coerce__", (testme, 1)), ("__rshift__", (testme, 1))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
213
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
214 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
215 1 >> testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
216 self.assertCallStack([("__coerce__", (testme, 1)), ("__rrshift__", (testme, 1))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
217
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
218 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
219 testme << 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
220 self.assertCallStack([("__coerce__", (testme, 1)), ("__lshift__", (testme, 1))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
221
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
222 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
223 1 << testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
224 self.assertCallStack([("__coerce__", (testme, 1)), ("__rlshift__", (testme, 1))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
225
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
226 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
227 testme & 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
228 self.assertCallStack([("__coerce__", (testme, 1)), ("__and__", (testme, 1))])
40301
61cd8c87cfe2 Correctly forward exception in instance_contains().
Martin v. Löwis <martin@v.loewis.de>
parents: 38659
diff changeset
229
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
230 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
231 1 & testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
232 self.assertCallStack([("__coerce__", (testme, 1)), ("__rand__", (testme, 1))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
233
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
234 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
235 testme | 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
236 self.assertCallStack([("__coerce__", (testme, 1)), ("__or__", (testme, 1))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
237
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
238 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
239 1 | testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
240 self.assertCallStack([("__coerce__", (testme, 1)), ("__ror__", (testme, 1))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
241
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
242 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
243 testme ^ 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
244 self.assertCallStack([("__coerce__", (testme, 1)), ("__xor__", (testme, 1))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
245
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
246 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
247 1 ^ testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
248 self.assertCallStack([("__coerce__", (testme, 1)), ("__rxor__", (testme, 1))])
40301
61cd8c87cfe2 Correctly forward exception in instance_contains().
Martin v. Löwis <martin@v.loewis.de>
parents: 38659
diff changeset
249
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
250 def testListAndDictOps(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
251 testme = AllTests()
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
252
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
253 # List/dict operations
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
254
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
255 class Empty: pass
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
256
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
257 try:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
258 1 in Empty()
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
259 self.fail('failed, should have raised TypeError')
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
260 except TypeError:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
261 pass
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
262
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
263 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
264 1 in testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
265 self.assertCallStack([('__contains__', (testme, 1))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
266
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
267 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
268 testme[1]
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
269 self.assertCallStack([('__getitem__', (testme, 1))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
270
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
271 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
272 testme[1] = 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
273 self.assertCallStack([('__setitem__', (testme, 1, 1))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
274
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
275 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
276 del testme[1]
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
277 self.assertCallStack([('__delitem__', (testme, 1))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
278
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
279 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
280 testme[:42]
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
281 self.assertCallStack([('__getslice__', (testme, 0, 42))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
282
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
283 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
284 testme[:42] = "The Answer"
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
285 self.assertCallStack([('__setslice__', (testme, 0, 42, "The Answer"))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
286
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
287 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
288 del testme[:42]
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
289 self.assertCallStack([('__delslice__', (testme, 0, 42))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
290
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
291 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
292 testme[2:1024:10]
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
293 self.assertCallStack([('__getitem__', (testme, slice(2, 1024, 10)))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
294
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
295 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
296 testme[2:1024:10] = "A lot"
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
297 self.assertCallStack([('__setitem__', (testme, slice(2, 1024, 10),
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
298 "A lot"))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
299 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
300 del testme[2:1024:10]
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
301 self.assertCallStack([('__delitem__', (testme, slice(2, 1024, 10)))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
302
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
303 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
304 testme[:42, ..., :24:, 24, 100]
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
305 self.assertCallStack([('__getitem__', (testme, (slice(None, 42, None),
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
306 Ellipsis,
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
307 slice(None, 24, None),
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
308 24, 100)))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
309 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
310 testme[:42, ..., :24:, 24, 100] = "Strange"
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
311 self.assertCallStack([('__setitem__', (testme, (slice(None, 42, None),
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
312 Ellipsis,
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
313 slice(None, 24, None),
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
314 24, 100), "Strange"))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
315 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
316 del testme[:42, ..., :24:, 24, 100]
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
317 self.assertCallStack([('__delitem__', (testme, (slice(None, 42, None),
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
318 Ellipsis,
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
319 slice(None, 24, None),
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
320 24, 100)))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
321
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
322 # Now remove the slice hooks to see if converting normal slices to
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
323 # slice object works.
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
324
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
325 getslice = AllTests.__getslice__
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
326 del AllTests.__getslice__
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
327 setslice = AllTests.__setslice__
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
328 del AllTests.__setslice__
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
329 delslice = AllTests.__delslice__
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
330 del AllTests.__delslice__
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
331
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
332 # XXX when using new-style classes the slice testme[:42] produces
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
333 # slice(None, 42, None) instead of slice(0, 42, None). py3k will have
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
334 # to change this test.
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
335 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
336 testme[:42]
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
337 self.assertCallStack([('__getitem__', (testme, slice(0, 42, None)))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
338
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
339 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
340 testme[:42] = "The Answer"
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
341 self.assertCallStack([('__setitem__', (testme, slice(0, 42, None),
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
342 "The Answer"))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
343 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
344 del testme[:42]
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
345 self.assertCallStack([('__delitem__', (testme, slice(0, 42, None)))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
346
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
347 # Restore the slice methods, or the tests will fail with regrtest -R.
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
348 AllTests.__getslice__ = getslice
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
349 AllTests.__setslice__ = setslice
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
350 AllTests.__delslice__ = delslice
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
351
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
352
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
353 def testUnaryOps(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
354 testme = AllTests()
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
355
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
356 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
357 -testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
358 self.assertCallStack([('__neg__', (testme,))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
359 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
360 +testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
361 self.assertCallStack([('__pos__', (testme,))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
362 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
363 abs(testme)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
364 self.assertCallStack([('__abs__', (testme,))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
365 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
366 int(testme)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
367 self.assertCallStack([('__int__', (testme,))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
368 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
369 long(testme)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
370 self.assertCallStack([('__long__', (testme,))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
371 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
372 float(testme)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
373 self.assertCallStack([('__float__', (testme,))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
374 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
375 oct(testme)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
376 self.assertCallStack([('__oct__', (testme,))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
377 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
378 hex(testme)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
379 self.assertCallStack([('__hex__', (testme,))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
380
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
381
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
382 def testMisc(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
383 testme = AllTests()
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
384
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
385 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
386 hash(testme)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
387 self.assertCallStack([('__hash__', (testme,))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
388
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
389 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
390 repr(testme)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
391 self.assertCallStack([('__repr__', (testme,))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
392
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
393 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
394 str(testme)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
395 self.assertCallStack([('__str__', (testme,))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
396
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
397 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
398 testme == 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
399 self.assertCallStack([("__coerce__", (testme, 1)), ('__cmp__', (testme, 1))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
400
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
401 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
402 testme < 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
403 self.assertCallStack([("__coerce__", (testme, 1)), ('__cmp__', (testme, 1))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
404
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
405 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
406 testme > 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
407 self.assertCallStack([("__coerce__", (testme, 1)), ('__cmp__', (testme, 1))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
408
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
409 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
410 testme <> 1 # XXX kill this in py3k
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
411 self.assertCallStack([("__coerce__", (testme, 1)), ('__cmp__', (testme, 1))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
412
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
413 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
414 testme != 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
415 self.assertCallStack([("__coerce__", (testme, 1)), ('__cmp__', (testme, 1))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
416
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
417 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
418 1 == testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
419 self.assertCallStack([("__coerce__", (testme, 1)), ('__cmp__', (1, testme))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
420
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
421 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
422 1 < testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
423 self.assertCallStack([("__coerce__", (testme, 1)), ('__cmp__', (1, testme))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
424
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
425 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
426 1 > testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
427 self.assertCallStack([("__coerce__", (testme, 1)), ('__cmp__', (1, testme))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
428
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
429 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
430 1 <> testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
431 self.assertCallStack([("__coerce__", (testme, 1)), ('__cmp__', (1, testme))])
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
432
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
433 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
434 1 != testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
435 self.assertCallStack([("__coerce__", (testme, 1)), ('__cmp__', (1, testme))])
16005
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
436
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
437
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
438 def testGetSetAndDel(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
439 # Interfering tests
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
440 class ExtraTests(AllTests):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
441 @trackCall
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
442 def __getattr__(self, *args):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
443 return "SomeVal"
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
444
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
445 @trackCall
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
446 def __setattr__(self, *args):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
447 pass
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
448
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
449 @trackCall
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
450 def __delattr__(self, *args):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
451 pass
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
452
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
453 testme = ExtraTests()
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
454
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
455 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
456 testme.spam
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
457 self.assertCallStack([('__getattr__', (testme, "spam"))])
32759
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
458
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
459 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
460 testme.eggs = "spam, spam, spam and ham"
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
461 self.assertCallStack([('__setattr__', (testme, "eggs",
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
462 "spam, spam, spam and ham"))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
463
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
464 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
465 del testme.cardinal
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
466 self.assertCallStack([('__delattr__', (testme, "cardinal"))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
467
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
468 def testDel(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
469 x = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
470
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
471 class DelTest:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
472 def __del__(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
473 x.append("crab people, crab people")
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
474 testme = DelTest()
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
475 del testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
476 import gc
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
477 gc.collect()
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
478 self.assertEquals(["crab people, crab people"], x)
32759
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
479
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
480 def testBadTypeReturned(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
481 # return values of some method are type-checked
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
482 class BadTypeClass:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
483 def __int__(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
484 return None
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
485 __float__ = __int__
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
486 __long__ = __int__
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
487 __str__ = __int__
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
488 __repr__ = __int__
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
489 __oct__ = __int__
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
490 __hex__ = __int__
32759
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
491
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
492 for f in [int, float, long, str, repr, oct, hex]:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
493 self.assertRaises(TypeError, f, BadTypeClass())
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
494
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
495 def testMixIntsAndLongs(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
496 # mixing up ints and longs is okay
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
497 class IntLongMixClass:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
498 @trackCall
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
499 def __int__(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
500 return 42L
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
501
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
502 @trackCall
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
503 def __long__(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
504 return 64
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
505
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
506 mixIntAndLong = IntLongMixClass()
32759
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
507
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
508 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
509 as_int = int(mixIntAndLong)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
510 self.assertEquals(type(as_int), long)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
511 self.assertEquals(as_int, 42L)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
512 self.assertCallStack([('__int__', (mixIntAndLong,))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
513
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
514 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
515 as_long = long(mixIntAndLong)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
516 self.assertEquals(type(as_long), int)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
517 self.assertEquals(as_long, 64)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
518 self.assertCallStack([('__long__', (mixIntAndLong,))])
32759
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
519
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
520 def testHashStuff(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
521 # Test correct errors from hash() on objects with comparisons but
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
522 # no __hash__
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
523
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
524 class C0:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
525 pass
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
526
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
527 hash(C0()) # This should work; the next two should raise TypeError
32759
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
528
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
529 class C1:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
530 def __cmp__(self, other): return 0
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
531
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
532 self.assertRaises(TypeError, hash, C1())
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
533
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
534 class C2:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
535 def __eq__(self, other): return 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
536
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
537 self.assertRaises(TypeError, hash, C2())
32759
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
538
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
539
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
540 def testSFBug532646(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
541 # Test for SF bug 532646
16005
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
542
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
543 class A:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
544 pass
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
545 A.__call__ = A()
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
546 a = A()
16005
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
547
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
548 try:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
549 a() # This should not segfault
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
550 except RuntimeError:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
551 pass
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
552 else:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
553 self.fail("Failed to raise RuntimeError")
23839
c8815bd01ff5 Fix for SF bug 532646. This is a little simpler than what Neal
Guido van Rossum <guido@python.org>
parents: 21351
diff changeset
554
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
555 def testForExceptionsRaisedInInstanceGetattr2(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
556 # Tests for exceptions raised in instance_getattr2().
25942
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
557
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
558 def booh(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
559 raise AttributeError("booh")
25942
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
560
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
561 class A:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
562 a = property(booh)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
563 try:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
564 A().a # Raised AttributeError: A instance has no attribute 'a'
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
565 except AttributeError, x:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
566 if str(x) != "booh":
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
567 self.fail("attribute error for A().a got masked: %s" % x)
25942
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
568
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
569 class E:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
570 __eq__ = property(booh)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
571 E() == E() # In debug mode, caused a C-level assert() to fail
25942
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
572
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
573 class I:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
574 __init__ = property(booh)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
575 try:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
576 # In debug mode, printed XXX undetected error and
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
577 # raises AttributeError
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
578 I()
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
579 except AttributeError, x:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
580 pass
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
581 else:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
582 self.fail("attribute error for I.__init__ got masked")
38659
5c58fda95aa5 (arre, arigo) SF bug #1350060
Armin Rigo <arigo@tunes.org>
parents: 35096
diff changeset
583
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
584 def testHashComparisonOfMethods(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
585 # Test comparison and hash of methods
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
586 class A:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
587 def __init__(self, x):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
588 self.x = x
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
589 def f(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
590 pass
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
591 def g(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
592 pass
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
593 def __eq__(self, other):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
594 return self.x == other.x
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
595 def __hash__(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
596 return self.x
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
597 class B(A):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
598 pass
38659
5c58fda95aa5 (arre, arigo) SF bug #1350060
Armin Rigo <arigo@tunes.org>
parents: 35096
diff changeset
599
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
600 a1 = A(1)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
601 a2 = A(2)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
602 self.assertEquals(a1.f, a1.f)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
603 self.assertNotEquals(a1.f, a2.f)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
604 self.assertNotEquals(a1.f, a1.g)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
605 self.assertEquals(a1.f, A(1).f)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
606 self.assertEquals(hash(a1.f), hash(a1.f))
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
607 self.assertEquals(hash(a1.f), hash(A(1).f))
38659
5c58fda95aa5 (arre, arigo) SF bug #1350060
Armin Rigo <arigo@tunes.org>
parents: 35096
diff changeset
608
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
609 self.assertNotEquals(A.f, a1.f)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
610 self.assertNotEquals(A.f, A.g)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
611 self.assertEquals(B.f, A.f)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
612 self.assertEquals(hash(B.f), hash(A.f))
38659
5c58fda95aa5 (arre, arigo) SF bug #1350060
Armin Rigo <arigo@tunes.org>
parents: 35096
diff changeset
613
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
614 # the following triggers a SystemError in 2.4
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
615 a = A(hash(A.f.im_func)^(-1))
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
616 hash(a.f)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
617
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
618 def test_main():
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
619 test_support.run_unittest(ClassTests)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
620
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
621 if __name__=='__main__':
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
622 test_main()