feat(e2e): sync the neutral core from kfde c03d61dd

This commit is contained in:
LGUG2Z committed 2026-10-30 18:22:44 -07:00
1 parent be4f1707ab
commit 8d5106f732
2 files changed
+79 -6

No files matched your search

+34 -6
View File
@@ -4,13 +4,24 @@ A suite file says what runs, in order, and each step labels the checks it makes:
scenario that runs on every platform, and a platform's own name for what only that platform can
check. The output reads `[shared] ...` and `[kde] ...`, and the same labels say, for each check,
which port it belongs to.
Each step prints the time it took, so that a log says which scenario the time went to.
To run only some of the steps, set `KFDE_ONLY` to a comma-separated list: a step runs when its
name (`module.function`, as printed) contains one of the words, and a step made with `always=True`
(what the others depend on, such as the one that opens the windows) runs whatever the list says.
The steps that do not run are printed, and return `None`.
"""
import os
import time
from collections.abc import Callable
from dataclasses import dataclass
from komorebi_vm.core.checks import Checks
ONLY = "KFDE_ONLY"
@dataclass(frozen=True)
class Step:
@@ -19,6 +30,7 @@ class Step:
scope: str
run: Callable[[], object]
name: str = ""
always: bool = False
def _name(fn: Callable[..., object]) -> str:
@@ -27,23 +39,39 @@ def _name(fn: Callable[..., object]) -> str:
return f"{module}.{getattr(fn, '__name__', '')}".strip(".")
def shared(scenario: Callable[..., object], *args: object) -> Step:
def shared(scenario: Callable[..., object], *args: object, always: bool = False) -> Step:
"""A scenario of `komorebi_vm.core.scenarios`, called with `args`."""
return Step("shared", lambda: scenario(*args), _name(scenario))
return Step("shared", lambda: scenario(*args), _name(scenario), always)
def platform_only(scope: str, extra: Callable[..., object], *args: object) -> Step:
def platform_only(
scope: str, extra: Callable[..., object], *args: object, always: bool = False
) -> Step:
"""What one platform adds: an extra of that platform, called with `args`, under its name."""
return Step(scope, lambda: extra(*args), _name(extra))
return Step(scope, lambda: extra(*args), _name(extra), always)
def _wanted() -> list[str]:
return [word.strip() for word in os.environ.get(ONLY, "").split(",") if word.strip()]
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 = []
so that a later part of a suite can use the windows a scenario opened.
A step that `KFDE_ONLY` leaves out is not run. A step that is run prints how long it took."""
wanted = _wanted()
results: list[object] = []
for step in steps:
if wanted and not step.always and not any(word in step.name for word in wanted):
print(f"== [{step.scope}] {step.name}: left out by {ONLY}")
results.append(None)
continue
if step.name:
print(f"== [{step.scope}] {step.name}")
started = time.monotonic()
with checks.scoped(step.scope):
results.append(step.run())
if step.name:
print(f" [{step.scope}] {step.name}: {time.monotonic() - started:.1f} s")
return results
+45
View File
@@ -89,3 +89,48 @@ def test_a_step_says_what_it_runs(capsys: pytest.CaptureFixture[str]) -> None:
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
def test_a_step_prints_how_long_it_took(capsys: pytest.CaptureFixture[str]) -> None:
def scenario() -> None:
pass
run_suite(Checks(), shared(scenario))
out = capsys.readouterr().out
assert " [shared] test_suite.scenario: " in out and " s\n" in out
def test_steps_not_named_in_the_list_are_left_out(
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
) -> None:
monkeypatch.setenv("KFDE_ONLY", "second, nothing")
ran: list[str] = []
def first() -> str:
ran.append("first")
return "a"
def second() -> str:
ran.append("second")
return "b"
def setup() -> str:
ran.append("setup")
return "c"
results = run_suite(
Checks(),
platform_only("kde", setup, always=True),
shared(first),
shared(second),
)
assert ran == ["setup", "second"]
assert results == ["c", None, "b"]
assert "test_suite.first: left out by KFDE_ONLY" in capsys.readouterr().out
def test_with_no_list_every_step_runs(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delenv("KFDE_ONLY", raising=False)
ran: list[int] = []
run_suite(Checks(), shared(lambda: ran.append(1)), shared(lambda: ran.append(2)))
assert ran == [1, 2]