]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Reject invalid opcode names in assertInBytecode (GH-97548)
authorDennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
Sun, 25 Sep 2022 19:55:53 +0000 (15:55 -0400)
committerGitHub <noreply@github.com>
Sun, 25 Sep 2022 19:55:53 +0000 (20:55 +0100)
Lib/test/support/bytecode_helper.py

index 05b54911e3f25a93f31525f4837ec63b4dfb62e9..eb4ae1a68e3fc12d0171162ec666d4cbf482d577 100644 (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)