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>
This commit is contained in:
Max Bernstein 2020-12-17 16:30:29 -08:00 committed by GitHub
parent 074ad5123f
commit 6e799be0a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View File

@ -35,7 +35,8 @@ class BytecodeTestCase(unittest.TestCase):
disassembly = self.get_disassembly_as_string(x)
if argval is _UNSPECIFIED:
msg = '%s occurs in bytecode:\n%s' % (opname, disassembly)
self.fail(msg)
elif instr.argval == argval:
msg = '(%s,%r) occurs in bytecode:\n%s'
msg = msg % (opname, argval, disassembly)
self.fail(msg)
self.fail(msg)

View File

@ -1212,5 +1212,24 @@ class BytecodeTests(unittest.TestCase):
b = dis.Bytecode.from_traceback(tb)
self.assertEqual(b.dis(), dis_traceback)
class TestBytecodeTestCase(BytecodeTestCase):
def test_assert_not_in_with_op_not_in_bytecode(self):
code = compile("a = 1", "<string>", "exec")
self.assertInBytecode(code, "LOAD_CONST", 1)
self.assertNotInBytecode(code, "LOAD_NAME")
self.assertNotInBytecode(code, "LOAD_NAME", "a")
def test_assert_not_in_with_arg_not_in_bytecode(self):
code = compile("a = 1", "<string>", "exec")
self.assertInBytecode(code, "LOAD_CONST")
self.assertInBytecode(code, "LOAD_CONST", 1)
self.assertNotInBytecode(code, "LOAD_CONST", 2)
def test_assert_not_in_with_arg_in_bytecode(self):
code = compile("a = 1", "<string>", "exec")
with self.assertRaises(AssertionError):
self.assertNotInBytecode(code, "LOAD_CONST", 1)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1 @@
Fix bytecode helper assertNotInBytecode.