Debian Codegraph @

pypy/module/_opcode/test/apptest_opcode.py

raw symbols SCIP
1 import pytest
2
3 import opcode
4
5 def test_errors():
6 pytest.raises(ValueError, opcode.stack_effect, opcode.opmap["LOAD_CONST"])
7 pytest.raises(ValueError, opcode.stack_effect, opcode.opmap["BINARY_ADD"], 1)
8 pytest.raises(ValueError, opcode.stack_effect, 1231231)
9 pytest.raises(ValueError, opcode.stack_effect, opcode.opmap["EXTENDED_ARG"])
10
11 def test_call_function():
12 assert opcode.stack_effect(opcode.opmap["CALL_FUNCTION"], 3) == -3
13 assert opcode.stack_effect(opcode.opmap["EXTENDED_ARG"], 3) == 0
14
15 def test_invalid_opcode():
16 pytest.raises(ValueError, opcode.stack_effect, 0)
17 pytest.raises(ValueError, opcode.stack_effect, 0, 0)
18
19 def test_jump():
20 assert opcode.stack_effect(opcode.opmap["FOR_ITER"], 0, jump=True) == -1
21 assert opcode.stack_effect(opcode.opmap["FOR_ITER"], 0, jump=False) == 1
22 assert opcode.stack_effect(opcode.opmap["FOR_ITER"], 0) == 1
23
24 def test_conditional_jump():
25 assert opcode.stack_effect(opcode.opmap["JUMP_IF_TRUE_OR_POP"], 0, jump=True) == 0
26 assert opcode.stack_effect(opcode.opmap["JUMP_IF_TRUE_OR_POP"], 0, jump=False) == -1