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

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

Issue 16510: Using appropriate checks in tests
Patch Set: Created 6 years 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_ossaudiodev.py ('k') | Lib/test/test_pep3120.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 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 def disassemble(func): 8 def disassemble(func):
9 f = StringIO() 9 f = StringIO()
10 tmp = sys.stdout 10 tmp = sys.stdout
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 self.assertEqual(eval(m.group(1)), elem) 161 self.assertEqual(eval(m.group(1)), elem)
162 162
163 # Ensure that the resulting code actually works: 163 # Ensure that the resulting code actually works:
164 def f(a): 164 def f(a):
165 return a in {1, 2, 3} 165 return a in {1, 2, 3}
166 166
167 def g(a): 167 def g(a):
168 return a not in {1, 2, 3} 168 return a not in {1, 2, 3}
169 169
170 self.assertTrue(f(3)) 170 self.assertTrue(f(3))
171 self.assertTrue(not f(4)) 171 self.assertFalse(f(4))
172 172
173 self.assertTrue(not g(3)) 173 self.assertFalse(g(3))
174 self.assertTrue(g(4)) 174 self.assertTrue(g(4))
175 175
176 176
177 def test_folding_of_binops_on_constants(self): 177 def test_folding_of_binops_on_constants(self):
178 for line, elem in ( 178 for line, elem in (
179 ('a = 2+3+4', '(9)'), # chained fold 179 ('a = 2+3+4', '(9)'), # chained fold
180 ('"@"*4', "('@@@@')"), # check string ops 180 ('"@"*4', "('@@@@')"), # check string ops
181 ('a="abc" + "def"', "('abcdef')"), # check string ops 181 ('a="abc" + "def"', "('abcdef')"), # check string ops
182 ('a = 3**4', '(81)'), # binary power 182 ('a = 3**4', '(81)'), # binary power
183 ('a = 3*4', '(12)'), # binary multiply 183 ('a = 3*4', '(12)'), # binary multiply
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 ): 233 ):
234 asm = dis_single(line) 234 asm = dis_single(line)
235 self.assertIn(elem, asm, asm) 235 self.assertIn(elem, asm, asm)
236 self.assertNotIn('UNARY_', asm) 236 self.assertNotIn('UNARY_', asm)
237 237
238 # Check that -0.0 works after marshaling 238 # Check that -0.0 works after marshaling
239 def negzero(): 239 def negzero():
240 return -(1.0-1.0) 240 return -(1.0-1.0)
241 241
242 self.assertNotIn('UNARY_', disassemble(negzero)) 242 self.assertNotIn('UNARY_', disassemble(negzero))
243 self.assertTrue(copysign(1.0, negzero()) < 0) 243 self.assertLess(copysign(1.0, negzero()), 0)
244 244
245 # Verify that unfoldables are skipped 245 # Verify that unfoldables are skipped
246 for line, elem in ( 246 for line, elem in (
247 ('-"abc"', "('abc')"), # unary negative 247 ('-"abc"', "('abc')"), # unary negative
248 ('~"abc"', "('abc')"), # unary invert 248 ('~"abc"', "('abc')"), # unary invert
249 ): 249 ):
250 asm = dis_single(line) 250 asm = dis_single(line)
251 self.assertIn(elem, asm, asm) 251 self.assertIn(elem, asm, asm)
252 self.assertIn('UNARY_', asm) 252 self.assertIn('UNARY_', asm)
253 253
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 import gc 347 import gc
348 counts = [None] * 5 348 counts = [None] * 5
349 for i in range(len(counts)): 349 for i in range(len(counts)):
350 support.run_unittest(*test_classes) 350 support.run_unittest(*test_classes)
351 gc.collect() 351 gc.collect()
352 counts[i] = sys.gettotalrefcount() 352 counts[i] = sys.gettotalrefcount()
353 print(counts) 353 print(counts)
354 354
355 if __name__ == "__main__": 355 if __name__ == "__main__":
356 test_main(verbose=True) 356 test_main(verbose=True)
OLDNEW
« no previous file with comments | « Lib/test/test_ossaudiodev.py ('k') | Lib/test/test_pep3120.py » ('j') | no next file with comments »

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