Skip to content

Commit 5866faa

Browse files
committed
update tests
1 parent f539224 commit 5866faa

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Lib/test/test_peepholer.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ def count_instr_recursively(f, opname):
3636
return count
3737

3838

39+
def get_binop_argval(arg):
40+
for i, nb_op in enumerate(opcode._nb_ops):
41+
if arg == nb_op[0]:
42+
return i
43+
assert False, f"{arg} is not a valid BINARY_OP argument."
44+
45+
3946
class TestTranforms(BytecodeTestCase):
4047

4148
def check_jump_targets(self, code):
@@ -518,8 +525,7 @@ def test_folding_subscript(self):
518525
('("a" * 10)[10]', True),
519526
('(1, (1, 2))[2:6][0][2-1]', True),
520527
]
521-
subscr_argval = 26
522-
assert opcode._nb_ops[subscr_argval][0] == 'NB_SUBSCR'
528+
subscr_argval = get_binop_argval('NB_SUBSCR')
523529
for expr, has_error in tests:
524530
with self.subTest(expr=expr, has_error=has_error):
525531
code = compile(expr, '', 'single')
@@ -1068,7 +1074,7 @@ def test_multiple_foldings(self):
10681074
('LOAD_SMALL_INT', 2, 0),
10691075
('BUILD_TUPLE', 1, 0),
10701076
('LOAD_SMALL_INT', 0, 0),
1071-
('BINARY_SUBSCR', None, 0),
1077+
('BINARY_OP', get_binop_argval('NB_SUBSCR'), 0),
10721078
('BUILD_TUPLE', 2, 0),
10731079
('RETURN_VALUE', None, 0)
10741080
]

0 commit comments

Comments
 (0)