Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
add test with offsets
  • Loading branch information
iritkatriel committed Nov 22, 2023
commit 823b0e1f9e4d2ff122528f75ccb9b41ed2ad34dd
23 changes: 19 additions & 4 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ def _f(a):
_f.__code__.co_firstlineno + 1,
_f.__code__.co_firstlineno + 2)

dis_f_with_offsets = """\
%3d 0 RESUME 0

%3d 2 LOAD_GLOBAL 1 (print + NULL)
12 LOAD_FAST 0 (a)
14 CALL 1
22 POP_TOP

%3d 24 RETURN_CONST 1 (1)
""" % (_f.__code__.co_firstlineno,
_f.__code__.co_firstlineno + 1,
_f.__code__.co_firstlineno + 2)


dis_f_co_code = """\
RESUME 0
Expand All @@ -122,7 +135,6 @@ def _f(a):
RETURN_CONST 1
"""


def bug708901():
for res in range(1,
10):
Expand Down Expand Up @@ -899,15 +911,15 @@ def get_disassembly(self, func, lasti=-1, wrapper=True, **kwargs):
def get_disassemble_as_string(self, func, lasti=-1):
return self.get_disassembly(func, lasti, False)

def do_disassembly_test(self, func, expected):
def do_disassembly_test(self, func, expected, **kwargs):
self.maxDiff = None
got = self.get_disassembly(func, depth=0)
got = self.get_disassembly(func, depth=0, **kwargs)
self.do_disassembly_compare(got, expected)
# Add checks for dis.disco
if hasattr(func, '__code__'):
got_disco = io.StringIO()
with contextlib.redirect_stdout(got_disco):
dis.disco(func.__code__)
dis.disco(func.__code__, **kwargs)
self.do_disassembly_compare(got_disco.getvalue(), expected)

def test_opmap(self):
Expand Down Expand Up @@ -936,6 +948,9 @@ def test_widths(self):
def test_dis(self):
self.do_disassembly_test(_f, dis_f)

def test_dis_with_offsets(self):
self.do_disassembly_test(_f, dis_f_with_offsets, show_offsets=True)

def test_bug_708901(self):
self.do_disassembly_test(bug708901, dis_bug708901)

Expand Down