Пример #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
 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")]
         )