Files
applepy/tests/test_runner_failures.py
Warezpeddler 3325436017 Initial commit
2026-04-25 23:09:31 +01:00

39 lines
1.2 KiB
Python

from pathlib import Path
from applepy.context import RunContext
from applepy.findings import Finding, Severity
from applepy.registry import CheckRegistry
from applepy.runner import run_phase
def _ok(_ctx: RunContext) -> list[Finding]:
return [
Finding(
id="ok-1",
title="OK check",
category="Test",
severity=Severity.INFORMATIONAL,
description="d",
evidence="e",
worksheet="Test",
)
]
def _boom(_ctx: RunContext) -> list[Finding]:
raise RuntimeError("deliberate test failure")
def test_run_phase_records_check_exception_as_finding(tmp_path: Path) -> None:
reg = CheckRegistry()
reg.register("boom", _boom, phases=("unprivileged",))
reg.register("ok", _ok, phases=("unprivileged",))
base = RunContext(home=tmp_path, output_dir=tmp_path, phase="unprivileged")
out = run_phase(reg, "unprivileged", base, parallel=False)
assert len(out) == 2
assert any(f.id == "ok-1" for f in out)
failed = [f for f in out if f.category == "Scanner reliability"]
assert len(failed) == 1
assert "boom" in failed[0].title
assert "RuntimeError" in failed[0].evidence