test_guard_external_catalogs.py¶
tests/guard/test_guard_external_catalogs.py
External requirements catalogs for the gate, and the silent no-catalog gap (GH #68, P6b-1).
test_a_pinned_external_catalogue_is_read_at_its_revision
None test_guard_external_catalogs.test_a_pinned_external_catalogue_is_read_at_its_revision(Path tmp_path, pytest.MonkeyPatch monkeypatch, pytest.CaptureFixture[str] capsys)
`{repo, rev, path}` read with `git show`.
tests/guard/test_guard_external_catalogs.py:69
Checks
assert code == 0, capsys.readouterr()assert code == 1
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-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-011 | measured | |
| REQ-DDB-GUARD-012 | measured | |
| REQ-DDB-GUARD-013 | measured | |
| REQ-DDB-GUARD-014 | measured | |
| REQ-DDB-GUARD-018 | measured | |
| REQ-DDB-GUARD-019 | measured | |
| REQ-DDB-GUARD-020 | measured | |
| REQ-DDB-GUARD-025 | measured | |
| REQ-DDB-GUARD-026 | measured | |
| REQ-DDB-GUARD-027 | measured | |
| REQ-DDB-PIPE-011 | measured | |
| REQ-DDB-SCHEMA-015 | measured |
Source · 36 lines
def test_a_pinned_external_catalogue_is_read_at_its_revision(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
) -> None:
"""THE PIN, NOT THE WORKING TREE: an id added to the consumer's catalogue after the pinned
revision is not satisfied by it.
@brief `{repo, rev, path}` read with `git show`.
"""
consumer = tmp_path / "consumer"
consumer.mkdir()
_catalog(consumer / "requirements.yaml", "REQ-PRD-001")
def git(*args: str) -> str:
return subprocess.run(
["git", "-c", "user.email=t@e", "-c", "user.name=t", *args],
cwd=consumer,
capture_output=True,
text=True,
check=True,
).stdout.strip()
git("init", "-q")
git("add", "-A")
git("commit", "-q", "-m", "catalogue")
rev = git("rev-parse", "HEAD")
_catalog(consumer / "requirements.yaml", "REQ-PRD-001", "REQ-PRD-002")
impact = (
"requirements:\n external:\n"
f" - {{repo: consumer, rev: {rev}, path: requirements.yaml}}\n"
)
code, _ = _run(tmp_path, monkeypatch, impact, "REQ-PRD-001")
assert code == 0, capsys.readouterr()
code, _ = _run(tmp_path, monkeypatch, impact, "REQ-PRD-002")
assert code == 1
Activity · 14 steps
test_a_tag_with_no_catalogue_to_check_it_is_reported
None test_guard_external_catalogs.test_a_tag_with_no_catalogue_to_check_it_is_reported(Path tmp_path, pytest.MonkeyPatch monkeypatch, pytest.CaptureFixture[str] capsys)
No catalogue, a tag: a violation.
tests/guard/test_guard_external_catalogs.py:117
Checks
assert code == 1 and "REQ-ANY-001" in text and "no requirements catalog" in text
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-009 | measured | |
| REQ-DDB-GUARD-001 | 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-011 | measured | |
| REQ-DDB-GUARD-012 | measured | |
| REQ-DDB-GUARD-013 | measured | |
| REQ-DDB-GUARD-014 | measured | |
| REQ-DDB-GUARD-018 | measured | |
| REQ-DDB-GUARD-019 | measured | |
| REQ-DDB-GUARD-020 | measured | |
| REQ-DDB-GUARD-025 | measured | |
| REQ-DDB-GUARD-026 | measured | |
| REQ-DDB-GUARD-027 | measured | |
| REQ-DDB-PIPE-011 | measured | |
| REQ-DDB-SCHEMA-015 | measured |
Source · 14 lines
def test_a_tag_with_no_catalogue_to_check_it_is_reported(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
) -> None:
"""THE GAP #68 EXPOSED: `cross_reference` on, no catalogue anywhere, a `@req` tag — reported as
uncheckable, with how to fix it, never passed silently.
@brief No catalogue, a tag: a violation.
"""
code, _ = _run(tmp_path, monkeypatch, "", "REQ-ANY-001")
out = capsys.readouterr()
text = out.out + out.err
assert code == 1 and "REQ-ANY-001" in text and "no requirements catalog" in text
Activity · 4 steps
test_a_url_is_refused_by_name
None test_guard_external_catalogs.test_a_url_is_refused_by_name(Path tmp_path)
A pre-commit gate never reaches the network: a URL source is refused, naming it.
tests/guard/test_guard_external_catalogs.py:105
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | inferred | test_a_url_is_refused_by_name → read_catalog_at → git_text → git_argv |
| REQ-DDB-GUARD-027 | measured | test_a_url_is_refused_by_name → read_catalog_at |
Source · 12 lines
def test_a_url_is_refused_by_name(tmp_path: Path) -> None:
"""@brief A pre-commit gate never reaches the network: a URL source is refused, naming it."""
from clew.requirements import read_catalog_at
with pytest.raises(ValueError, match="URL"):
read_catalog_at(tmp_path, "https://example.invalid/requirements.yaml")
with pytest.raises(ValueError, match="URL"):
read_catalog_at(
tmp_path, {"repo": "git@github.com:o/r.git", "rev": "abc", "path": "r.yaml"}
)
Activity · 5 steps
test_an_external_catalogue_satisfies_cross_reference_without_a_local_one
None test_guard_external_catalogs.test_an_external_catalogue_satisfies_cross_reference_without_a_local_one(Path tmp_path, pytest.MonkeyPatch monkeypatch, pytest.CaptureFixture[str] capsys)
A library checks its tags against its consumer's catalogue; an unknown id is named.
tests/guard/test_guard_external_catalogs.py:56
Checks
assert code == 0, capsys.readouterr()assert code == 1 and "REQ-PRD-999" in (out.out + out.err)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-009 | measured | |
| REQ-DDB-GUARD-001 | 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-011 | measured | |
| REQ-DDB-GUARD-012 | measured | |
| REQ-DDB-GUARD-013 | measured | |
| REQ-DDB-GUARD-014 | measured | |
| REQ-DDB-GUARD-018 | measured | |
| REQ-DDB-GUARD-019 | measured | |
| REQ-DDB-GUARD-020 | measured | |
| REQ-DDB-GUARD-025 | measured | |
| REQ-DDB-GUARD-026 | measured | |
| REQ-DDB-GUARD-027 | measured | |
| REQ-DDB-PIPE-011 | measured | |
| REQ-DDB-SCHEMA-015 | measured |
Source · 13 lines
def test_an_external_catalogue_satisfies_cross_reference_without_a_local_one(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
) -> None:
"""@brief A library checks its tags against its consumer's catalogue; an unknown id is named."""
_catalog(tmp_path / "product" / "requirements.yaml", "REQ-PRD-001")
impact = "requirements:\n external: [product/requirements.yaml]\n"
code, _ = _run(tmp_path, monkeypatch, impact, "REQ-PRD-001")
assert code == 0, capsys.readouterr()
code, _ = _run(tmp_path, monkeypatch, impact, "REQ-PRD-999")
out = capsys.readouterr()
assert code == 1 and "REQ-PRD-999" in (out.out + out.err)
Activity · 7 steps
test_the_wiki_and_the_gate_read_catalogues_through_one_reader
None test_guard_external_catalogs.test_the_wiki_and_the_gate_read_catalogues_through_one_reader(Path tmp_path)
The shared reader returns every id with its row, in both catalogue shapes.
tests/guard/test_guard_external_catalogs.py:131
Checks
assert set(read_catalog_at(tmp_path, "keyed.yaml")) == {"REQ-A-001", "REQ-A-002"}assert read_catalog_at(tmp_path, "flat.yaml")["REQ-B-001"]["name"] == "B"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | inferred | test_the_wiki_and_the_gate_read_catalogues_through_one_reader → read_catalog_at → git_text → git_argv |
| REQ-DDB-GUARD-027 | measured | test_the_wiki_and_the_gate_read_catalogues_through_one_reader → read_catalog_at |
Source · 8 lines
def test_the_wiki_and_the_gate_read_catalogues_through_one_reader(tmp_path: Path) -> None:
"""@brief The shared reader returns every id with its row, in both catalogue shapes."""
from clew.requirements import read_catalog_at
_catalog(tmp_path / "keyed.yaml", "REQ-A-001", "REQ-A-002")
(tmp_path / "flat.yaml").write_text("- {id: REQ-B-001, name: B}\n")
assert set(read_catalog_at(tmp_path, "keyed.yaml")) == {"REQ-A-001", "REQ-A-002"}
assert read_catalog_at(tmp_path, "flat.yaml")["REQ-B-001"]["name"] == "B"1 more lines, not shown