Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_augassign.AugAssignTest Class Reference

List of all members.

Public Member Functions

def testBasic
def test_with_unpacking
def testInList
def testInDict
def testSequences
def testCustomMethods1
def testCustomMethods2

Public Attributes

 val

Detailed Description

Definition at line 7 of file test_augassign.py.


Member Function Documentation

Definition at line 22 of file test_augassign.py.

00022 
00023     def test_with_unpacking(self):
00024         self.assertRaises(SyntaxError, compile, "x, b += 3", "<test>", "exec")

Here is the call graph for this function:

Definition at line 8 of file test_augassign.py.

00008 
00009     def testBasic(self):
00010         x = 2
00011         x += 1
00012         x *= 2
00013         x **= 2
00014         x -= 8
00015         x //= 5
00016         x %= 3
00017         x &= 2
00018         x |= 5
00019         x ^= 1
00020         x /= 2
00021         self.assertEqual(x, 3.0)

Here is the call graph for this function:

Definition at line 68 of file test_augassign.py.

00068 
00069     def testCustomMethods1(self):
00070 
00071         class aug_test:
00072             def __init__(self, value):
00073                 self.val = value
00074             def __radd__(self, val):
00075                 return self.val + val
00076             def __add__(self, val):
00077                 return aug_test(self.val + val)
00078 
00079         class aug_test2(aug_test):
00080             def __iadd__(self, val):
00081                 self.val = self.val + val
00082                 return self
00083 
00084         class aug_test3(aug_test):
00085             def __iadd__(self, val):
00086                 return aug_test3(self.val + val)
00087 
00088         x = aug_test(1)
00089         y = x
00090         x += 10
00091 
00092         self.assertIsInstance(x, aug_test)
00093         self.assertTrue(y is not x)
00094         self.assertEqual(x.val, 11)
00095 
00096         x = aug_test2(2)
00097         y = x
00098         x += 10
00099 
00100         self.assertTrue(y is x)
00101         self.assertEqual(x.val, 12)
00102 
00103         x = aug_test3(3)
00104         y = x
00105         x += 10
00106 
00107         self.assertIsInstance(x, aug_test3)
00108         self.assertTrue(y is not x)
00109         self.assertEqual(x.val, 13)
00110 

Here is the call graph for this function:

Definition at line 111 of file test_augassign.py.

