diff options
Diffstat (limited to 'Lib/test/test_peepholer.py')
-rw-r--r-- | Lib/test/test_peepholer.py | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py index fcd7ccc..531b425 100644 --- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -26,9 +26,9 @@ class TestTranforms(unittest.TestCase): del x asm = disassemble(unot) for elem in ('UNARY_NOT', 'POP_JUMP_IF_FALSE'): - self.assertTrue(elem not in asm) + self.assertNotIn(elem, asm) for elem in ('POP_JUMP_IF_TRUE',): - self.assertTrue(elem in asm) + self.assertIn(elem, asm) def test_elim_inversion_of_is_or_in(self): for line, elem in ( @@ -38,7 +38,7 @@ class TestTranforms(unittest.TestCase): ('not a not in b', '(in)',), ): asm = dis_single(line) - self.assertTrue(elem in asm) + self.assertIn(elem, asm) def test_global_as_constant(self): # LOAD_GLOBAL None/True/False --> LOAD_CONST None/True/False @@ -55,14 +55,14 @@ class TestTranforms(unittest.TestCase): for func, name in ((f, 'None'), (g, 'True'), (h, 'False')): asm = disassemble(func) for elem in ('LOAD_GLOBAL',): - self.assertTrue(elem not in asm) + self.assertNotIn(elem, asm) for elem in ('LOAD_CONST', '('+name+')'): - self.assertTrue(elem in asm) + self.assertIn(elem, asm) def f(): 'Adding a docstring made this test fail in Py2.5.0' return None - self.assertTrue('LOAD_CONST' in disassemble(f)) - self.assertTrue('LOAD_GLOBAL' not in disassemble(f)) + self.assertIn('LOAD_CONST', disassemble(f)) + self.assertNotIn('LOAD_GLOBAL', disassemble(f)) def test_while_one(self): # Skip over: LOAD_CONST trueconst POP_JUMP_IF_FALSE xx @@ -72,9 +72,9 @@ class TestTranforms(unittest.TestCase): return list asm = disassemble(f) for elem in ('LOAD_CONST', 'POP_JUMP_IF_FALSE'): - self.assertTrue(elem not in asm) + self.assertNotIn(elem, asm) for elem in ('JUMP_ABSOLUTE',): - self.assertTrue(elem in asm) + self.assertIn(elem, asm) def test_pack_unpack(self): for line, elem in ( @@ -83,9 +83,9 @@ class TestTranforms(unittest.TestCase): ('a, b, c = a, b, c', 'ROT_THREE',), ): asm = dis_single(line) - self.assertTrue(elem in asm) - self.assertTrue('BUILD_TUPLE' not in asm) - self.assertTrue('UNPACK_TUPLE' not in asm) + self.assertIn(elem, asm) + self.assertNotIn('BUILD_TUPLE', asm) + self.assertNotIn('UNPACK_TUPLE', asm) def test_folding_of_tuples_of_constants(self): for line, elem in ( @@ -96,8 +96,8 @@ class TestTranforms(unittest.TestCase): ('((1, 2), 3, 4)', '(((1, 2), 3, 4))'), ): asm = dis_single(line) - self.assertTrue(elem in asm) - self.assertTrue('BUILD_TUPLE' not in asm) + self.assertIn(elem, asm) + self.assertNotIn('BUILD_TUPLE', asm) # Bug 1053819: Tuple of constants misidentified when presented with: # . . . opcode_with_arg 100 unary_opcode BUILD_TUPLE 1 . . . @@ -183,17 +183,17 @@ class TestTranforms(unittest.TestCase): ('a = 13 | 7', '(15)'), # binary or ): asm = dis_single(line) - self.assertTrue(elem in asm, asm) - self.assertTrue('BINARY_' not in asm) + self.assertIn(elem, asm, asm) + self.assertNotIn('BINARY_', asm) # Verify that unfoldables are skipped asm = dis_single('a=2+"b"') - self.assertTrue('(2)' in asm) - self.assertTrue("('b')" in asm) + self.assertIn('(2)', asm) + self.assertIn("('b')", asm) # Verify that large sequences do not result from folding asm = dis_single('a="x"*1000') - self.assertTrue('(1000)' in asm) + self.assertIn('(1000)', asm) def test_folding_of_unaryops_on_constants(self): for line, elem in ( @@ -202,8 +202,8 @@ class TestTranforms(unittest.TestCase): ('+1', '(1)'), # unary positive ): asm = dis_single(line) - self.assertTrue(elem in asm, asm) - self.assertTrue('UNARY_' not in asm) + self.assertIn(elem, asm, asm) + self.assertNotIn('UNARY_', asm) # Verify that unfoldables are skipped for line, elem in ( @@ -211,16 +211,16 @@ class TestTranforms(unittest.TestCase): ('~"abc"', "('abc')"), # unary invert ): asm = dis_single(line) - self.assertTrue(elem in asm, asm) - self.assertTrue('UNARY_' in asm) + self.assertIn(elem, asm, asm) + self.assertIn('UNARY_', asm) def test_elim_extra_return(self): # RETURN LOAD_CONST None RETURN --> RETURN def f(x): return x asm = disassemble(f) - self.assertTrue('LOAD_CONST' not in asm) - self.assertTrue('(None)' not in asm) + self.assertNotIn('LOAD_CONST', asm) + self.assertNotIn('(None)', asm) self.assertEqual(asm.split().count('RETURN_VALUE'), 1) def test_elim_jump_to_return(self): @@ -228,8 +228,8 @@ class TestTranforms(unittest.TestCase): def f(cond, true_value, false_value): return true_value if cond else false_value asm = disassemble(f) - self.assertTrue('JUMP_FORWARD' not in asm) - self.assertTrue('JUMP_ABSOLUTE' not in asm) + self.assertNotIn('JUMP_FORWARD', asm) + self.assertNotIn('JUMP_ABSOLUTE', asm) self.assertEqual(asm.split().count('RETURN_VALUE'), 2) def test_elim_jump_after_return1(self): @@ -244,8 +244,8 @@ class TestTranforms(unittest.TestCase): return 5 return 6 asm = disassemble(f) - self.assertTrue('JUMP_FORWARD' not in asm) - self.assertTrue('JUMP_ABSOLUTE' not in asm) + self.assertNotIn('JUMP_FORWARD', asm) + self.assertNotIn('JUMP_ABSOLUTE', asm) self.assertEqual(asm.split().count('RETURN_VALUE'), 6) def test_elim_jump_after_return2(self): @@ -254,7 +254,7 @@ class TestTranforms(unittest.TestCase): while 1: if cond1: return 4 asm = disassemble(f) - self.assertTrue('JUMP_FORWARD' not in asm) + self.assertNotIn('JUMP_FORWARD', asm) # There should be one jump for the while loop. self.assertEqual(asm.split().count('JUMP_ABSOLUTE'), 1) self.assertEqual(asm.split().count('RETURN_VALUE'), 2) @@ -265,7 +265,7 @@ class TestTranforms(unittest.TestCase): pass return g asm = disassemble(f) - self.assertTrue('BINARY_ADD' not in asm) + self.assertNotIn('BINARY_ADD', asm) def test_main(verbose=None): |