-
Notifications
You must be signed in to change notification settings - Fork 811
/
Copy pathwrite_report.py
executable file
·60 lines (44 loc) · 1.76 KB
/
write_report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
from __future__ import annotations
from decimal import ROUND_DOWN
from decimal import Decimal
from pathlib import Path
import orjson
PRECISION = Decimal(".01")
ROOT = Path(__file__).resolve().parent.parent
def main():
coverage_summary = ROOT / "coverage-summary.json"
coverage_data = orjson.loads(coverage_summary.read_text(encoding="utf-8"))
total_data = coverage_data.pop("total")
lines = [
"\n",
"Package | Statements\n",
"------- | ----------\n",
]
for package, data in sorted(coverage_data.items()):
statements_covered = data["statements_covered"]
statements = data["statements"]
rate = Decimal(statements_covered) / Decimal(statements) * 100
rate = rate.quantize(PRECISION, rounding=ROUND_DOWN)
lines.append(
f"{package} | {100 if rate == 100 else rate}% ({statements_covered} / {statements})\n" # noqa: PLR2004
)
total_statements_covered = total_data["statements_covered"]
total_statements = total_data["statements"]
total_rate = Decimal(total_statements_covered) / Decimal(total_statements) * 100
total_rate = total_rate.quantize(PRECISION, rounding=ROUND_DOWN)
color = "ok" if float(total_rate) >= 95 else "critical"
lines.insert(
0,
f"\n",
)
lines.append(
f"**Summary** | {100 if total_rate == 100 else total_rate}% "
f"({total_statements_covered} / {total_statements})\n"
)
coverage_report = ROOT / "coverage-report.md"
with coverage_report.open("w", encoding="utf-8") as f:
f.write("".join(lines))
return 0
if __name__ == "__main__":
raise SystemExit(main())