File tree 1 file changed +12
-8
lines changed
1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change 143
143
gc_collect )
144
144
from test .support .script_helper import assert_python_ok
145
145
from test .support import threading_helper
146
- from opcode import opmap
146
+ from opcode import opmap , opname
147
147
COPY_FREE_VARS = opmap ['COPY_FREE_VARS' ]
148
148
149
149
@@ -339,15 +339,19 @@ def func():
339
339
self .assertEqual (list (new_code .co_lines ()), [])
340
340
341
341
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
344
344
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>' )
350
347
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 ()
351
355
352
356
@requires_debug_ranges ()
353
357
def test_co_positions_artificial_instructions (self ):
You can’t perform that action at this time.
0 commit comments