OLD | NEW |
1 import dis | 1 import dis |
2 import re | 2 import re |
3 import sys | 3 import sys |
4 from io import StringIO | 4 from io import StringIO |
5 import unittest | 5 import unittest |
6 from math import copysign | 6 from math import copysign |
7 | 7 |
8 from test.bytecode_helper import BytecodeTestCase | 8 from test.bytecode_helper import BytecodeTestCase |
9 | 9 |
10 class TestTranforms(BytecodeTestCase): | 10 class TestTranforms(BytecodeTestCase): |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 self.assertInBytecode(code, 'LOAD_CONST', elem) | 134 self.assertInBytecode(code, 'LOAD_CONST', elem) |
135 | 135 |
136 # Ensure that the resulting code actually works: | 136 # Ensure that the resulting code actually works: |
137 def f(a): | 137 def f(a): |
138 return a in {1, 2, 3} | 138 return a in {1, 2, 3} |
139 | 139 |
140 def g(a): | 140 def g(a): |
141 return a not in {1, 2, 3} | 141 return a not in {1, 2, 3} |
142 | 142 |
143 self.assertTrue(f(3)) | 143 self.assertTrue(f(3)) |
144 self.assertTrue(not f(4)) | 144 self.assertFalse(f(4)) |
145 | 145 |
146 self.assertTrue(not g(3)) | 146 self.assertFalse(g(3)) |
147 self.assertTrue(g(4)) | 147 self.assertTrue(g(4)) |
148 | 148 |
149 | 149 |
150 def test_folding_of_binops_on_constants(self): | 150 def test_folding_of_binops_on_constants(self): |
151 for line, elem in ( | 151 for line, elem in ( |
152 ('a = 2+3+4', 9), # chained fold | 152 ('a = 2+3+4', 9), # chained fold |
153 ('"@"*4', '@@@@'), # check string ops | 153 ('"@"*4', '@@@@'), # check string ops |
154 ('a="abc" + "def"', 'abcdef'), # check string ops | 154 ('a="abc" + "def"', 'abcdef'), # check string ops |
155 ('a = 3**4', 81), # binary power | 155 ('a = 3**4', 81), # binary power |
156 ('a = 3*4', 12), # binary multiply | 156 ('a = 3*4', 12), # binary multiply |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 import gc | 330 import gc |
331 counts = [None] * 5 | 331 counts = [None] * 5 |
332 for i in range(len(counts)): | 332 for i in range(len(counts)): |
333 support.run_unittest(*test_classes) | 333 support.run_unittest(*test_classes) |
334 gc.collect() | 334 gc.collect() |
335 counts[i] = sys.gettotalrefcount() | 335 counts[i] = sys.gettotalrefcount() |
336 print(counts) | 336 print(counts) |
337 | 337 |
338 if __name__ == "__main__": | 338 if __name__ == "__main__": |
339 test_main(verbose=True) | 339 test_main(verbose=True) |
OLD | NEW |