republisher/tests/test_qa.py

67 lines
1.9 KiB
Python

import tomllib
from pathlib import Path
from types import SimpleNamespace
from repub.qa import qa_entrypoint, qa_final_entrypoint
def test_pyproject_registers_qa_scripts() -> None:
pyproject_path = Path(__file__).resolve().parents[1] / "pyproject.toml"
config = tomllib.loads(pyproject_path.read_text(encoding="utf-8"))
scripts = config["project"]["scripts"]
assert scripts["qa"] == "repub.qa:qa_entrypoint"
assert scripts["qa-final"] == "repub.qa:qa_final_entrypoint"
def test_qa_entrypoint_runs_expected_commands_in_order(monkeypatch) -> None:
recorded: list[tuple[str, ...]] = []
def fake_run(command: tuple[str, ...], *, check: bool) -> SimpleNamespace:
recorded.append(command)
return SimpleNamespace(returncode=0)
monkeypatch.setattr("repub.qa.subprocess.run", fake_run)
assert qa_entrypoint() == 0
assert recorded == [
(
"tailwindcss",
"-i",
"./repub/static/app.tailwind.css",
"-o",
"./repub/static/app.css",
),
("black", "repub/", "tests/"),
("flake8", "repub/", "tests/"),
("pyright",),
("pytest",),
]
def test_qa_final_entrypoint_runs_expected_commands_in_order(monkeypatch) -> None:
recorded: list[tuple[str, ...]] = []
def fake_run(command: tuple[str, ...], *, check: bool) -> SimpleNamespace:
recorded.append(command)
return SimpleNamespace(returncode=0)
monkeypatch.setattr("repub.qa.subprocess.run", fake_run)
assert qa_final_entrypoint() == 0
assert recorded == [
(
"tailwindcss",
"-i",
"./repub/static/app.tailwind.css",
"-o",
"./repub/static/app.css",
),
("black", "repub/", "tests/"),
("flake8", "repub/", "tests/"),
("pyright",),
("pytest",),
("nix", "fmt"),
("nix", "flake", "check"),
]