Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4)

Side by Side Diff: Lib/test/test_augassign.py

Issue 25958: Implicit ABCs have no means of "anti-registration"
Patch Set: Created 4 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Augmented assignment test. 1 # Augmented assignment test.
2 2
3 import unittest 3 import unittest
4 4
5 5
6 class AugAssignTest(unittest.TestCase): 6 class AugAssignTest(unittest.TestCase):
7 def testBasic(self): 7 def testBasic(self):
8 x = 2 8 x = 2
9 x += 1 9 x += 1
10 x *= 2 10 x *= 2
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 return aug_test(self.val + val) 75 return aug_test(self.val + val)
76 76
77 class aug_test2(aug_test): 77 class aug_test2(aug_test):
78 def __iadd__(self, val): 78 def __iadd__(self, val):
79 self.val = self.val + val 79 self.val = self.val + val
80 return self 80 return self
81 81
82 class aug_test3(aug_test): 82 class aug_test3(aug_test):
83 def __iadd__(self, val): 83 def __iadd__(self, val):
84 return aug_test3(self.val + val) 84 return aug_test3(self.val + val)
85
86 class aug_test4(aug_test3):
87 "Blocks inheritance, and fallback to __add__"
Martin Panter 2016/01/09 02:34:57 I think triple quotes (or triple double-quotes) ar
abarnert 2016/01/18 20:28:42 Thanks; fixed.
88 __iadd__ = None
85 89
86 x = aug_test(1) 90 x = aug_test(1)
87 y = x 91 y = x
88 x += 10 92 x += 10
89 93
90 self.assertIsInstance(x, aug_test) 94 self.assertIsInstance(x, aug_test)
91 self.assertTrue(y is not x) 95 self.assertTrue(y is not x)
92 self.assertEqual(x.val, 11) 96 self.assertEqual(x.val, 11)
93 97
94 x = aug_test2(2) 98 x = aug_test2(2)
95 y = x 99 y = x
96 x += 10 100 x += 10
97 101
98 self.assertTrue(y is x) 102 self.assertTrue(y is x)
99 self.assertEqual(x.val, 12) 103 self.assertEqual(x.val, 12)
100 104
101 x = aug_test3(3) 105 x = aug_test3(3)
102 y = x 106 y = x
103 x += 10 107 x += 10
104 108
105 self.assertIsInstance(x, aug_test3) 109 self.assertIsInstance(x, aug_test3)
106 self.assertTrue(y is not x) 110 self.assertTrue(y is not x)
107 self.assertEqual(x.val, 13) 111 self.assertEqual(x.val, 13)
108 112
113 x = aug_test4(4)
114 with self.assertRaises(TypeError):
115 x += 10
109 116
110 def testCustomMethods2(test_self): 117 def testCustomMethods2(test_self):
111 output = [] 118 output = []
112 119
113 class testall: 120 class testall:
114 def __add__(self, val): 121 def __add__(self, val):
115 output.append("__add__ called") 122 output.append("__add__ called")
116 def __radd__(self, val): 123 def __radd__(self, val):
117 output.append("__radd__ called") 124 output.append("__radd__ called")
118 def __iadd__(self, val): 125 def __iadd__(self, val):
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 __rshift__ called 316 __rshift__ called
310 __rrshift__ called 317 __rrshift__ called
311 __irshift__ called 318 __irshift__ called
312 __lshift__ called 319 __lshift__ called
313 __rlshift__ called 320 __rlshift__ called
314 __ilshift__ called 321 __ilshift__ called
315 '''.splitlines()) 322 '''.splitlines())
316 323
317 if __name__ == '__main__': 324 if __name__ == '__main__':
318 unittest.main() 325 unittest.main()
OLDNEW
« no previous file with comments | « Lib/_collections_abc.py ('k') | Lib/test/test_binop.py » ('j') | Lib/test/test_binop.py » ('J')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+