File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change 143143 gc_collect )
144144from test .support .script_helper import assert_python_ok
145145from test .support import threading_helper
146- from opcode import opmap
146+ from opcode import opmap , opname
147147COPY_FREE_VARS = opmap ['COPY_FREE_VARS' ]
148148
149149
@@ -339,15 +339,19 @@ def func():
339339 self .assertEqual (list (new_code .co_lines ()), [])
340340
341341 def test_invalid_bytecode (self ):
342- def foo (): pass
343- foo . __code__ = co = foo . __code__ . replace ( co_code = b' \xee \x00 d \x00 S \x00 ' )
342+ def foo ():
343+ pass
344344
345- with self .assertRaises (SystemError ) as se :
346- foo ()
347- self .assertEqual (
348- f"{ co .co_filename } :{ co .co_firstlineno } : unknown opcode 238" ,
349- str (se .exception ))
345+ # assert that opcode 238 is invalid
346+ self .assertEqual (opname [238 ], '<238>' )
350347
348+ # change first opcode to 0xee (=238)
349+ foo .__code__ = foo .__code__ .replace (
350+ co_code = b'\xee ' + foo .__code__ .co_code [1 :])
351+
352+ msg = f"unknown opcode 238"
353+ with self .assertRaisesRegex (SystemError , msg ):
354+ foo ()
351355
352356 @requires_debug_ranges ()
353357 def test_co_positions_artificial_instructions (self ):
You can’t perform that action at this time.
0 commit comments