test_guard_ratio_floor.py¶
tests/guard/test_guard_ratio_floor.py
The requirement ratio floor, and coverage running from the pre-commit hook (PG3; 2.0.0).
test_a_floor_outside_zero_to_one_is_refused
None test_guard_ratio_floor.test_a_floor_outside_zero_to_one_is_refused(tmp_path, monkeypatch, capsys, bad)
A floor is a number in (0, 1]; anything else is refused by name.
tests/guard/test_guard_ratio_floor.py:77
Checks
assert main(["coverage", "."]) != 0assert "min_req_ratio" in capsys.readouterr().err
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-012 | measured | |
| REQ-DDB-GUARD-013 | measured | |
| REQ-DDB-GUARD-014 | measured |
Source · 7 lines
def test_a_floor_outside_zero_to_one_is_refused(tmp_path, monkeypatch, capsys, bad) -> None:
"""@brief A floor is a number in (0, 1]; anything else is refused by name."""
monkeypatch.chdir(_repo(tmp_path, f" coverage:\n min_req_ratio: {bad}\n"))
assert main(["coverage", "."]) != 0
assert "min_req_ratio" in capsys.readouterr().err
Activity · 3 steps
test_a_ratio_at_or_above_the_floor_passes
None test_guard_ratio_floor.test_a_ratio_at_or_above_the_floor_passes(tmp_path, monkeypatch)
Floor 0.25: passes.
tests/guard/test_guard_ratio_floor.py:70
Checks
assert main(["coverage", "."]) == 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-CONFIG-009 | measured | |
| REQ-DDB-GUARD-011 | measured | |
| REQ-DDB-GUARD-012 | measured | |
| REQ-DDB-GUARD-013 | measured | |
| REQ-DDB-GUARD-016 | measured | |
| REQ-DDB-GUARD-018 | measured | |
| REQ-DDB-GUARD-019 | measured | |
| REQ-DDB-GUARD-020 | measured | |
| REQ-DDB-GUARD-022 | measured | |
| REQ-DDB-GUARD-024 | measured | |
| REQ-DDB-GUARD-025 | measured | |
| REQ-DDB-PIPE-011 | measured |
Source · 7 lines
def test_a_ratio_at_or_above_the_floor_passes(tmp_path, monkeypatch) -> None:
"""@brief Floor 0.25: passes."""
monkeypatch.chdir(_repo(tmp_path, " coverage:\n min_req_ratio: 0.25\n"))
assert main(["coverage", "."]) == 0
@pytest.mark.parametrize("bad", ["0", "1.5", "half"])test_a_ratio_below_the_declared_floor_fails
None test_guard_ratio_floor.test_a_ratio_below_the_declared_floor_fails(tmp_path, monkeypatch, capsys)
Floor 0.50, ratio 0.25: rc 1, saying both numbers.
tests/guard/test_guard_ratio_floor.py:62
Checks
assert main(["coverage", "."]) == 1assert "ratio 0.25" in out and "below the floor 0.5" in out
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-CONFIG-009 | measured | |
| REQ-DDB-GUARD-011 | measured | |
| REQ-DDB-GUARD-012 | measured | |
| REQ-DDB-GUARD-013 | measured | |
| REQ-DDB-GUARD-016 | measured | |
| REQ-DDB-GUARD-018 | measured | |
| REQ-DDB-GUARD-019 | measured | |
| REQ-DDB-GUARD-020 | measured | |
| REQ-DDB-GUARD-022 | measured | |
| REQ-DDB-GUARD-024 | measured | |
| REQ-DDB-GUARD-025 | measured | |
| REQ-DDB-PIPE-011 | measured |
Source · 8 lines
def test_a_ratio_below_the_declared_floor_fails(tmp_path, monkeypatch, capsys) -> None:
"""@brief Floor 0.50, ratio 0.25: rc 1, saying both numbers."""
monkeypatch.chdir(_repo(tmp_path, " coverage:\n min_req_ratio: 0.5\n"))
assert main(["coverage", "."]) == 1
out = capsys.readouterr().out
assert "ratio 0.25" in out and "below the floor 0.5" in out
Activity · 4 steps
test_the_counts_are_printed_and_tests_are_left_out
None test_guard_ratio_floor.test_the_counts_are_printed_and_tests_are_left_out(tmp_path, monkeypatch, capsys)
1 @req, 2 @utility, 1
tests/guard/test_guard_ratio_floor.py:53
Checks
assert main(["coverage", "."]) == 0assert "1 with @req" in out and "@utility 2" in out and "@callback 1" in outassert "ratio 0.25" in out and "no floor declared" in out
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-CONFIG-009 | measured | |
| REQ-DDB-GUARD-011 | measured | |
| REQ-DDB-GUARD-012 | measured | |
| REQ-DDB-GUARD-013 | measured | |
| REQ-DDB-GUARD-016 | measured | |
| REQ-DDB-GUARD-018 | measured | |
| REQ-DDB-GUARD-019 | measured | |
| REQ-DDB-GUARD-020 | measured | |
| REQ-DDB-GUARD-022 | measured | |
| REQ-DDB-GUARD-025 | measured | |
| REQ-DDB-PIPE-011 | measured |
Source · 9 lines
def test_the_counts_are_printed_and_tests_are_left_out(tmp_path, monkeypatch, capsys) -> None:
"""@brief 1 @req, 2 @utility, 1 @callback (the tests/ helper not counted): ratio 0.25."""
monkeypatch.chdir(_repo(tmp_path))
assert main(["coverage", "."]) == 0
out = capsys.readouterr().out
assert "1 with @req" in out and "@utility 2" in out and "@callback 1" in out
assert "ratio 0.25" in out and "no floor declared" in out
Activity · 5 steps
test_the_pre_commit_hook_runs_the_coverage_gate
None test_guard_ratio_floor.test_the_pre_commit_hook_runs_the_coverage_gate(tmp_path, monkeypatch, capsys)
`clew guard <files>` (what pre-commit runs) runs the coverage gate.
tests/guard/test_guard_ratio_floor.py:84
Checks
assert main(["validate", "--no-git", "src/a.c"]) == 0, "the staged file itself is clean"assert main(["src/a.c"]) == 1assert "REQ-B-002" in captured.out + captured.err
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-CONFIG-009 | measured | |
| REQ-DDB-GUARD-001 | measured | |
| REQ-DDB-GUARD-002 | measured | |
| REQ-DDB-GUARD-003 | measured | |
| REQ-DDB-GUARD-004 | measured | |
| REQ-DDB-GUARD-005 | measured | |
| REQ-DDB-GUARD-006 | measured | |
| REQ-DDB-GUARD-007 | measured | |
| REQ-DDB-GUARD-009 | measured | |
| REQ-DDB-GUARD-010 | measured | |
| REQ-DDB-GUARD-011 | measured | |
| REQ-DDB-GUARD-012 | measured | |
| REQ-DDB-GUARD-013 | measured | |
| REQ-DDB-GUARD-014 | measured | |
| REQ-DDB-GUARD-016 | measured | |
| REQ-DDB-GUARD-018 | measured | |
| REQ-DDB-GUARD-019 | measured | |
| REQ-DDB-GUARD-020 | measured | |
| REQ-DDB-GUARD-022 | measured | |
| REQ-DDB-GUARD-023 | measured | |
| REQ-DDB-GUARD-025 | measured | |
| REQ-DDB-GUARD-026 | measured | |
| REQ-DDB-GUARD-027 | measured | |
| REQ-DDB-INDEX-007 | measured | |
| REQ-DDB-MCP-001 | measured | |
| REQ-DDB-PIPE-011 | measured | |
| REQ-DDB-SCHEMA-006 | measured | |
| REQ-DDB-SCHEMA-015 | measured |
Source · 16 lines
def test_the_pre_commit_hook_runs_the_coverage_gate(tmp_path, monkeypatch, capsys) -> None:
"""A VALID config, no floor, and a staged file with nothing wrong in it: the hook still fails,
because the catalog holds a requirement nothing implements. Before PG3 the hook never ran
coverage, so this passed (rc 0) and the gap waited for someone to run `coverage` by hand.
@brief `clew guard <files>` (what pre-commit runs) runs the coverage gate.
"""
root = _repo(tmp_path)
(root / "requirements.yaml").write_text(
_CATALOG + " REQ-B-002:\n name: nobody implements this\n"
)
monkeypatch.chdir(root)
assert main(["validate", "--no-git", "src/a.c"]) == 0, "the staged file itself is clean"
assert main(["src/a.c"]) == 1
captured = capsys.readouterr()
assert "REQ-B-002" in captured.out + captured.err1 more lines, not shown