Updated for hfsplus module, new gusi libs.
[python/dscho.git] / Lib / test / test_augassign.py
blobc372b9a695acc2715f0045ca58bd8a1502c4a65e
1 # Augmented assignment test.
3 x = 2
4 x += 1
5 x *= 2
6 x **= 2
7 x -= 8
8 x //= 2
9 x //= 1
10 x %= 12
11 x &= 2
12 x |= 5
13 x ^= 1
15 print x
17 x = [2]
18 x[0] += 1
19 x[0] *= 2
20 x[0] **= 2
21 x[0] -= 8
22 x[0] //= 2
23 x[0] //= 2
24 x[0] %= 12
25 x[0] &= 2
26 x[0] |= 5
27 x[0] ^= 1
29 print x
31 x = {0: 2}
32 x[0] += 1
33 x[0] *= 2
34 x[0] **= 2
35 x[0] -= 8
36 x[0] //= 2
37 x[0] //= 1
38 x[0] %= 12
39 x[0] &= 2
40 x[0] |= 5
41 x[0] ^= 1
43 print x[0]
45 x = [1,2]
46 x += [3,4]
47 x *= 2
49 print x
51 x = [1, 2, 3]
52 y = x
53 x[1:2] *= 2
54 y[1:2] += [1]
56 print x
57 print x is y
59 class aug_test:
60 def __init__(self, value):
61 self.val = value
62 def __radd__(self, val):
63 return self.val + val
64 def __add__(self, val):
65 return aug_test(self.val + val)
68 class aug_test2(aug_test):
69 def __iadd__(self, val):
70 self.val = self.val + val
71 return self
73 class aug_test3(aug_test):
74 def __iadd__(self, val):
75 return aug_test3(self.val + val)
77 x = aug_test(1)
78 y = x
79 x += 10
81 print isinstance(x, aug_test)
82 print y is not x
83 print x.val
85 x = aug_test2(2)
86 y = x
87 x += 10
89 print y is x
90 print x.val
92 x = aug_test3(3)
93 y = x
94 x += 10
96 print isinstance(x, aug_test3)
97 print y is not x
98 print x.val
100 class testall:
102 def __add__(self, val):
103 print "__add__ called"
104 def __radd__(self, val):
105 print "__radd__ called"
106 def __iadd__(self, val):
107 print "__iadd__ called"
108 return self
110 def __sub__(self, val):
111 print "__sub__ called"
112 def __rsub__(self, val):
113 print "__rsub__ called"
114 def __isub__(self, val):
115 print "__isub__ called"
116 return self
118 def __mul__(self, val):
119 print "__mul__ called"
120 def __rmul__(self, val):
121 print "__rmul__ called"
122 def __imul__(self, val):
123 print "__imul__ called"
124 return self
126 def __div__(self, val):
127 print "__div__ called"
128 def __rdiv__(self, val):
129 print "__rdiv__ called"
130 def __idiv__(self, val):
131 print "__idiv__ called"
132 return self
134 def __floordiv__(self, val):
135 print "__floordiv__ called"
136 return self
137 def __ifloordiv__(self, val):
138 print "__ifloordiv__ called"
139 return self
140 def __rfloordiv__(self, val):
141 print "__rfloordiv__ called"
142 return self
144 def __truediv__(self, val):
145 print "__truediv__ called"
146 return self
147 def __itruediv__(self, val):
148 print "__itruediv__ called"
149 return self
151 def __mod__(self, val):
152 print "__mod__ called"
153 def __rmod__(self, val):
154 print "__rmod__ called"
155 def __imod__(self, val):
156 print "__imod__ called"
157 return self
159 def __pow__(self, val):
160 print "__pow__ called"
161 def __rpow__(self, val):
162 print "__rpow__ called"
163 def __ipow__(self, val):
164 print "__ipow__ called"
165 return self
167 def __or__(self, val):
168 print "__or__ called"
169 def __ror__(self, val):
170 print "__ror__ called"
171 def __ior__(self, val):
172 print "__ior__ called"
173 return self
175 def __and__(self, val):
176 print "__and__ called"
177 def __rand__(self, val):
178 print "__rand__ called"
179 def __iand__(self, val):
180 print "__iand__ called"
181 return self
183 def __xor__(self, val):
184 print "__xor__ called"
185 def __rxor__(self, val):
186 print "__rxor__ called"
187 def __ixor__(self, val):
188 print "__ixor__ called"
189 return self
191 def __rshift__(self, val):
192 print "__rshift__ called"
193 def __rrshift__(self, val):
194 print "__rrshift__ called"
195 def __irshift__(self, val):
196 print "__irshift__ called"
197 return self
199 def __lshift__(self, val):
200 print "__lshift__ called"
201 def __rlshift__(self, val):
202 print "__rlshift__ called"
203 def __ilshift__(self, val):
204 print "__ilshift__ called"
205 return self
207 x = testall()
208 x + 1
209 1 + x
210 x += 1
212 x - 1
213 1 - x
214 x -= 1
216 x * 1
217 1 * x
218 x *= 1
220 x / 1
221 1 / x
222 x /= 1
224 x // 1
225 1 // x
226 x //= 1
228 x % 1
229 1 % x
230 x %= 1
232 x ** 1
233 1 ** x
234 x **= 1
236 x | 1
237 1 | x
238 x |= 1
240 x & 1
241 1 & x
242 x &= 1
244 x ^ 1
245 1 ^ x
246 x ^= 1
248 x >> 1
249 1 >> x
250 x >>= 1
252 x << 1
253 1 << x
254 x <<= 1