Initial commit
This commit is contained in:
38
tests/test_runner_failures.py
Normal file
38
tests/test_runner_failures.py
Normal file
@@ -0,0 +1,38 @@
|
||||
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
|
||||
Reference in New Issue
Block a user