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

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

Issue 16510: Using appropriate checks in tests
Patch Set: Created 5 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/test/test_asyncore.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 from test.support import run_unittest 3 from test.support import run_unittest
4 import unittest 4 import unittest
5 5
6 6
7 class AugAssignTest(unittest.TestCase): 7 class AugAssignTest(unittest.TestCase):
8 def testBasic(self): 8 def testBasic(self):
9 x = 2 9 x = 2
10 x += 1 10 x += 1
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 x *= 2 56 x *= 2
57 57
58 self.assertEqual(x, [1, 2, 3, 4, 1, 2, 3, 4]) 58 self.assertEqual(x, [1, 2, 3, 4, 1, 2, 3, 4])
59 59
60 x = [1, 2, 3] 60 x = [1, 2, 3]
61 y = x 61 y = x
62 x[1:2] *= 2 62 x[1:2] *= 2
63 y[1:2] += [1] 63 y[1:2] += [1]
64 64
65 self.assertEqual(x, [1, 2, 1, 2, 3]) 65 self.assertEqual(x, [1, 2, 1, 2, 3])
66 self.assertTrue(x is y) 66 self.assertIs(x, y)
67 67
68 def testCustomMethods1(self): 68 def testCustomMethods1(self):
69 69
70 class aug_test: 70 class aug_test:
71 def __init__(self, value): 71 def __init__(self, value):
72 self.val = value 72 self.val = value
73 def __radd__(self, val): 73 def __radd__(self, val):
74 return self.val + val 74 return self.val + val
75 def __add__(self, val): 75 def __add__(self, val):
76 return aug_test(self.val + val) 76 return aug_test(self.val + val)
77 77
78 class aug_test2(aug_test): 78 class aug_test2(aug_test):
79 def __iadd__(self, val): 79 def __iadd__(self, val):
80 self.val = self.val + val 80 self.val = self.val + val
81 return self 81 return self
82 82
83 class aug_test3(aug_test): 83 class aug_test3(aug_test):
84 def __iadd__(self, val): 84 def __iadd__(self, val):
85 return aug_test3(self.val + val) 85 return aug_test3(self.val + val)
86 86
87 x = aug_test(1) 87 x = aug_test(1)
88 y = x 88 y = x
89 x += 10 89 x += 10
90 90
91 self.assertIsInstance(x, aug_test) 91 self.assertIsInstance(x, aug_test)
92 self.assertTrue(y is not x) 92 self.assertIsNot(y, x)
93 self.assertEqual(x.val, 11) 93 self.assertEqual(x.val, 11)
94 94
95 x = aug_test2(2) 95 x = aug_test2(2)
96 y = x 96 y = x
97 x += 10 97 x += 10
98 98
99 self.assertTrue(y is x) 99 self.assertIs(y, x)
100 self.assertEqual(x.val, 12) 100 self.assertEqual(x.val, 12)
101 101
102 x = aug_test3(3) 102 x = aug_test3(3)
103 y = x 103 y = x
104 x += 10 104 x += 10
105 105
106 self.assertIsInstance(x, aug_test3) 106 self.assertIsInstance(x, aug_test3)
107 self.assertTrue(y is not x) 107 self.assertIsNot(y, x)
108 self.assertEqual(x.val, 13) 108 self.assertEqual(x.val, 13)
109 109
110 110
111 def testCustomMethods2(test_self): 111 def testCustomMethods2(test_self):
112 output = [] 112 output = []
113 113
114 class testall: 114 class testall:
115 def __add__(self, val): 115 def __add__(self, val):
116 output.append("__add__ called") 116 output.append("__add__ called")
117 def __radd__(self, val): 117 def __radd__(self, val):
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 __lshift__ called 306 __lshift__ called
307 __rlshift__ called 307 __rlshift__ called
308 __ilshift__ called 308 __ilshift__ called
309 '''.splitlines()) 309 '''.splitlines())
310 310
311 def test_main(): 311 def test_main():
312 run_unittest(AugAssignTest) 312 run_unittest(AugAssignTest)
313 313
314 if __name__ == '__main__': 314 if __name__ == '__main__':
315 test_main() 315 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_asyncore.py ('k') | Lib/test/test_binop.py » ('j') | no next file with comments »

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