Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions examples/run_quickstarts.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,9 @@ def run_quickstarts(
profile: str,
require_gpu: bool,
components: Sequence[str],
on_failure: Callable[[dict[str, Any]], None] | None = None,
) -> dict[str, Any]:
"""Run selected synthetic workflows and return their root summary."""
"""Return the root summary, reporting component failures to on_failure."""

if profile not in {"auto", "cpu"}:
raise ValueError("profile must be 'auto' or 'cpu'")
Expand Down Expand Up @@ -679,6 +680,8 @@ def run_quickstarts(
}
summary["status"] = "failed"
_write_json(summary_path, summary)
if on_failure is not None:
on_failure(summary)
raise
_write_json(summary_path, summary)

Expand Down Expand Up @@ -716,6 +719,10 @@ def build_parser() -> argparse.ArgumentParser:
return parser


def _print_summary(summary: dict[str, Any]) -> None:
print(json.dumps(summary, allow_nan=False, indent=2, sort_keys=True))


def main(argv: Sequence[str] | None = None) -> int:
parser = build_parser()
args = parser.parse_args(argv)
Expand All @@ -727,17 +734,15 @@ def main(argv: Sequence[str] | None = None) -> int:
profile=args.profile,
require_gpu=args.require_gpu,
components=args.component,
on_failure=_print_summary,
)
except Exception as exc:
print(
f"quickstart failed: {type(exc).__name__}: {exc}",
file=sys.stderr,
)
summary_path = args.output_dir.expanduser().resolve() / "summary.json"
if summary_path.is_file():
print(summary_path.read_text(encoding="utf-8"), end="")
return 1
print(json.dumps(summary, allow_nan=False, indent=2, sort_keys=True))
_print_summary(summary)
return 0


Expand Down
40 changes: 40 additions & 0 deletions tests/test_quickstarts.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,43 @@ def test_quickstart_output_directory_must_be_new(tmp_path: Path) -> None:
require_gpu=False,
components=["xray"],
)


def test_quickstart_main_existing_output_keeps_previous_summary(
tmp_path: Path, capsys: pytest.CaptureFixture[str]
) -> None:
summary_path = tmp_path / "summary.json"
previous = '{"status": "ok"}\n'
summary_path.write_text(previous)

assert run_quickstarts.main(["--output-dir", str(tmp_path)]) == 1

captured = capsys.readouterr()
assert captured.out == ""
assert "already exists" in captured.err
assert summary_path.read_text() == previous


def test_quickstart_main_reports_current_component_failure(
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
capsys: pytest.CaptureFixture[str],
) -> None:
def fail(*args: Any, **kwargs: Any) -> None:
raise ValueError("component failed")

monkeypatch.setattr(run_quickstarts, "detect_hardware", _cpu_hardware)
monkeypatch.setitem(run_quickstarts.RUNNERS, "xray", fail)
output = tmp_path / "new"

assert (
run_quickstarts.main(
["--component", "xray", "--output-dir", str(output)]
)
== 1
)

captured = capsys.readouterr()
assert captured.out == (output / "summary.json").read_text()
assert json.loads(captured.out)["status"] == "failed"
assert "ValueError: component failed" in captured.err
Loading