(
identifier: str, code: str, inputs: List[List[Any]], entry_point: str
)
| 48 | |
| 49 | |
| 50 | def 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 | |
| 76 | def collect_coverage_info(coverage_dir: str, dataset: str) -> Dict[str, Dict[str, Any]]: |
no test coverage detected