INNER CODE UNIT · Python
aggregate
OpenChemistry/avogadrolibs · scripts/coverage_summary.py:50
def aggregate(summary: dict) -> dict[str, dict[str, int]]:
"""Sum the per-file counts into per-module and TOTAL counts."""
zero = {"lc": 0, "lt": 0, "bc": 0, "bt": 0}
result = {m: dict(zero) for m in MODULES}
result[TOTAL] = dict(zero)
for entry in summary.get("files", []):
match = MODULE_RE.search(entry.get("filename", "").replace("\\", "/"))
if not match or match.group(1) not in result:
continue
counts = {
"lc": int(entry.get("line_covered", 0)),
"lt": int(entry.get("line_total", 0)),
"bc": int(entry.get("branch_covered", 0)),
"bt": int(entry.get("branch_total", 0)),
}
for key in (match.group(1), TOTAL):
for name, value in counts.items():
result[key][name] += value