00111 
00112     def testCustomMethods2(test_self):
00113         output = []
00114 
00115         class testall:
00116             def __add__(self, val):
00117                 output.append("__add__ called")
00118             def __radd__(self, val):
00119                 output.append("__radd__ called")
00120             def __iadd__(self, val):
00121                 output.append("__iadd__ called")
00122                 return self
00123 
00124             def __sub__(self, val):
00125                 output.append("__sub__ called")
00126             def __rsub__(self, val):
00127                 output.append("__rsub__ called")
00128             def __isub__(self, val):
00129                 output.append("__isub__ called")
00130                 return self
00131 
00132             def __mul__(self, val):
00133                 output.append("__mul__ called")
00134             def __rmul__(self, val):
00135                 output.append("__rmul__ called")
00136             def __imul__(self, val):
00137                 output.append("__imul__ called")
00138                 return self
00139 
00140             def __div__(self, val):
00141                 output.append("__div__ called")
00142             def __rdiv__(self, val):
00143                 output.append("__rdiv__ called")
00144             def __idiv__(self, val):
00145                 output.append("__idiv__ called")
00146                 return self
00147 
00148             def __floordiv__(self, val):
00149                 output.append("__floordiv__ called")
00150                 return self
00151             def __ifloordiv__(self, val):
00152                 output.append("__ifloordiv__ called")
00153                 return self
00154             def __rfloordiv__(self, val):
00155                 output.append("__rfloordiv__ called")
00156                 return self
00157 
00158             def __truediv__(self, val):
00159                 output.append("__truediv__ called")
00160                 return self
00161             def __rtruediv__(self, val):
00162                 output.append("__rtruediv__ called")
00163                 return self
00164             def __itruediv__(self, val):
00165                 output.append("__itruediv__ called")
00166                 return self
00167 
00168             def __mod__(self, val):
00169                 output.append("__mod__ called")
00170             def __rmod__(self, val):
00171                 output.append("__rmod__ called")
00172             def __imod__(self, val):
00173                 output.append("__imod__ called")
00174                 return self
00175 
00176             def __pow__(self, val):
00177                 output.append("__pow__ called")
00178             def __rpow__(self, val):
00179                 output.append("__rpow__ called")
00180             def __ipow__(self, val):
00181                 output.append("__ipow__ called")
00182                 return self
00183 
00184             def __or__(self, val):
00185                 output.append("__or__ called")
00186             def __ror__(self, val):
00187                 output.append("__ror__ called")
00188             def __ior__(self, val):
00189                 output.append("__ior__ called")
00190                 return self
00191 
00192             def __and__(self, val):
00193                 output.append("__and__ called")
00194             def __rand__(self, val):
00195                 output.append("__rand__ called")
00196             def __iand__(self, val):
00197                 output.append("__iand__ called")
00198                 return self
00199 
00200             def __xor__(self, val):
00201                 output.append("__xor__ called")
00202             def __rxor__(self, val):
00203                 output.append("__rxor__ called")
00204             def __ixor__(self, val):
00205                 output.append("__ixor__ called")
00206                 return self
00207 
00208             def __rshift__(self, val):
00209                 output.append("__rshift__ called")
00210             def __rrshift__(self, val):
00211                 output.append("__rrshift__ called")
00212             def __irshift__(self, val):
00213                 output.append("__irshift__ called")
00214                 return self
00215 
00216             def __lshift__(self, val):
00217                 output.append("__lshift__ called")
00218             def __rlshift__(self, val):
00219                 output.append("__rlshift__ called")
00220             def __ilshift__(self, val):
00221                 output.append("__ilshift__ called")
00222                 return self
00223 
00224         x = testall()
00225         x + 1
00226         1 + x
00227         x += 1
00228 
00229         x - 1
00230         1 - x
00231         x -= 1
00232 
00233         x * 1
00234         1 * x
00235         x *= 1
00236 
00237         x / 1
00238         1 / x
00239         x /= 1
00240 
00241         x // 1
00242         1 // x
00243         x //= 1
00244 
00245         x % 1
00246         1 % x
00247         x %= 1
00248 
00249         x ** 1
00250         1 ** x
00251         x **= 1
00252 
00253         x | 1
00254         1 | x
00255         x |= 1
00256 
00257         x & 1
00258         1 & x
00259         x &= 1
00260 
00261         x ^ 1
00262         1 ^ x
00263         x ^= 1
00264 
00265         x >> 1
00266         1 >> x
00267         x >>= 1
00268 
00269         x << 1
00270         1 << x
00271         x <<= 1
00272 
00273         test_self.assertEqual(output, '''\
00274 __add__ called
00275 __radd__ called
00276 __iadd__ called
00277 __sub__ called
00278 __rsub__ called
00279 __isub__ called
00280 __mul__ called
00281 __rmul__ called
00282 __imul__ called
00283 __truediv__ called
00284 __rtruediv__ called
00285 __itruediv__ called
00286 __floordiv__ called
00287 __rfloordiv__ called
00288 __ifloordiv__ called
00289 __mod__ called
00290 __rmod__ called
00291 __imod__ called
00292 __pow__ called
00293 __rpow__ called
00294 __ipow__ called
00295 __or__ called
00296 __ror__ called
00297 __ior__ called
00298 __and__ called
00299 __rand__ called
00300 __iand__ called
00301 __xor__ called
00302 __rxor__ called
00303 __ixor__ called
00304 __rshift__ called
00305 __rrshift__ called
00306 __irshift__ called
00307 __lshift__ called
00308 __rlshift__ called
00309 __ilshift__ called
00310 '''.splitlines())

Here is the call graph for this function:

Definition at line 39 of file test_augassign.py.

00039 
00040     def testInDict(self):
00041         x = {0: 2}
00042         x[0] += 1
00043         x[0] *= 2
00044         x[0] **= 2
00045         x[0] -= 8
00046         x[0] //= 5
00047         x[0] %= 3
00048         x[0] &= 2
00049         x[0] |= 5
00050         x[0] ^= 1
00051         x[0] /= 2
00052         self.assertEqual(x[0], 3.0)

Here is the call graph for this function:

Definition at line 25 of file test_augassign.py.

00025 
00026     def testInList(self):
00027         x = [2]
00028         x[0] += 1
00029         x[0] *= 2
00030         x[0] **= 2
00031         x[0] -= 8
00032         x[0] //= 5
00033         x[0] %= 3
00034         x[0] &= 2
00035         x[0] |= 5
00036         x[0] ^= 1
00037         x[0] /= 2
00038         self.assertEqual(x[0], 3.0)

Here is the call graph for this function:

Definition at line 53 of file test_augassign.py.

00053 
00054     def testSequences(self):
00055         x = [1,2]
00056         x += [3,4]
00057         x *= 2
00058 
00059         self.assertEqual(x, [1, 2, 3, 4, 1, 2, 3, 4])
00060 
00061         x = [1, 2, 3]
00062         y = x
00063         x[1:2] *= 2
00064         y[1:2] += [1]
00065 
00066         self.assertEqual(x, [1, 2, 1, 2, 3])
00067         self.assertTrue(x is y)

Here is the call graph for this function:


Member Data Documentation

Definition at line 72 of file test_augassign.py.


The documentation for this class was generated from the following file: