Skip to content

Commit 6e799be

Browse files
tekknolagiDinoVblurb-it[bot]
authored
bpo-42199: Fix bytecode_helper assertNotInBytecode (#23031)
* bpo-42199: Fix bytecode_helper assertNotInBytecode Add tests. * πŸ“œπŸ€– Added by blurb_it. Co-authored-by: Dino Viehland <dinoviehland@fb.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
1 parent 074ad51 commit 6e799be

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

β€ŽLib/test/support/bytecode_helper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def assertNotInBytecode(self, x, opname, argval=_UNSPECIFIED):
3535
disassembly = self.get_disassembly_as_string(x)
3636
if argval is _UNSPECIFIED:
3737
msg = '%s occurs in bytecode:\n%s' % (opname, disassembly)
38+
self.fail(msg)
3839
elif instr.argval == argval:
3940
msg = '(%s,%r) occurs in bytecode:\n%s'
4041
msg = msg % (opname, argval, disassembly)
41-
self.fail(msg)
42+
self.fail(msg)

β€ŽLib/test/test_dis.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,5 +1212,24 @@ def test_from_traceback_dis(self):
12121212
b = dis.Bytecode.from_traceback(tb)
12131213
self.assertEqual(b.dis(), dis_traceback)
12141214

1215+
1216+
class TestBytecodeTestCase(BytecodeTestCase):
1217+
def test_assert_not_in_with_op_not_in_bytecode(self):
1218+
code = compile("a = 1", "<string>", "exec")
1219+
self.assertInBytecode(code, "LOAD_CONST", 1)
1220+
self.assertNotInBytecode(code, "LOAD_NAME")
1221+
self.assertNotInBytecode(code, "LOAD_NAME", "a")
1222+
1223+
def test_assert_not_in_with_arg_not_in_bytecode(self):
1224+
code = compile("a = 1", "<string>", "exec")
1225+
self.assertInBytecode(code, "LOAD_CONST")
1226+
self.assertInBytecode(code, "LOAD_CONST", 1)
1227+
self.assertNotInBytecode(code, "LOAD_CONST", 2)
1228+
1229+
def test_assert_not_in_with_arg_in_bytecode(self):
1230+
code = compile("a = 1", "<string>", "exec")
1231+
with self.assertRaises(AssertionError):
1232+
self.assertNotInBytecode(code, "LOAD_CONST", 1)
1233+
12151234
if __name__ == "__main__":
12161235
unittest.main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bytecode helper assertNotInBytecode.

0 commit comments

Comments
Β (0)