MCPcopy
hub / github.com/python/mypy / assert_emit

Method assert_emit

mypyc/test/test_emitfunc.py:974–1021  ·  view source on GitHub ↗
(
        self,
        op: Op | list[Op],
        expected: str,
        next_block: BasicBlock | None = None,
        *,
        rare: bool = False,
        next_branch: Branch | None = None,
        skip_next: bool = False,
    )

Source from the content-addressed store, hash-verified

972 self.assert_emit(Assign(s, CString(b)), f'cpy_r_s = "{target}";')
973
974 def assert_emit(
975 self,
976 op: Op | list[Op],
977 expected: str,
978 next_block: BasicBlock | None = None,
979 *,
980 rare: bool = False,
981 next_branch: Branch | None = None,
982 skip_next: bool = False,
983 ) -> None:
984 block = BasicBlock(0)
985 if isinstance(op, Op):
986 block.ops.append(op)
987 else:
988 block.ops.extend(op)
989 op = op[-1]
990 value_names = generate_names_for_ir(self.registers, [block])
991 emitter = Emitter(self.context, value_names)
992 declarations = Emitter(self.context, value_names)
993 emitter.fragments = []
994 declarations.fragments = []
995
996 visitor = FunctionEmitterVisitor(emitter, declarations, "prog.py", "prog")
997 visitor.next_block = next_block
998 visitor.rare = rare
999 if next_branch:
1000 visitor.ops = [op, next_branch]
1001 else:
1002 visitor.ops = [op]
1003 visitor.op_index = 0
1004
1005 op.accept(visitor)
1006 frags = declarations.fragments + emitter.fragments
1007 actual_lines = [line.strip(" ") for line in frags]
1008 assert all(line.endswith("\n") for line in actual_lines)
1009 actual_lines = [line.rstrip("\n") for line in actual_lines]
1010 if not expected.strip():
1011 expected_lines = []
1012 else:
1013 expected_lines = expected.rstrip().split("\n")
1014 expected_lines = [line.strip(" ") for line in expected_lines]
1015 assert_string_arrays_equal(
1016 expected_lines, actual_lines, msg="Generated code unexpected", traceback=True
1017 )
1018 if skip_next:
1019 assert visitor.op_index == 1
1020 else:
1021 assert visitor.op_index == 0
1022
1023 def assert_emit_binary_op(
1024 self, op: str, dest: Value, left: Value, right: Value, expected: str

Callers 15

test_gotoMethod · 0.95
test_goto_next_blockMethod · 0.95
test_returnMethod · 0.95
test_integerMethod · 0.95
test_tuple_getMethod · 0.95
test_load_NoneMethod · 0.95
test_assign_intMethod · 0.95
test_int_negMethod · 0.95
test_branchMethod · 0.95
test_branch_no_elseMethod · 0.95
test_branch_is_errorMethod · 0.95

Calls 14

BasicBlockClass · 0.90
generate_names_for_irFunction · 0.90
EmitterClass · 0.90
isinstanceFunction · 0.85
allFunction · 0.85
appendMethod · 0.80
extendMethod · 0.80
stripMethod · 0.80
rstripMethod · 0.80
splitMethod · 0.80

Tested by

no test coverage detected