diff options
Diffstat (limited to 'Lib/test/test_compile.py')
-rw-r--r-- | Lib/test/test_compile.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index ac06518..d329cb1 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -984,6 +984,38 @@ if 1: elif instr.opname in HANDLED_JUMPS: self.assertNotEqual(instr.arg, (line + 1)*INSTR_SIZE) + def test_compare_positions(self): + for opname, op in [ + ("COMPARE_OP", "<"), + ("COMPARE_OP", "<="), + ("COMPARE_OP", ">"), + ("COMPARE_OP", ">="), + ("CONTAINS_OP", "in"), + ("CONTAINS_OP", "not in"), + ("IS_OP", "is"), + ("IS_OP", "is not"), + ]: + expr = f'a {op} b {op} c' + expected_lines = 2 * [2] + for source in [ + f"\\\n{expr}", f'if \\\n{expr}: x', f"x if \\\n{expr} else y" + ]: + code = compile(source, "<test>", "exec") + all_lines = ( + line + for start, stop, line in code.co_lines() + for _ in range(start, stop, 2) + ) + actual_lines = [ + line + for instruction, line in zip( + dis.get_instructions(code), all_lines, strict=True + ) + if instruction.opname == opname + ] + with self.subTest(source): + self.assertEqual(actual_lines, expected_lines) + class TestExpressionStackSize(unittest.TestCase): # These tests check that the computed stack size for a code object |