Skip to content

Commit

Permalink
add test for _get_argval_argrepr
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel committed Nov 10, 2023
1 parent c3d7a10 commit f129246
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2001,6 +2001,24 @@ def test_jump_target(self):
positions=None)
self.assertEqual(10 + 2 + 1*2 + 100*2, instruction.jump_target)

def test_argval_argrepr(self):
f = dis.Instruction._get_argval_argrepr

offset = 42
co_consts = (0, 1, 2, 3)
names = {1: 'a', 2: 'b'}
varname_from_oparg = lambda i : names[i]
args = (offset, co_consts, names, varname_from_oparg)
self.assertEqual(f(opcode.opmap["POP_TOP"], None, *args), (None, ''))
self.assertEqual(f(opcode.opmap["LOAD_CONST"], 1, *args), (1, '1'))
self.assertEqual(f(opcode.opmap["LOAD_GLOBAL"], 2, *args), ('a', 'a'))
self.assertEqual(f(opcode.opmap["JUMP_BACKWARD"], 11, *args), (24, 'to 24'))
self.assertEqual(f(opcode.opmap["COMPARE_OP"], 3, *args), ('<', '<'))
self.assertEqual(f(opcode.opmap["SET_FUNCTION_ATTRIBUTE"], 2, *args), (2, 'kwdefaults'))
self.assertEqual(f(opcode.opmap["BINARY_OP"], 3, *args), (3, '<<'))
self.assertEqual(f(opcode.opmap["CALL_INTRINSIC_1"], 2, *args), (2, 'INTRINSIC_IMPORT_STAR'))


def test_start_offset(self):
# When no extended args are present,
# start_offset should be equal to offset
Expand Down

0 comments on commit f129246

Please sign in to comment.