Changeset 391 for python/trunk/Lib/test/test_peepholer.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/test/test_peepholer.py
r2 r391 20 20 21 21 def test_unot(self): 22 # UNARY_NOT JUMP_IF_FALSE POP_TOP --> JUMP_IF_TRUE POP_TOP'22 # UNARY_NOT POP_JUMP_IF_FALSE --> POP_JUMP_IF_TRUE 23 23 def unot(x): 24 24 if not x == 2: 25 25 del x 26 26 asm = disassemble(unot) 27 for elem in ('UNARY_NOT', 'JUMP_IF_FALSE'): 28 self.assert_(elem not in asm) 29 for elem in ('JUMP_IF_TRUE', 'POP_TOP'): 30 self.assert_(elem in asm) 27 for elem in ('UNARY_NOT', 'POP_JUMP_IF_FALSE'): 28 self.assertNotIn(elem, asm) 29 self.assertIn('POP_JUMP_IF_TRUE', asm) 31 30 32 31 def test_elim_inversion_of_is_or_in(self): … … 38 37 ): 39 38 asm = dis_single(line) 40 self.assert _(elem inasm)39 self.assertIn(elem, asm) 41 40 42 41 def test_none_as_constant(self): … … 47 46 asm = disassemble(f) 48 47 for elem in ('LOAD_GLOBAL',): 49 self.assert _(elem not inasm)48 self.assertNotIn(elem, asm) 50 49 for elem in ('LOAD_CONST', '(None)'): 51 self.assert _(elem inasm)50 self.assertIn(elem, asm) 52 51 def f(): 53 52 'Adding a docstring made this test fail in Py2.5.0' 54 53 return None 55 self.assert _('LOAD_CONST' indisassemble(f))56 self.assert _('LOAD_GLOBAL' not indisassemble(f))54 self.assertIn('LOAD_CONST', disassemble(f)) 55 self.assertNotIn('LOAD_GLOBAL', disassemble(f)) 57 56 58 57 def test_while_one(self): 59 # Skip over: LOAD_CONST trueconst JUMP_IF_FALSE xx POP_TOP58 # Skip over: LOAD_CONST trueconst POP_JUMP_IF_FALSE xx 60 59 def f(): 61 60 while 1: … … 63 62 return list 64 63 asm = disassemble(f) 65 for elem in ('LOAD_CONST', ' JUMP_IF_FALSE'):66 self.assert _(elem not inasm)64 for elem in ('LOAD_CONST', 'POP_JUMP_IF_FALSE'): 65 self.assertNotIn(elem, asm) 67 66 for elem in ('JUMP_ABSOLUTE',): 68 self.assert _(elem inasm)67 self.assertIn(elem, asm) 69 68 70 69 def test_pack_unpack(self): … … 75 74 ): 76 75 asm = dis_single(line) 77 self.assert _(elem inasm)78 self.assert _('BUILD_TUPLE' not inasm)79 self.assert _('UNPACK_TUPLE' not inasm)76 self.assertIn(elem, asm) 77 self.assertNotIn('BUILD_TUPLE', asm) 78 self.assertNotIn('UNPACK_TUPLE', asm) 80 79 81 80 def test_folding_of_tuples_of_constants(self): … … 88 87 ): 89 88 asm = dis_single(line) 90 self.assert _(elem inasm)91 self.assert _('BUILD_TUPLE' not inasm)89 self.assertIn(elem, asm) 90 self.assertNotIn('BUILD_TUPLE', asm) 92 91 93 92 # Bug 1053819: Tuple of constants misidentified when presented with: … … 127 126 ): 128 127 asm = dis_single(line) 129 self.assert _(elem inasm, asm)130 self.assert _('BINARY_' not inasm)128 self.assertIn(elem, asm, asm) 129 self.assertNotIn('BINARY_', asm) 131 130 132 131 # Verify that unfoldables are skipped 133 132 asm = dis_single('a=2+"b"') 134 self.assert _('(2)' inasm)135 self.assert _("('b')" inasm)133 self.assertIn('(2)', asm) 134 self.assertIn("('b')", asm) 136 135 137 136 # Verify that large sequences do not result from folding 138 137 asm = dis_single('a="x"*1000') 139 self.assert_('(1000)' in asm) 138 self.assertIn('(1000)', asm) 139 140 def test_binary_subscr_on_unicode(self): 141 # unicode strings don't get optimized 142 asm = dis_single('u"foo"[0]') 143 self.assertNotIn("(u'f')", asm) 144 self.assertIn('BINARY_SUBSCR', asm) 145 asm = dis_single('u"\u0061\uffff"[1]') 146 self.assertNotIn("(u'\\uffff')", asm) 147 self.assertIn('BINARY_SUBSCR', asm) 148 149 # out of range 150 asm = dis_single('u"fuu"[10]') 151 self.assertIn('BINARY_SUBSCR', asm) 152 # non-BMP char (see #5057) 153 asm = dis_single('u"\U00012345"[0]') 154 self.assertIn('BINARY_SUBSCR', asm) 155 asm = dis_single('u"\U00012345abcdef"[3]') 156 self.assertIn('BINARY_SUBSCR', asm) 157 140 158 141 159 def test_folding_of_unaryops_on_constants(self): … … 146 164 ): 147 165 asm = dis_single(line) 148 self.assert _(elem inasm, asm)149 self.assert _('UNARY_' not inasm)166 self.assertIn(elem, asm, asm) 167 self.assertNotIn('UNARY_', asm) 150 168 151 169 # Verify that unfoldables are skipped … … 155 173 ): 156 174 asm = dis_single(line) 157 self.assert _(elem inasm, asm)158 self.assert _('UNARY_' inasm)175 self.assertIn(elem, asm, asm) 176 self.assertIn('UNARY_', asm) 159 177 160 178 def test_elim_extra_return(self): … … 163 181 return x 164 182 asm = disassemble(f) 165 self.assert _('LOAD_CONST' not inasm)166 self.assert _('(None)' not inasm)183 self.assertNotIn('LOAD_CONST', asm) 184 self.assertNotIn('(None)', asm) 167 185 self.assertEqual(asm.split().count('RETURN_VALUE'), 1) 168 186 … … 172 190 return true_value if cond else false_value 173 191 asm = disassemble(f) 174 self.assert _('JUMP_FORWARD' not inasm)175 self.assert _('JUMP_ABSOLUTE' not inasm)192 self.assertNotIn('JUMP_FORWARD', asm) 193 self.assertNotIn('JUMP_ABSOLUTE', asm) 176 194 self.assertEqual(asm.split().count('RETURN_VALUE'), 2) 177 195 … … 188 206 return 6 189 207 asm = disassemble(f) 190 self.assert _('JUMP_FORWARD' not inasm)191 self.assert _('JUMP_ABSOLUTE' not inasm)208 self.assertNotIn('JUMP_FORWARD', asm) 209 self.assertNotIn('JUMP_ABSOLUTE', asm) 192 210 self.assertEqual(asm.split().count('RETURN_VALUE'), 6) 193 211 … … 198 216 if cond1: return 4 199 217 asm = disassemble(f) 200 self.assert _('JUMP_FORWARD' not inasm)218 self.assertNotIn('JUMP_FORWARD', asm) 201 219 # There should be one jump for the while loop. 202 220 self.assertEqual(asm.split().count('JUMP_ABSOLUTE'), 1) … … 208 226 from test import test_support 209 227 test_classes = (TestTranforms,) 210 test_support.run_unittest(*test_classes) 211 212 # verify reference counting 213 if verbose and hasattr(sys, "gettotalrefcount"): 214 import gc 215 counts = [None] * 5 216 for i in xrange(len(counts)): 217 test_support.run_unittest(*test_classes) 218 gc.collect() 219 counts[i] = sys.gettotalrefcount() 220 print counts 228 229 with test_support.check_py3k_warnings( 230 ("backquote not supported", SyntaxWarning)): 231 test_support.run_unittest(*test_classes) 232 233 # verify reference counting 234 if verbose and hasattr(sys, "gettotalrefcount"): 235 import gc 236 counts = [None] * 5 237 for i in xrange(len(counts)): 238 test_support.run_unittest(*test_classes) 239 gc.collect() 240 counts[i] = sys.gettotalrefcount() 241 print counts 221 242 222 243 if __name__ == "__main__":
Note:
See TracChangeset
for help on using the changeset viewer.