MCPcopy Index your code
hub / github.com/python/cpython / test_show_currinstr_with_cache

Method test_show_currinstr_with_cache

Lib/test/test_dis.py:1452–1480  ·  view source on GitHub ↗

Make sure that with lasti pointing to CACHE, it still shows the current line correctly

(self)

Source from the content-addressed store, hash-verified

1450
1451 @cpython_only
1452 def test_show_currinstr_with_cache(self):
1453 """
1454 Make sure that with lasti pointing to CACHE, it still shows the current
1455 line correctly
1456 """
1457 def f():
1458 print(a)
1459 # The code above should generate a LOAD_GLOBAL which has CACHE instr after
1460 # However, this might change in the future. So we explicitly try to find
1461 # a CACHE entry in the instructions. If we can't do that, fail the test
1462
1463 for inst in _unroll_caches_as_Instructions(
1464 dis.get_instructions(f, show_caches=True), show_caches=True):
1465 if inst.opname == "CACHE":
1466 op_offset = inst.offset - 2
1467 cache_offset = inst.offset
1468 break
1469 else:
1470 opname = inst.opname
1471 else:
1472 self.fail("Can't find a CACHE entry in the function provided to do the test")
1473
1474 assem_op = self.get_disassembly(f.__code__, lasti=op_offset, wrapper=False)
1475 assem_cache = self.get_disassembly(f.__code__, lasti=cache_offset, wrapper=False)
1476
1477 # Make sure --> exists and points to the correct op
1478 self.assertRegex(assem_op, fr"--> {opname}")
1479 # Make sure when lasti points to cache, it shows the same disassembly
1480 self.assertEqual(assem_op, assem_cache)
1481
1482
1483class DisWithFileTests(DisTests):

Callers

nothing calls this directly

Calls 6

get_disassemblyMethod · 0.95
get_instructionsMethod · 0.80
assertRegexMethod · 0.80
failMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected