From 05c92759b6078fd667ed2275a523893f0685f0b9 Mon Sep 17 00:00:00 2001 From: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com> Date: Sun, 25 Sep 2022 15:55:53 -0400 Subject: [PATCH] Reject invalid opcode names in assertInBytecode (GH-97548) --- Lib/test/support/bytecode_helper.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/test/support/bytecode_helper.py b/Lib/test/support/bytecode_helper.py index 05b54911e3f..eb4ae1a68e3 100644 --- a/Lib/test/support/bytecode_helper.py +++ b/Lib/test/support/bytecode_helper.py @@ -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)