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

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

Issue 25958: Implicit ABCs have no means of "anti-registration"
Patch Set: Created 3 years, 6 months 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
« no previous file with comments | « Lib/_collections_abc.py ('k') | Lib/test/test_binop.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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__"""
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)
112
113 x = aug_test4(4)
114 with self.assertRaises(TypeError):
115 x += 10
108 116
109 117
110 def testCustomMethods2(test_self): 118 def testCustomMethods2(test_self):
111 output = [] 119 output = []
112 120
113 class testall: 121 class testall:
114 def __add__(self, val): 122 def __add__(self, val):
115 output.append("__add__ called") 123 output.append("__add__ called")
116 def __radd__(self, val): 124 def __radd__(self, val):
117 output.append("__radd__ called") 125 output.append("__radd__ called")
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 __rshift__ called 317 __rshift__ called
310 __rrshift__ called 318 __rrshift__ called
311 __irshift__ called 319 __irshift__ called
312 __lshift__ called 320 __lshift__ called
313 __rlshift__ called 321 __rlshift__ called
314 __ilshift__ called 322 __ilshift__ called
315 '''.splitlines()) 323 '''.splitlines())
316 324
317 if __name__ == '__main__': 325 if __name__ == '__main__':
318 unittest.main() 326 unittest.main()
OLDNEW
« no previous file with comments | « Lib/_collections_abc.py ('k') | Lib/test/test_binop.py » ('j') | no next file with comments »

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