test_packaging.py¶
tests/test_packaging.py
Would `pip install clew` on a clean machine produce a working tool?
test_a_missing_doxygen_is_refused_not_traced_back
test_a_missing_doxygen_is_refused_not_traced_back(monkeypatch)
Checks
assert "not on PATH" in messageassert "apt install doxygen" in message, "the refusal must carry an install command"assert "PyPI" in message, "it must explain WHY it is not just another dependency"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | inferred | test_a_missing_doxygen_is_refused_not_traced_back → run_doxygen → doxygen_supports_sqlite3 |
| REQ-DDB-INDEX-001 | measured | test_a_missing_doxygen_is_refused_not_traced_back → run_doxygen |
| REQ-DDB-PIPE-003 | inferred | test_a_missing_doxygen_is_refused_not_traced_back → run_doxygen → _build_doxyfile_content → extra_input_clears_exclude |
| REQ-DDB-PIPE-006 | inferred | test_a_missing_doxygen_is_refused_not_traced_back → run_doxygen → clean_subprocess_env |
Source · 28 lines
def test_a_missing_doxygen_is_refused_not_traced_back(monkeypatch) -> None:
"""doxygen is the one prerequisite that CANNOT be a pip dependency — it is a
C++ program shipped as a system package, and `pip install doxygen` finds no
distribution. So on a clean machine it is the most likely thing to be missing,
and it was the worst-handled: `subprocess.Popen` raised
`FileNotFoundError: ... 'doxygen'` from twelve frames down, which reads as a
crash in this tool rather than a missing prerequisite.
Patches `shutil.which` rather than manipulating PATH so the test states its
premise directly and cannot be affected by the runner's environment.
Asserts the REMEDY is present, not just that something was raised: the value of
this refusal is that it tells the reader what to install, and an error message
without the fix is only a politer traceback."""
import pytest
from clew import doxygen as doxygen_module
from clew.errors import DoxygenUnavailableError
monkeypatch.setattr(doxygen_module.shutil, "which", lambda _name: None)
with pytest.raises(DoxygenUnavailableError) as exc:
doxygen_module.run_doxygen(REPO_ROOT / "nonexistent-Doxyfile", REPO_ROOT)
message = str(exc.value)
assert "not on PATH" in message
assert "apt install doxygen" in message, "the refusal must carry an install command"
assert "PyPI" in message, "it must explain WHY it is not just another dependency"Activity · 10 steps
test_every_action_is_pinned_by_commit_sha
test_every_action_is_pinned_by_commit_sha()
Checks
assert not offenders, ("these action references are mutable, so the code CI runs is chosen by whoever can " f"move the ref: {offenders}" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-039 | catalog |
Source · 20 lines
def test_every_action_is_pinned_by_commit_sha() -> None:
"""S2, 1.1.0 AUDIT. A mutable ref means the code that runs in CI is chosen by whoever
can move that ref, and `pypa/gh-action-pypi-publish@release/v1` was a BRANCH in the job
holding the publishing credential — a force-push to it publishes anything it likes as
this project. A local `./.github/workflows/...` call is exempt: it names this repository
at this commit.
@brief No workflow uses a tag or branch ref.
@version 1
"""
offenders = [
f"{where}: {ref}"
for where, ref in _action_refs()
if not ref.startswith("./") and not _SHA_RE.match(ref.partition("@")[2].split()[0])
]
assert not offenders, (
"these action references are mutable, so the code CI runs is chosen by whoever can "
f"move the ref: {offenders}"
)