Reject invalid opcode names in assertInBytecode (GH-97548)

This commit is contained in:
Dennis Sweeney 2022-09-25 15:55:53 -04:00 committed by GitHub
parent c8c0afc713
commit 05c92759b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -17,6 +17,7 @@ class BytecodeTestCase(unittest.TestCase):
def assertInBytecode(self, x, opname, argval=_UNSPECIFIED):
"""Returns instr if opname is found, otherwise throws AssertionError"""
self.assertIn(opname, dis.opmap)
for instr in dis.get_instructions(x):
if instr.opname == opname:
if argval is _UNSPECIFIED or instr.argval == argval:
@ -31,6 +32,7 @@ class BytecodeTestCase(unittest.TestCase):
def assertNotInBytecode(self, x, opname, argval=_UNSPECIFIED):
"""Throws AssertionError if opname is found"""
self.assertIn(opname, dis.opmap)
for instr in dis.get_instructions(x):
if instr.opname == opname:
disassembly = self.get_disassembly_as_string(x)