Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve cache test to explicitly find CACHE entry
  • Loading branch information
gaogaotiantian committed Mar 27, 2023
commit dfadcd69efd981dc614b33c549d2a629163e9cfd
21 changes: 17 additions & 4 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1200,13 +1200,26 @@ def test_show_caches(self):

@cpython_only
def test_show_currinstr_with_cache(self):
"""
Make sure that with lasti pointing to CACHE, it still shows the current
line correctly
Comment thread
iritkatriel marked this conversation as resolved.
"""
def f():
print(a)
# The code above should generate a LOAD_GLOBAL which has CACHE instr after
# Make sure that with lasti pointing to CACHE, it still shows the current
# line correctly
self.assertEqual(self.get_disassembly(f.__code__, lasti=2, wrapper=False),
self.get_disassembly(f.__code__, lasti=4, wrapper=False))
# However, this might change in the future. So we explicitly try to find
# a CACHE entry in the instructions. If we can't do that, fail the test

for inst in dis.get_instructions(f, show_caches=True):
if inst.opname == "CACHE":
op_offset = inst.offset - 2
cache_offset = inst.offset
break
else:
self.fail("Can't find a CACHE entry in the function provided to do the test")

self.assertEqual(self.get_disassembly(f.__code__, lasti=op_offset, wrapper=False),
self.get_disassembly(f.__code__, lasti=cache_offset, wrapper=False))


class DisWithFileTests(DisTests):
Expand Down