(self)
| 503 | |
| 504 | @requires_debug_ranges() |
| 505 | def test_co_positions_artificial_instructions(self): |
| 506 | import dis |
| 507 | |
| 508 | namespace = {} |
| 509 | exec(textwrap.dedent("""\ |
| 510 | try: |
| 511 | 1/0 |
| 512 | except Exception as e: |
| 513 | exc = e |
| 514 | """), namespace) |
| 515 | |
| 516 | exc = namespace['exc'] |
| 517 | traceback = exc.__traceback__ |
| 518 | code = traceback.tb_frame.f_code |
| 519 | |
| 520 | artificial_instructions = [] |
| 521 | for instr, positions in instructions_with_positions( |
| 522 | dis.get_instructions(code), code.co_positions() |
| 523 | ): |
| 524 | # If any of the positions is None, then all have to |
| 525 | # be None as well for the case above. There are still |
| 526 | # some places in the compiler, where the artificial instructions |
| 527 | # get assigned the first_lineno but they don't have other positions. |
| 528 | # There is no easy way of inferring them at that stage, so for now |
| 529 | # we don't support it. |
| 530 | self.assertIn(positions.count(None), [0, 3, 4]) |
| 531 | |
| 532 | if not any(positions): |
| 533 | artificial_instructions.append(instr) |
| 534 | |
| 535 | self.assertEqual( |
| 536 | [ |
| 537 | (instruction.opname, instruction.argval) |
| 538 | for instruction in artificial_instructions |
| 539 | ], |
| 540 | [ |
| 541 | ("PUSH_EXC_INFO", None), |
| 542 | ("LOAD_CONST", None), # artificial 'None' |
| 543 | ("STORE_NAME", "e"), # XX: we know the location for this |
| 544 | ("DELETE_NAME", "e"), |
| 545 | ("RERAISE", 1), |
| 546 | ("COPY", 3), |
| 547 | ("POP_EXCEPT", None), |
| 548 | ("RERAISE", 1) |
| 549 | ] |
| 550 | ) |
| 551 | |
| 552 | def test_endline_and_columntable_none_when_no_debug_ranges(self): |
| 553 | # Make sure that if `-X no_debug_ranges` is used, there is |
nothing calls this directly
no test coverage detected