File size: 1,320 Bytes
f4952b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""The suite enters the package it ships: a floor keeps dark corners from piling up."""

from __future__ import annotations

import json
import os
import subprocess
import sys
from pathlib import Path

import pytest

ROOT = Path(__file__).resolve().parents[1]

# Measured at 95.9 percent when this floor was first written; ten points of
# margin let one refactor breathe without letting a whole module go dark.
FLOOR = 90.0


@pytest.mark.skipif(
    os.environ.get("LINGOLOGOS_COVERAGE_CHILD") == "1",
    reason="this test is the measurement: inside the traced child it would nest forever",
)
def test_the_suite_enters_most_of_the_package_it_ships(tmp_path: Path) -> None:
    report = tmp_path / "coverage.json"
    status = subprocess.run(
        [
            sys.executable,
            "-B",
            "tools/measure_coverage.py",
            "--floor",
            str(FLOOR),
            "--report",
            str(report),
        ],
        cwd=str(ROOT),
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    ).returncode
    assert status == 0, "the traced suite failed or the coverage floor was missed"
    payload = json.loads(report.read_text(encoding="utf-8"))
    assert payload["percent"] >= FLOOR
    assert payload["total"] > 100, "a denominator that small measures nothing"