コード例 #1
0
 def test_self_match_all(self):
     self.check_instrs([], [SkipAny()])
     self.check_instrs([Instruction("STORE_NAME", "foo")], [SkipAny()])
     self.check_instrs(
         [Instruction("STORE_NAME", "foo"), Instruction("STORE_NAME", "foo")],
         [SkipAny()],
     )
コード例 #2
0
 def test_self_neg_wildcard_multimatch(self):
     with self.assertRaisesRegex(
         AssertionError, "unexpected match CALL_FUNCTION 0, got CALL_FUNCTION 0"
     ):
         self.check_instrs(
             [Instruction("LOAD_NAME", "foo"), Instruction("CALL_FUNCTION", 0)],
             [SkipBut(Op("LOAD_NAME", "bar"), Op("CALL_FUNCTION", 0))],
         )
コード例 #3
0
 def test_self_neg_wildcard_match(self):
     with self.assertRaisesRegex(
         AssertionError, "unexpected match LOAD_NAME foo, got LOAD_NAME 'foo'"
     ):
         self.check_instrs(
             [Instruction("LOAD_NAME", "foo"), Instruction("CALL_FUNCTION", 0)],
             [~Op("LOAD_NAME", "foo")],
         )
コード例 #4
0
 def test_self_trailing_script_wildcard(self):
     with self.assertRaisesRegex(
         AssertionError, escape("Trailing script elements: [Op(STORE_NAME, 'bar')]")
     ):
         self.check_instrs(
             [Instruction("STORE_NAME", "foo"), Instruction("STORE_NAME", "foo")],
             [SkipAny(), Op("STORE_NAME", "bar")],
         )
コード例 #5
0
ファイル: test_code_sbs.py プロジェクト: SavoBit/cinder-1
 def test_self_trailing_instrs(self):
     with self.assertRaisesRegex(AssertionError,
                                 "Extra bytecodes not expected"):
         self.check_instrs(
             [
                 Instruction("STORE_NAME", "foo"),
                 Instruction("STORE_NAME", "foo")
             ],
             [Op("STORE_NAME", "foo")],
         )
コード例 #6
0
 def test_self_match_block(self):
     block = pyassem.Block()
     block.bid = 1
     self.check_instrs(
         [
             Instruction("JUMP_ABSOLUTE", None, target=block),
             Instruction("LOAD_CONST", None),
             Instruction("RETURN_VALUE", 0),
         ],
         [Op("JUMP_ABSOLUTE", Block(1)), Op("LOAD_CONST", None), SkipAny()],
     )
コード例 #7
0
 def test_self_match_wrong_block(self):
     block = pyassem.Block()
     block.bid = 1
     with self.assertRaisesRegex(
         AssertionError,
         escape(
             "mismatch, expected JUMP_ABSOLUTE Block(2), got JUMP_ABSOLUTE Block(1)"
         ),
     ):
         self.check_instrs(
             [
                 Instruction("JUMP_ABSOLUTE", None, target=block),
                 Instruction("LOAD_CONST", None),
                 Instruction("RETURN_VALUE", 0),
             ],
             [Op("JUMP_ABSOLUTE", Block(2)), Op("LOAD_CONST", None), SkipAny()],
         )
コード例 #8
0
 def test_self_bad_oparg(self):
     return
     with self.assertRaisesRegex(
         AssertionError, "Failed to eval expected oparg: foo"
     ):
         self.check_instrs(
             [Instruction("STORE_NAME", "foo")], [Op("STORE_NAME", "foo")]
         )
コード例 #9
0
def graph_instrs(graph, name=None):
    if name:
        yield Instruction(SCRIPT_OPCODE_CODE, name)
    for block in graph.getBlocks():
        for instr in block.getInstructions():
            yield instr
コード例 #10
0
 def test_self_neg_wildcard_no_multimatch(self):
     self.check_instrs(
         [Instruction("LOAD_NAME", "foo"), Instruction("CALL_FUNCTION", 0)],
         [SkipBut(Op("LOAD_NAME", "bar"), Op("CALL_FUNCTION", 1))],
     )
コード例 #11
0
 def test_self_match_after_wildcard(self):
     self.check_instrs(
         [Instruction("LOAD_NAME", "foo"), Instruction("CALL_FUNCTION", 0)],
         [SkipAny(), Op("CALL_FUNCTION", 0)],
     )
コード例 #12
0
 def test_self_wildcard_opname(self):
     self.check_instrs([Instruction("LOAD_NAME", "foo")], [Op(Any, "foo")])
コード例 #13
0
 def test_self_wildcard_oparg(self):
     self.check_instrs([Instruction("LOAD_NAME", "foo")], [Op("LOAD_NAME", Any)])
コード例 #14
0
 def test_self_mismatch_opname(self):
     with self.assertRaises(AssertionError):
         self.check_instrs(
             [Instruction("LOAD_NAME", "foo")], [Op("STORE_NAME", "foo")]
         )