MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_show_currinstr_with_cache

Method test_show_currinstr_with_cache

Lib/test/test_dis.py:1431–1459  ·  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

1429
1430 @cpython_only
1431 def test_show_currinstr_with_cache(self):
1432 """
1433 Make sure that with lasti pointing to CACHE, it still shows the current
1434 line correctly
1435 """
1436 def f():
1437 print(a)
1438 # The code above should generate a LOAD_GLOBAL which has CACHE instr after
1439 # However, this might change in the future. So we explicitly try to find
1440 # a CACHE entry in the instructions. If we can't do that, fail the test
1441
1442 for inst in _unroll_caches_as_Instructions(
1443 dis.get_instructions(f, show_caches=True), show_caches=True):
1444 if inst.opname == "CACHE":
1445 op_offset = inst.offset - 2
1446 cache_offset = inst.offset
1447 break
1448 else:
1449 opname = inst.opname
1450 else:
1451 self.fail("Can't find a CACHE entry in the function provided to do the test")
1452
1453 assem_op = self.get_disassembly(f.__code__, lasti=op_offset, wrapper=False)
1454 assem_cache = self.get_disassembly(f.__code__, lasti=cache_offset, wrapper=False)
1455
1456 # Make sure --> exists and points to the correct op
1457 self.assertRegex(assem_op, fr"--> {opname}")
1458 # Make sure when lasti points to cache, it shows the same disassembly
1459 self.assertEqual(assem_op, assem_cache)
1460
1461
1462class 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