Add baseline report formats and --baseline/--format CLI switches
CI / checks (pull_request) Successful in 1m5s
CI / checks (pull_request) Successful in 1m5s
Text and Markdown comparison reports (regressions first, IDs escaped); exit code still comes from the current arm only, errors give exit 2. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8f3844d650
commit
74574b948c
4 files changed
+213
-4
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
@@ -96,3 +97,71 @@ def test_exit_2_on_empty_set(tmp_path: Path, capsys: pytest.CaptureFixture[str])
|
||||
case.unlink()
|
||||
assert main([str(tmp_path)]) == 2
|
||||
assert "no cases found" in capsys.readouterr().err
|
||||
|
||||
|
||||
GIT = [
|
||||
"git",
|
||||
"-c",
|
||||
"user.name=t",
|
||||
"-c",
|
||||
"user.email=t@example.invalid",
|
||||
"-c",
|
||||
"commit.gpgsign=false",
|
||||
]
|
||||
|
||||
|
||||
def git(repo: Path, *args: str) -> None:
|
||||
subprocess.run([*GIT, "-C", str(repo), *args], capture_output=True, check=True) # noqa: S603
|
||||
|
||||
|
||||
def commit_all(repo: Path) -> None:
|
||||
git(repo, "add", "-A")
|
||||
git(repo, "commit", "-q", "-m", "x")
|
||||
|
||||
|
||||
def record(set_dir: Path, a: str, b: str) -> None:
|
||||
(set_dir / "recorded" / "a.json").write_text(a, encoding="utf-8")
|
||||
(set_dir / "recorded" / "b.json").write_text(b, encoding="utf-8")
|
||||
|
||||
|
||||
def test_baseline_exit_code_follows_current_arm(
|
||||
tmp_path: Path, capsys: pytest.CaptureFixture[str]
|
||||
) -> None:
|
||||
git(tmp_path, "init", "-q")
|
||||
set_dir = make_recorded(tmp_path / "demo", {"a": GOOD, "b": GOOD})
|
||||
commit_all(tmp_path)
|
||||
record(set_dir, GOOD, BAD)
|
||||
assert main([str(set_dir), "--baseline", "HEAD"]) == 1
|
||||
out = capsys.readouterr().out
|
||||
assert "demo: 1/2 passed" in out
|
||||
assert "REGRESSION b" in out
|
||||
commit_all(tmp_path)
|
||||
record(set_dir, GOOD, GOOD)
|
||||
assert main([str(set_dir), "--baseline", "HEAD"]) == 0
|
||||
assert "FIXED b" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_baseline_unknown_ref_exit_2(tmp_path: Path, capsys: pytest.CaptureFixture[str]) -> None:
|
||||
git(tmp_path, "init", "-q")
|
||||
set_dir = make_recorded(tmp_path / "demo", {"a": GOOD, "b": GOOD})
|
||||
commit_all(tmp_path)
|
||||
assert main([str(set_dir), "--baseline", "no-such-ref"]) == 2
|
||||
captured = capsys.readouterr()
|
||||
assert captured.err.startswith("chemenu-eval: ")
|
||||
assert captured.out == ""
|
||||
|
||||
|
||||
def test_markdown_requires_baseline(tmp_path: Path) -> None:
|
||||
make_recorded(tmp_path, {"a": GOOD, "b": GOOD})
|
||||
with pytest.raises(SystemExit) as excinfo:
|
||||
main([str(tmp_path), "--format", "markdown"])
|
||||
assert excinfo.value.code == 2
|
||||
|
||||
|
||||
def test_baseline_new_set_exit_0(tmp_path: Path, capsys: pytest.CaptureFixture[str]) -> None:
|
||||
git(tmp_path, "init", "-q")
|
||||
(tmp_path / "other.txt").write_text("x")
|
||||
commit_all(tmp_path)
|
||||
set_dir = make_recorded(tmp_path / "demo", {"a": GOOD, "b": GOOD})
|
||||
assert main([str(set_dir), "--baseline", "HEAD", "--format", "markdown"]) == 0
|
||||
assert "new set" in capsys.readouterr().out
|
||||
Reference in new issue
Block a user