annotate Lib/test/test_class.py @ 27998:e27f58a50737 legacy-trunk

SF bug #690377: Dud footnote reference in distutils docs
author Raymond Hettinger <python@rcn.com>
date Fri, 21 Feb 2003 02:47:09 +0000
parents 3db772d45f98
children 6f15e73b59f2
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
24442
226ba34bd998 Complete the absolute import patch for the test suite. All relative
Barry Warsaw <barry@python.org>
parents: 23839
diff changeset
3 from test.test_support import TestFailed
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
4
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
5 testmeths = [
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 # Binary operations
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
8 "add",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
9 "radd",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
10 "sub",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
11 "rsub",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
12 "mul",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
13 "rmul",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
14 "div",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
15 "rdiv",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
16 "mod",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
17 "rmod",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
18 "divmod",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
19 "rdivmod",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
20 "pow",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
21 "rpow",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
22 "rshift",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
23 "rrshift",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
24 "lshift",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
25 "rlshift",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
26 "and",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
27 "rand",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
28 "or",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
29 "ror",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
30 "xor",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
31 "rxor",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
32
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
33 # 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
34 "contains",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
35 "getitem",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
36 "getslice",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
37 "setitem",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
38 "setslice",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
39 "delitem",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
40 "delslice",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
41
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
42 # Unary operations
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
43 "neg",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
44 "pos",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
45 "abs",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
46 "int",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
47 "long",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
48 "float",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
49 "oct",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
50 "hex",
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 # generic operations
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
53 "init",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
54 ]
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
55
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
56 # 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
57 # "coerce",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
58 # "hash",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
59 # "str",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
60 # "repr",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
61
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
62 # 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
63 # "getattr",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
64 # "setattr",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
65 # "delattr",
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
66
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
67 class AllTests:
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
68 def __coerce__(self, *args):
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
69 print "__coerce__:", args
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 15014
diff changeset
70 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
71
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
72 def __hash__(self, *args):
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
73 print "__hash__:", 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
74 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
75
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
76 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
77 print "__str__:", args
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
78 return "AllTests"
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
79
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
80 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
81 print "__repr__:", args
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
82 return "AllTests"
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
83
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
84 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
85 print "__cmp__:", args
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
86 return 0
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
87
19406
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
88 def __del__(self, *args):
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
89 print "__del__:", args
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
90
21351
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
91 # Synthesize AllTests methods from the names in testmeths.
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
92
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
93 method_template = """\
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
94 def __%(method)s__(self, *args):
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
95 print "__%(method)s__:", args
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
96 """
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
97
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
98 for method in testmeths:
21351
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
99 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
100
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
101 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
102
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
103 # this also tests __init__ of course.
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
104 testme = AllTests()
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
105
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
106 # Binary operations
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
107
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
108 testme + 1
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
109 1 + testme
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
110
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
111 testme - 1
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
112 1 - testme
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
113
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
114 testme * 1
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
115 1 * testme
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
116
21351
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
117 if 1/2 == 0:
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
118 testme / 1
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
119 1 / testme
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
120 else:
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
121 # True division is in effect, so "/" doesn't map to __div__ etc; but
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
122 # the canned expected-output file requires that __div__ etc get called.
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
123 testme.__coerce__(1)
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
124 testme.__div__(1)
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
125 testme.__coerce__(1)
be990e703d0f Fiddle test_class so it passes with -Qnew.
Tim Peters <tim.peters@gmail.com>
parents: 19406
diff changeset
126 testme.__rdiv__(1)
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
127
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
128 testme % 1
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
129 1 % testme
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
130
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
131 divmod(testme,1)
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
132 divmod(1, testme)
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
133
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
134 testme ** 1
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
135 1 ** testme
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
136
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
137 testme >> 1
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
138 1 >> testme
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
139
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
140 testme << 1
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
141 1 << testme
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
142
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
143 testme & 1
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
144 1 & testme
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
145
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
146 testme | 1
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
147 1 | testme
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
148
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
149 testme ^ 1
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
150 1 ^ testme
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
151
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
152
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
153 # 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
154
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
155 1 in testme
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
156
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
157 testme[1]
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
158 testme[1] = 1
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
159 del testme[1]
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
160
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
161 testme[:42]
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
162 testme[:42] = "The Answer"
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
163 del testme[:42]
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
164
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
165 testme[2:1024:10]
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
166 testme[2:1024:10] = "A lot"
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
167 del testme[2:1024:10]
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
168
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
169 testme[:42, ..., :24:, 24, 100]
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
170 testme[:42, ..., :24:, 24, 100] = "Strange"
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
171 del testme[:42, ..., :24:, 24, 100]
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
172
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
173
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
174 # Now remove the slice hooks to see if converting normal slices to slice
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
175 # object works.
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
176
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
177 del AllTests.__getslice__
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
178 del AllTests.__setslice__
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
179 del AllTests.__delslice__
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
180
19406
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
181 import sys
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
182 if sys.platform[:4] != 'java':
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
183 testme[:42]
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
184 testme[:42] = "The Answer"
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
185 del testme[:42]
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
186 else:
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
187 # This works under Jython, but the actual slice values are
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
188 # different.
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
189 print "__getitem__: (slice(0, 42, None),)"
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
190 print "__setitem__: (slice(0, 42, None), 'The Answer')"
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
191 print "__delitem__: (slice(0, 42, None),)"
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 # Unary operations
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
194
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
195 -testme
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
196 +testme
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
197 abs(testme)
19406
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
198 if sys.platform[:4] != 'java':
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
199 int(testme)
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
200 long(testme)
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
201 float(testme)
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
202 oct(testme)
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
203 hex(testme)
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
204 else:
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
205 # Jython enforced that the these methods return
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
206 # a value of the expected type.
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
207 print "__int__: ()"
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
208 print "__long__: ()"
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
209 print "__float__: ()"
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
210 print "__oct__: ()"
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
211 print "__hex__: ()"
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
212
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
213
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
214 # And the rest...
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
215
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
216 hash(testme)
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
217 repr(testme)
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
218 str(testme)
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
219
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
220 testme == 1
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
221 testme < 1
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
222 testme > 1
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
223 testme <> 1
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
224 testme != 1
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
225 1 == testme
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
226 1 < testme
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
227 1 > testme
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
228 1 <> testme
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
229 1 != testme
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
230
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
231 # This test has to be last (duh.)
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
232
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
233 del testme
19406
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
234 if sys.platform[:4] == 'java':
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
235 import java
9306f828fbb7 Committing and closing SF patch #403671 by Finn Bock to help Jython
Barry Warsaw <barry@python.org>
parents: 16104
diff changeset
236 java.lang.System.gc()
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
237
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
238 # Interfering tests
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
239
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
240 class ExtraTests:
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 15014
diff changeset
241 def __getattr__(self, *args):
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 15014
diff changeset
242 print "__getattr__:", args
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 15014
diff changeset
243 return "SomeVal"
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
244
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 15014
diff changeset
245 def __setattr__(self, *args):
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 15014
diff changeset
246 print "__setattr__:", args
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
247
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 15014
diff changeset
248 def __delattr__(self, *args):
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 15014
diff changeset
249 print "__delattr__:", args
14037
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
250
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
251 testme = ExtraTests()
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
252 testme.spam
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
253 testme.eggs = "spam, spam, spam and ham"
91f847a783d2 Apply SF patch #101029: call __getitem__ with a proper slice object if there
Thomas Wouters <thomas@python.org>
parents:
diff changeset
254 del testme.cardinal
16005
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
255
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
256
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
257 # Test correct errors from hash() on objects with comparisons but no __hash__
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
258
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
259 class C0:
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
260 pass
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
261
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
262 hash(C0()) # This should work; the next two should raise TypeError
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
263
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
264 class C1:
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
265 def __cmp__(self, other): return 0
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
266
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
267 try: hash(C1())
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
268 except TypeError: pass
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
269 else: raise TestFailed, "hash(C1()) should raise an exception"
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
270
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
271 class C2:
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
272 def __eq__(self, other): return 1
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
273
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
274 try: hash(C2())
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
275 except TypeError: pass
ced8041eb4ea Add test that ensures hash() of objects defining __cmp__ or __eq__ but
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
276 else: raise TestFailed, "hash(C2()) should raise an exception"
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
277
c8815bd01ff5 Fix for SF bug 532646. This is a little simpler than what Neal
Guido van Rossum <guido@python.org>
parents: 21351
diff changeset
278
c8815bd01ff5 Fix for SF bug 532646. This is a little simpler than what Neal
Guido van Rossum <guido@python.org>
parents: 21351
diff changeset
279 # Test for SF bug 532646
c8815bd01ff5 Fix for SF bug 532646. This is a little simpler than what Neal
Guido van Rossum <guido@python.org>
parents: 21351
diff changeset
280
c8815bd01ff5 Fix for SF bug 532646. This is a little simpler than what Neal
Guido van Rossum <guido@python.org>
parents: 21351
diff changeset
281 class A:
c8815bd01ff5 Fix for SF bug 532646. This is a little simpler than what Neal
Guido van Rossum <guido@python.org>
parents: 21351
diff changeset
282 pass
c8815bd01ff5 Fix for SF bug 532646. This is a little simpler than what Neal
Guido van Rossum <guido@python.org>
parents: 21351
diff changeset
283 A.__call__ = A()
c8815bd01ff5 Fix for SF bug 532646. This is a little simpler than what Neal
Guido van Rossum <guido@python.org>
parents: 21351
diff changeset
284 a = A()
c8815bd01ff5 Fix for SF bug 532646. This is a little simpler than what Neal
Guido van Rossum <guido@python.org>
parents: 21351
diff changeset
285 try:
c8815bd01ff5 Fix for SF bug 532646. This is a little simpler than what Neal
Guido van Rossum <guido@python.org>
parents: 21351
diff changeset
286 a() # This should not segfault
c8815bd01ff5 Fix for SF bug 532646. This is a little simpler than what Neal
Guido van Rossum <guido@python.org>
parents: 21351
diff changeset
287 except RuntimeError:
c8815bd01ff5 Fix for SF bug 532646. This is a little simpler than what Neal
Guido van Rossum <guido@python.org>
parents: 21351
diff changeset
288 pass
c8815bd01ff5 Fix for SF bug 532646. This is a little simpler than what Neal
Guido van Rossum <guido@python.org>
parents: 21351
diff changeset
289 else:
c8815bd01ff5 Fix for SF bug 532646. This is a little simpler than what Neal
Guido van Rossum <guido@python.org>
parents: 21351
diff changeset
290 raise TestFailed, "how could this not have overflowed the stack?"
25942
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
291
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
292
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
293 # Tests for exceptions raised in instance_getattr2().
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
294
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
295 def booh(self):
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
296 raise AttributeError, "booh"
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
297
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
298 class A:
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
299 a = property(booh)
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
300 try:
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
301 A().a # Raised AttributeError: A instance has no attribute 'a'
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
302 except AttributeError, x:
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
303 if str(x) is not "booh":
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
304 print "attribute error for A().a got masked:", str(x)
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
305
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
306 class E:
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
307 __eq__ = property(booh)
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
308 E() == E() # In debug mode, caused a C-level assert() to fail
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
309
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
310 class I:
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
311 __init__ = property(booh)
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
312 try:
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
313 I() # In debug mode, printed XXX undetected error and raises AttributeError
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
314 except AttributeError, x:
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
315 pass
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
316 else:
3db772d45f98 Added test for this fix to classobject.c:
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
317 print "attribute error for I.__init__ got masked"