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

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

Issue 5057: Unicode-width dependent optimization leads to non-portable pyc file
Patch Set: Created 2 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
« no previous file with comments | « no previous file | Python/peephole.c » ('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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 self.assertNotIn('BINARY_', asm) 197 self.assertNotIn('BINARY_', asm)
198 198
199 # Verify that unfoldables are skipped 199 # Verify that unfoldables are skipped
200 asm = dis_single('a=2+"b"') 200 asm = dis_single('a=2+"b"')
201 self.assertIn('(2)', asm) 201 self.assertIn('(2)', asm)
202 self.assertIn("('b')", asm) 202 self.assertIn("('b')", asm)
203 203
204 # Verify that large sequences do not result from folding 204 # Verify that large sequences do not result from folding
205 asm = dis_single('a="x"*1000') 205 asm = dis_single('a="x"*1000')
206 self.assertIn('(1000)', asm) 206 self.assertIn('(1000)', asm)
207
208 def test_binary_subscr_on_unicode(self):
209 # valid code get optimized
210 asm = dis_single('"foo"[0]')
211 self.assertIn("('f')", asm)
212 self.assertNotIn('BINARY_SUBSCR', asm)
213 asm = dis_single('"\u0061\uffff"[1]')
214 self.assertIn("('\\uffff')", asm)
215 self.assertNotIn('BINARY_SUBSCR', asm)
216
217 # invalid code doesn't get optimized
218 # out of range
219 asm = dis_single('"fuu"[10]')
220 self.assertIn('BINARY_SUBSCR', asm)
221 # non-BMP char (see #5057)
222 asm = dis_single('"\U00012345"[0]')
223 self.assertIn('BINARY_SUBSCR', asm)
224
207 225
208 def test_folding_of_unaryops_on_constants(self): 226 def test_folding_of_unaryops_on_constants(self):
209 for line, elem in ( 227 for line, elem in (
210 ('-0.5', '(-0.5)'), # unary negative 228 ('-0.5', '(-0.5)'), # unary negative
211 ('-0.0', '(-0.0)'), # -0.0 229 ('-0.0', '(-0.0)'), # -0.0
212 ('-(1.0-1.0)','(-0.0)'), # -0.0 after folding 230 ('-(1.0-1.0)','(-0.0)'), # -0.0 after folding
213 ('-0', '(0)'), # -0 231 ('-0', '(0)'), # -0
214 ('~-2', '(1)'), # unary invert 232 ('~-2', '(1)'), # unary invert
215 ('+1', '(1)'), # unary positive 233 ('+1', '(1)'), # unary positive
216 ): 234 ):
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 import gc 348 import gc
331 counts = [None] * 5 349 counts = [None] * 5
332 for i in range(len(counts)): 350 for i in range(len(counts)):
333 support.run_unittest(*test_classes) 351 support.run_unittest(*test_classes)
334 gc.collect() 352 gc.collect()
335 counts[i] = sys.gettotalrefcount() 353 counts[i] = sys.gettotalrefcount()
336 print(counts) 354 print(counts)
337 355
338 if __name__ == "__main__": 356 if __name__ == "__main__":
339 test_main(verbose=True) 357 test_main(verbose=True)
OLDNEW
« no previous file with comments | « no previous file | Python/peephole.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7