Skip to content

Test Coverageยค

Coverage is measured on every push to main and the results are committed to reports/coverage.json.

Summaryยค

import json
from pathlib import Path

def format_coverage(pct: float) -> str:
    if pct == 100:
        return "โœ… 100.0%"
    elif pct >= 80:
        return f"๐ŸŸก {pct:.1f}%"
    else:
        return f"๐Ÿ”ด {pct:.1f}%"

report_path = Path("reports/coverage.json")

if not report_path.exists():
    print("*No coverage data yet โ€” run `make test` to generate it.*")
else:
    data = json.loads(report_path.read_text())
    totals = data["totals"]
    pct = totals["percent_covered"]
    covered = totals["covered_lines"]
    total = totals["num_statements"]

    print(f"**Overall coverage:** `{pct:.1f}%` ({covered}/{total} statements)\n")

    rows = [
        (
            path.replace("src/", "").replace("/", ".").removesuffix(".py"),
            info["summary"]["covered_lines"],
            info["summary"]["num_statements"],
            info["summary"]["percent_covered"],
        )
        for path, info in sorted(data["files"].items())
        if "src/" in path
    ]

    print("| Module | Covered | Statements | Coverage |")
    print("|:-------|--------:|-----------:|:---------|")
    for module, covered, stmts, pct_m in rows:
        print(f"| `{module}` | {covered} | {stmts} | {format_coverage(pct_m)} |")

Overall coverage: 92.4% (290/314 statements)

Module Covered Statements Coverage
docchex.__init__ 21 21 โœ… 100.0%
docchex.__main__ 0 4 ๐Ÿ”ด 0.0%
docchex._internal.__init__ 0 0 โœ… 100.0%
docchex._internal.cli 21 21 โœ… 100.0%
docchex._internal.debug 57 63 ๐ŸŸก 90.5%
docchex._internal.evaluation.__init__ 1 1 โœ… 100.0%
docchex._internal.evaluation.ai 5 5 โœ… 100.0%
docchex._internal.evaluation.engine 12 12 โœ… 100.0%
docchex._internal.models 32 32 โœ… 100.0%
docchex._internal.parsing.__init__ 1 1 โœ… 100.0%
docchex._internal.parsing.base 15 16 ๐ŸŸก 93.8%
docchex._internal.parsing.pdf 19 19 โœ… 100.0%
docchex._internal.parsing.text 7 12 ๐Ÿ”ด 58.3%
docchex._internal.rules.__init__ 1 1 โœ… 100.0%
docchex._internal.rules.base 14 15 ๐ŸŸก 93.3%
docchex._internal.rules.builtin.__init__ 1 1 โœ… 100.0%
docchex._internal.rules.builtin.required_section 17 17 โœ… 100.0%
docchex._internal.rules.builtin.word_count 22 22 โœ… 100.0%
docchex._internal.rules.loader 44 51 ๐ŸŸก 86.3%