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

Show on the map →

Called by none

Calls _repo

Checks

  • assert main(["coverage", "."]) != 0
  • assert "min_req_ratio" in capsys.readouterr().err

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-012measured
REQ-DDB-GUARD-013measured
REQ-DDB-GUARD-014measured
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
lines 79–79monkeypatch.chdir(_repo(tmp_path, f" coverage:\n min_req_ratio: {bad}\n"))lines 80–80assert main(["coverage", "."]) != 0lines 81–81assert "min_req_ratio" in capsys.readouterr().err

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

Show on the map →

Called by none

Calls _repo

Checks

  • assert main(["coverage", "."]) == 0

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-009measured
REQ-DDB-GUARD-011measured
REQ-DDB-GUARD-012measured
REQ-DDB-GUARD-013measured
REQ-DDB-GUARD-016measured
REQ-DDB-GUARD-018measured
REQ-DDB-GUARD-019measured
REQ-DDB-GUARD-020measured
REQ-DDB-GUARD-022measured
REQ-DDB-GUARD-024measured
REQ-DDB-GUARD-025measured
REQ-DDB-PIPE-011measured
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

Show on the map →

Called by none

Calls _repo

Checks

  • assert main(["coverage", "."]) == 1
  • assert "ratio 0.25" in out and "below the floor 0.5" in out

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-009measured
REQ-DDB-GUARD-011measured
REQ-DDB-GUARD-012measured
REQ-DDB-GUARD-013measured
REQ-DDB-GUARD-016measured
REQ-DDB-GUARD-018measured
REQ-DDB-GUARD-019measured
REQ-DDB-GUARD-020measured
REQ-DDB-GUARD-022measured
REQ-DDB-GUARD-024measured
REQ-DDB-GUARD-025measured
REQ-DDB-PIPE-011measured
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
lines 64–64monkeypatch.chdir(_repo(tmp_path, " coverage:\n min_req_ratio: 0.5\n"))lines 65–65assert main(["coverage", "."]) == 1lines 66–66out = capsys.readouterr().outlines 67–67assert "ratio 0.25" in out and "below the floor 0.5" in out

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

Show on the map →

Called by none

Calls _repo

Checks

  • assert main(["coverage", "."]) == 0
  • 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

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-009measured
REQ-DDB-GUARD-011measured
REQ-DDB-GUARD-012measured
REQ-DDB-GUARD-013measured
REQ-DDB-GUARD-016measured
REQ-DDB-GUARD-018measured
REQ-DDB-GUARD-019measured
REQ-DDB-GUARD-020measured
REQ-DDB-GUARD-022measured
REQ-DDB-GUARD-025measured
REQ-DDB-PIPE-011measured
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
lines 55–55monkeypatch.chdir(_repo(tmp_path))lines 56–56assert main(["coverage", "."]) == 0lines 57–57out = capsys.readouterr().outlines 58–58assert "1 with @req" in out and "@utility 2" in out and "@callback 1" in outlines 59–59assert "ratio 0.25" in out and "no floor declared" in out

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

Show on the map →

Called by none

Calls _repo

Checks

  • assert main(["validate", "--no-git", "src/a.c"]) == 0, "the staged file itself is clean"
  • assert main(["src/a.c"]) == 1
  • assert "REQ-B-002" in captured.out + captured.err

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-009measured
REQ-DDB-GUARD-001measured
REQ-DDB-GUARD-002measured
REQ-DDB-GUARD-003measured
REQ-DDB-GUARD-004measured
REQ-DDB-GUARD-005measured
REQ-DDB-GUARD-006measured
REQ-DDB-GUARD-007measured
REQ-DDB-GUARD-009measured
REQ-DDB-GUARD-010measured
REQ-DDB-GUARD-011measured
REQ-DDB-GUARD-012measured
REQ-DDB-GUARD-013measured
REQ-DDB-GUARD-014measured
REQ-DDB-GUARD-016measured
REQ-DDB-GUARD-018measured
REQ-DDB-GUARD-019measured
REQ-DDB-GUARD-020measured
REQ-DDB-GUARD-022measured
REQ-DDB-GUARD-023measured
REQ-DDB-GUARD-025measured
REQ-DDB-GUARD-026measured
REQ-DDB-GUARD-027measured
REQ-DDB-INDEX-007measured
REQ-DDB-MCP-001measured
REQ-DDB-PIPE-011measured
REQ-DDB-SCHEMA-006measured
REQ-DDB-SCHEMA-015measured
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.err

1 more lines, not shown

Activity · 7 steps
lines 91–91root = _repo(tmp_path)lines 92–94(root / "requirements.yaml").write_text( _CATALOG + " REQ-B-002:\n name: nobody implements this\n" )lines 95–95monkeypatch.chdir(root)lines 96–96assert main(["validate", "--no-git", "src/a.c"]) == 0, "the staged file itself is clean"lines 97–97assert main(["src/a.c"]) == 1lines 98–98captured = capsys.readouterr()lines 99–99assert "REQ-B-002" in captured.out + captured.err