MCPcopy Index your code
hub / github.com/evalplus/evalplus / test_code_coverage

Function test_code_coverage

tools/tsr/coverage_init.py:50–73  ·  view source on GitHub ↗
(
    identifier: str, code: str, inputs: List[List[Any]], entry_point: str
)

Source from the content-addressed store, hash-verified

48
49
50def test_code_coverage(
51 identifier: str, code: str, inputs: List[List[Any]], entry_point: str
52):
53 module_name = f"tmp_src_{identifier}"
54 with open(f"{module_name}.py", "w") as f:
55 f.write(code)
56
57 mod = import_module(module_name)
58 func = getattr(mod, entry_point, None)
59 assert func != None, f"entry_point = {entry_point} not exist, code: {code}"
60
61 cov = coverage.Coverage(branch=True)
62 cov.start()
63 with swallow_io():
64 for input_list in inputs:
65 func(*input_list)
66 cov.stop()
67 with Capturing() as outputs:
68 cov.lcov_report(outfile="-")
69
70 ret = parse_lcov(outputs)
71
72 os.remove(f"{module_name}.py")
73 return ret
74
75
76def collect_coverage_info(coverage_dir: str, dataset: str) -> Dict[str, Dict[str, Any]]:

Callers 1

collect_coverage_infoFunction · 0.70

Calls 4

swallow_ioFunction · 0.90
funcFunction · 0.85
CapturingClass · 0.70
parse_lcovFunction · 0.70

Tested by

no test coverage detected