feat(nix): a suite names its steps and returns what they returned

This commit is contained in:
LGUG2Z committed 2026-10-30 12:03:01 -07:00
1 parent af25cf8564
commit 2c58920db0
2 files changed
+32 -5

No files matched your search

+17 -5
View File
@@ -18,20 +18,32 @@ class Step:
scope: str
run: Callable[[], object]
name: str = ""
def _name(fn: Callable[..., object]) -> str:
"""`module.function` of a scenario or an extra, for the line that says what runs."""
module = getattr(fn, "__module__", "").rsplit(".", 1)[-1]
return f"{module}.{getattr(fn, '__name__', '')}".strip(".")
def shared(scenario: Callable[..., object], *args: object) -> Step:
"""A scenario of `komorebi_vm.core.scenarios`, called with `args`."""
return Step("shared", lambda: scenario(*args))
return Step("shared", lambda: scenario(*args), _name(scenario))
def platform_only(scope: str, extra: Callable[..., object], *args: object) -> Step:
"""What one platform adds: an extra of that platform, called with `args`, under its name."""
return Step(scope, lambda: extra(*args))
return Step(scope, lambda: extra(*args), _name(extra))
def run_suite(checks: Checks, *steps: Step) -> None:
"""Runs the steps in order, each with its scope on `checks`."""
def run_suite(checks: Checks, *steps: Step) -> list[object]:
"""Runs the steps in order, each with its scope on `checks`, and returns what each returned,
so that a later part of a suite can use the windows a scenario opened."""
results = []
for step in steps:
if step.name:
print(f"== [{step.scope}] {step.name}")
with checks.scoped(step.scope):
step.run()
results.append(step.run())
return results
+15
View File
@@ -74,3 +74,18 @@ def test_a_suite_runs_its_steps_in_order_each_in_its_own_scope() -> None:
)
assert order == ["kde:first", "shared:second", "kde:third"]
assert checks.scope == ""
def test_a_suite_returns_what_its_steps_returned() -> None:
checks = Checks()
results = run_suite(checks, shared(lambda: 1), platform_only("kde", lambda: "two"))
assert results == [1, "two"]
def test_a_step_says_what_it_runs(capsys: pytest.CaptureFixture[str]) -> None:
def scenario() -> None:
pass
run_suite(Checks(), shared(scenario), platform_only("kde", scenario))
out = capsys.readouterr().out
assert "== [shared] test_suite.scenario" in out and "== [kde] test_suite.scenario" in out