annotate Lib/test/test_class.py @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents 3d4d52e47431
children
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
72942
418fbf1af875 PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents: 68256
diff changeset
353 @test_support.cpython_only
418fbf1af875 PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents: 68256
diff changeset
354 def testDelItem(self):
418fbf1af875 PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents: 68256
diff changeset
355 class A:
418fbf1af875 PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents: 68256
diff changeset
356 ok = False
418fbf1af875 PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents: 68256
diff changeset
357 def __delitem__(self, key):
418fbf1af875 PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents: 68256
diff changeset
358 self.ok = True
418fbf1af875 PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents: 68256
diff changeset
359 a = A()
418fbf1af875 PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents: 68256
diff changeset
360 # Subtle: we need to call PySequence_SetItem, not PyMapping_SetItem.
418fbf1af875 PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents: 68256
diff changeset
361 from _testcapi import sequence_delitem
418fbf1af875 PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents: 68256
diff changeset
362 sequence_delitem(a, 2)
418fbf1af875 PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents: 68256
diff changeset
363 self.assertTrue(a.ok)
418fbf1af875 PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents: 68256
diff changeset
364
418fbf1af875 PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents: 68256
diff changeset
365
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
366 def testUnaryOps(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
367 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
368
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
369 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
370 -testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
371 self.assertCallStack([('__neg__', (testme,))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
372 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
373 +testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
374 self.assertCallStack([('__pos__', (testme,))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
375 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
376 abs(testme)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
377 self.assertCallStack([('__abs__', (testme,))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
378 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
379 int(testme)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
380 self.assertCallStack([('__int__', (testme,))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
381 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
382 long(testme)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
383 self.assertCallStack([('__long__', (testme,))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
384 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
385 float(testme)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
386 self.assertCallStack([('__float__', (testme,))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
387 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
388 oct(testme)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
389 self.assertCallStack([('__oct__', (testme,))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
390 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
391 hex(testme)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
392 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
393
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
394
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
395 def testMisc(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
396 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
397
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
398 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
399 hash(testme)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
400 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
401
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
402 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
403 repr(testme)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
404 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
405
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
406 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
407 str(testme)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
408 self.assertCallStack([('__str__', (testme,))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
409
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
410 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
411 testme == 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
412 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
413
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
414 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
415 testme < 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
416 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
417
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
418 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
419 testme > 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
420 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
421
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
422 callLst[:] = []
63572
51102abdec50 Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 45468
diff changeset
423 eval('testme <> 1') # XXX kill this in py3k
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
424 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
425
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
426 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
427 testme != 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
428 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
429
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
430 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
431 1 == testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
432 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
433
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
434 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
435 1 < testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
436 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
437
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
438 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
439 1 > testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
440 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
441
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
442 callLst[:] = []
63572
51102abdec50 Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 45468
diff changeset
443 eval('1 <> testme')
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
444 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
445
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
446 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
447 1 != testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
448 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
449
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
450
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
451 def testGetSetAndDel(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
452 # Interfering tests
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
453 class ExtraTests(AllTests):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
454 @trackCall
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
455 def __getattr__(self, *args):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
456 return "SomeVal"
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
457
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
458 @trackCall
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
459 def __setattr__(self, *args):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
460 pass
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
461
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
462 @trackCall
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
463 def __delattr__(self, *args):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
464 pass
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
465
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
466 testme = ExtraTests()
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 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
469 testme.spam
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
470 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
471
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
472 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
473 testme.eggs = "spam, spam, spam and ham"
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
474 self.assertCallStack([('__setattr__', (testme, "eggs",
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
475 "spam, spam, spam and ham"))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
476
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
477 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
478 del testme.cardinal
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
479 self.assertCallStack([('__delattr__', (testme, "cardinal"))])
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
480
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
481 def testDel(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
482 x = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
483
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
484 class DelTest:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
485 def __del__(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
486 x.append("crab people, crab people")
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
487 testme = DelTest()
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
488 del testme
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
489 import gc
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
490 gc.collect()
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 64946
diff changeset
491 self.assertEqual(["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
492
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
493 def testBadTypeReturned(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
494 # 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
495 class BadTypeClass:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
496 def __int__(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
497 return None
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
498 __float__ = __int__
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
499 __long__ = __int__
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
500 __str__ = __int__
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
501 __repr__ = __int__
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
502 __oct__ = __int__
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
503 __hex__ = __int__
32759
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
504
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
505 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
506 self.assertRaises(TypeError, f, BadTypeClass())
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
507
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
508 def testMixIntsAndLongs(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
509 # mixing up ints and longs is okay
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
510 class IntLongMixClass:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
511 @trackCall
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
512 def __int__(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
513 return 42L
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
514
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
515 @trackCall
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
516 def __long__(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
517 return 64
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
518
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
519 mixIntAndLong = IntLongMixClass()
32759
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
520
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
521 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
522 as_int = int(mixIntAndLong)
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 64946
diff changeset
523 self.assertEqual(type(as_int), long)
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 64946
diff changeset
524 self.assertEqual(as_int, 42L)
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
525 self.assertCallStack([('__int__', (mixIntAndLong,))])
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 callLst[:] = []
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
528 as_long = long(mixIntAndLong)
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 64946
diff changeset
529 self.assertEqual(type(as_long), long)
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 64946
diff changeset
530 self.assertEqual(as_long, 64)
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
531 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
532
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
533 def testHashStuff(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
534 # 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
535 # no __hash__
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 class C0:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
538 pass
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
539
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
540 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
541
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
542 class C1:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
543 def __cmp__(self, other): return 0
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
544
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
545 self.assertRaises(TypeError, hash, C1())
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
546
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
547 class C2:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
548 def __eq__(self, other): return 1
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
549
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
550 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
551
d1777f51923b Check the type of values returned by __int__, __float__, __long__,
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 30723
diff changeset
552
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
553 def testSFBug532646(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
554 # 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
555
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
556 class A:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
557 pass
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
558 A.__call__ = A()
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
559 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
560
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
561 try:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
562 a() # This should not segfault
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
563 except RuntimeError:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
564 pass
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
565 else:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
566 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
567
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
568 def testForExceptionsRaisedInInstanceGetattr2(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
569 # 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
570
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
571 def booh(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
572 raise AttributeError("booh")
25942
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
573
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
574 class A:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
575 a = property(booh)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
576 try:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
577 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
578 except AttributeError, x:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
579 if str(x) != "booh":
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
580 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
581
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
582 class E:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
583 __eq__ = property(booh)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
584 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
585
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
586 class I:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
587 __init__ = property(booh)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
588 try:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
589 # 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
590 # raises AttributeError
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
591 I()
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
592 except AttributeError, x:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
593 pass
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
594 else:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
595 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
596
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
597 def testHashComparisonOfMethods(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
598 # Test comparison and hash of methods
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
599 class A:
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
600 def __init__(self, x):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
601 self.x = x
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
602 def f(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
603 pass
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
604 def g(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
605 pass
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
606 def __eq__(self, other):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
607 return self.x == other.x
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
608 def __hash__(self):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
609 return self.x
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
610 class B(A):
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
611 pass
38659
5c58fda95aa5 (arre, arigo) SF bug #1350060
Armin Rigo <arigo@tunes.org>
parents: 35096
diff changeset
612
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
613 a1 = A(1)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
614 a2 = A(2)
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 64946
diff changeset
615 self.assertEqual(a1.f, a1.f)
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 64946
diff changeset
616 self.assertNotEqual(a1.f, a2.f)
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 64946
diff changeset
617 self.assertNotEqual(a1.f, a1.g)
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 64946
diff changeset
618 self.assertEqual(a1.f, A(1).f)
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 64946
diff changeset
619 self.assertEqual(hash(a1.f), hash(a1.f))
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 64946
diff changeset
620 self.assertEqual(hash(a1.f), hash(A(1).f))
38659
5c58fda95aa5 (arre, arigo) SF bug #1350060
Armin Rigo <arigo@tunes.org>
parents: 35096
diff changeset
621
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 64946
diff changeset
622 self.assertNotEqual(A.f, a1.f)
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 64946
diff changeset
623 self.assertNotEqual(A.f, A.g)
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 64946
diff changeset
624 self.assertEqual(B.f, A.f)
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 64946
diff changeset
625 self.assertEqual(hash(B.f), hash(A.f))
38659
5c58fda95aa5 (arre, arigo) SF bug #1350060
Armin Rigo <arigo@tunes.org>
parents: 35096
diff changeset
626
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
627 # 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
628 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
629 hash(a.f)
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
630
75745
3d4d52e47431 check for string attribute names in old-style classes (closes #14334)
Benjamin Peterson <benjamin@python.org>
parents: 72942
diff changeset
631 def testAttrSlots(self):
3d4d52e47431 check for string attribute names in old-style classes (closes #14334)
Benjamin Peterson <benjamin@python.org>
parents: 72942
diff changeset
632 class C:
3d4d52e47431 check for string attribute names in old-style classes (closes #14334)
Benjamin Peterson <benjamin@python.org>
parents: 72942
diff changeset
633 pass
3d4d52e47431 check for string attribute names in old-style classes (closes #14334)
Benjamin Peterson <benjamin@python.org>
parents: 72942
diff changeset
634 for c in C, C():
3d4d52e47431 check for string attribute names in old-style classes (closes #14334)
Benjamin Peterson <benjamin@python.org>
parents: 72942
diff changeset
635 self.assertRaises(TypeError, type(c).__getattribute__, c, [])
3d4d52e47431 check for string attribute names in old-style classes (closes #14334)
Benjamin Peterson <benjamin@python.org>
parents: 72942
diff changeset
636 self.assertRaises(TypeError, type(c).__setattr__, c, [], [])
3d4d52e47431 check for string attribute names in old-style classes (closes #14334)
Benjamin Peterson <benjamin@python.org>
parents: 72942
diff changeset
637
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
638 def test_main():
59783
c8c840162804 #7092 - Silence more py3k deprecation warnings, using test_support.check_py3k_warnings() helper.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58198
diff changeset
639 with test_support.check_py3k_warnings(
63572
51102abdec50 Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 45468
diff changeset
640 (".+__(get|set|del)slice__ has been removed", DeprecationWarning),
51102abdec50 Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 45468
diff changeset
641 ("classic int division", DeprecationWarning),
51102abdec50 Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 45468
diff changeset
642 ("<> not supported", DeprecationWarning)):
51102abdec50 Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 45468
diff changeset
643 test_support.run_unittest(ClassTests)
42792
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
644
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
645 if __name__=='__main__':
e42e7d03173b Port test_class to unittest. Patch #1671298.
Georg Brandl <georg@python.org>
parents: 40301
diff changeset
646 test_main()