1 "Test the functionality of Python classes implementing operators."
32 # List/dict operations
56 # These need to return something other than None
62 # These are separate because they can influence the test of other methods.
68 def __coerce__(self
, *args
):
69 print "__coerce__:", args
72 def __hash__(self
, *args
):
73 print "__hash__:", args
76 def __str__(self
, *args
):
77 print "__str__:", args
80 def __repr__(self
, *args
):
81 print "__repr__:", args
84 def __cmp__(self
, *args
):
85 print "__cmp__:", args
88 for method
in testmeths
:
89 exec("""def __%(method)s__(self, *args):
90 print "__%(method)s__:", args
91 """%locals(), AllTests
.__dict
__);
93 # this also tests __init__ of course.
135 # List/dict operations
144 testme
[:42] = "The Answer"
148 testme
[2:1024:10] = "A lot"
149 del testme
[2:1024:10]
151 testme
[:42, ..., :24:, 24, 100]
152 testme
[:42, ..., :24:, 24, 100] = "Strange"
153 del testme
[:42, ..., :24:, 24, 100]
156 # Now remove the slice hooks to see if converting normal slices to slice
159 del AllTests
.__getslice
__
160 del AllTests
.__setslice
__
161 del AllTests
.__delslice
__
164 testme
[:42] = "The Answer"
197 # This test has to be last (duh.)
205 def __getattr__(self
, *args
):
206 print "__getattr__:", args
209 def __setattr__(self
, *args
):
210 print "__setattr__:", args
212 def __delattr__(self
, *args
):
213 print "__delattr__:", args
215 testme
= ExtraTests()
217 testme
.eggs
= "spam, spam, spam and ham"