MCPcopy Index your code
hub / github.com/python/cpython / assertInBytecode

Method assertInBytecode

Lib/test/support/bytecode_helper.py:34–47  ·  view source on GitHub ↗

Returns instr if opname is found, otherwise throws AssertionError

(self, x, opname, argval=_UNSPECIFIED)

Source from the content-addressed store, hash-verified

32 return s.getvalue()
33
34 def assertInBytecode(self, x, opname, argval=_UNSPECIFIED):
35 """Returns instr if opname is found, otherwise throws AssertionError"""
36 self.assertIn(opname, dis.opmap)
37 for instr in dis.get_instructions(x):
38 if instr.opname == opname:
39 if argval is _UNSPECIFIED or instr.argval == argval:
40 return instr
41 disassembly = self.get_disassembly_as_string(x)
42 if argval is _UNSPECIFIED:
43 msg = '%s not found in bytecode:\n%s' % (opname, disassembly)
44 else:
45 msg = '(%s,%r) not found in bytecode:\n%s'
46 msg = msg % (opname, argval, disassembly)
47 self.fail(msg)
48
49 def assertNotInBytecode(self, x, opname, argval=_UNSPECIFIED):
50 """Throws AssertionError if opname is found"""

Calls 4

assertInMethod · 0.80
get_instructionsMethod · 0.80
failMethod · 0.45