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)

tests/test_packaging.py:227

Show on the map →

Called by none

Calls run_doxygen

Checks

  • 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"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002inferredtest_a_missing_doxygen_is_refused_not_traced_back → run_doxygen → doxygen_supports_sqlite3
REQ-DDB-INDEX-001measuredtest_a_missing_doxygen_is_refused_not_traced_back → run_doxygen
REQ-DDB-PIPE-003inferredtest_a_missing_doxygen_is_refused_not_traced_back → run_doxygen → _build_doxyfile_content → extra_input_clears_exclude
REQ-DDB-PIPE-006inferredtest_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
lines 241–241import pytestlines 243–243from clew import doxygen as doxygen_modulelines 244–244from clew.errors import DoxygenUnavailableErrorlines 246–246monkeypatch.setattr(doxygen_module.shutil, "which", lambda _name: None)lines 248–248with pytest.raises(DoxygenUnavailableError) as exclines 249–249doxygen_module.run_doxygen(REPO_ROOT / "nonexistent-Doxyfile", REPO_ROOT)lines 251–251message = str(exc.value)lines 252–252assert "not on PATH" in messagelines 253–253assert "apt install doxygen" in message, "the refusal must carry an install command"lines 254–254assert "PyPI" in message, "it must explain WHY it is not just another dependency"

test_every_action_is_pinned_by_commit_sha

test_every_action_is_pinned_by_commit_sha()

tests/test_packaging.py:307

Show on the map →

Called by none

Calls _action_refs

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

requirementlinkedpath to the implementer
REQ-DDB-WIKI-039catalog
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}"
    )
Activity · 2 steps
lines 317–321offenders = [ f"{where}: {ref}" for where, ref in _action_refs() if not ref.startswith("./") and not _SHA_RE.match(ref.partition("@")[2].split()[0]) ]lines 323–326assert not offenders, ( "these action references are mutable, so the code CI runs is chosen by whoever can " f"move the ref: {offenders}" )