Skip to content

Commit a6379e3

Browse files
committed
tests(regression): support baseline generation and missing baseline handling:
- Allow regression tests to run in `--update-baselines` mode without requiring existing baseline files - Defer baseline existence checks until after update-mode is considered - Create baseline directories automatically when updating baselines - Ensure `discover_cases` does not fail collection when baselines are missing
1 parent c625c63 commit a6379e3

7 files changed

Lines changed: 28 additions & 29 deletions

File tree

‎tests/regression/cases.py‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ def repo_root() -> Path:
1515

1616

1717
def discover_cases():
18-
configs_root = repo_root() / "tests/regression/configs"
19-
baselines_root = repo_root() / "tests/regression/baselines"
18+
base_dir = Path(__file__).resolve().parent
19+
20+
configs_root = base_dir / "configs"
21+
baselines_root = base_dir / "baselines"
2022

2123
cases = []
2224

@@ -25,18 +27,19 @@ def discover_cases():
2527
continue
2628

2729
system = system_dir.name
28-
config_path = system_dir / "config.yaml"
29-
baseline_path = baselines_root / system / "config.json"
3030

31-
if not config_path.exists():
32-
continue
31+
for config_path in sorted(system_dir.glob("*.yaml")):
32+
case_name = config_path.stem
33+
34+
baseline_path = baselines_root / system / f"{case_name}.json"
3335

34-
cases.append(
35-
pytest.param(
36-
RegressionCase(system, config_path, baseline_path),
37-
id=system,
38-
marks=pytest.mark.slow if system != "dna" else (),
36+
# DO NOT skip if baseline is missing
37+
cases.append(
38+
pytest.param(
39+
RegressionCase(system, config_path, baseline_path),
40+
id=f"{system}-{case_name}",
41+
marks=pytest.mark.slow if system != "dna" else (),
42+
)
3943
)
40-
)
4144

4245
return cases
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎tests/regression/test_regression.py‎

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313

1414
def _group_index(payload: dict[str, Any]) -> dict[str, dict[str, Any]]:
15-
"""Return the groups mapping from a regression payload."""
1615
groups = payload.get("groups", {})
1716
if not isinstance(groups, dict):
1817
raise TypeError("payload['groups'] must be a dict")
@@ -26,7 +25,6 @@ def _compare_grouped(
2625
rtol: float,
2726
atol: float,
2827
) -> None:
29-
"""Compare grouped regression outputs against baseline values."""
3028
got_groups = _group_index(got_payload)
3129
base_groups = _group_index(baseline_payload)
3230

@@ -41,9 +39,7 @@ def _compare_grouped(
4139
base_components = base_g.get("components", {})
4240
got_components = got_g.get("components", {})
4341

44-
if not isinstance(base_components, dict) or not isinstance(
45-
got_components, dict
46-
):
42+
if not isinstance(base_components, dict) or not isinstance(got_components, dict):
4743
mismatches.append(f"group {gid}: components must be dicts")
4844
continue
4945

@@ -73,8 +69,7 @@ def _compare_grouped(
7369
)
7470
except AssertionError:
7571
mismatches.append(
76-
f"group {gid} total: expected={base_g['total']} "
77-
f"got={got_g.get('total')}"
72+
f"group {gid} total: expected={base_g['total']} got={got_g.get('total')}"
7873
)
7974

8075
assert not mismatches, "Mismatches:\n" + "\n".join(" " + m for m in mismatches)
@@ -85,33 +80,34 @@ def _compare_grouped(
8580
def test_regression_matches_baseline(
8681
tmp_path: Path, case, request: pytest.FixtureRequest
8782
) -> None:
88-
"""Run a regression test for one system and compare to its baseline."""
8983
system = case.system
9084
config_path = case.config_path
9185
baseline_path = case.baseline_path
9286

93-
assert config_path.exists(), f"Missing config: {config_path}"
94-
assert baseline_path.exists(), f"Missing baseline: {baseline_path}"
87+
update_mode = request.config.getoption("--update-baselines")
9588

96-
baseline_payload = json.loads(baseline_path.read_text())
89+
if not baseline_path.exists():
90+
if not update_mode:
91+
raise AssertionError(f"Missing baseline: {baseline_path}")
92+
baseline_payload = {}
93+
else:
94+
baseline_payload = json.loads(baseline_path.read_text())
9795

9896
run = run_codeentropy_with_config(
9997
workdir=tmp_path,
10098
config_src=config_path,
10199
)
102100

103101
if request.config.getoption("--codeentropy-debug"):
104-
print("\n[CodeEntropy regression debug]")
102+
print("\n[DEBUG]")
105103
print("system:", system)
106-
print("workdir:", run.workdir)
107-
print("job_dir:", run.job_dir)
108-
print("output_json:", run.output_json)
109-
print("payload copy saved:", run.workdir / "codeentropy_output.json")
104+
print("config:", config_path)
105+
print("baseline:", baseline_path)
110106

111107
if request.config.getoption("--update-baselines"):
112108
baseline_path.parent.mkdir(parents=True, exist_ok=True)
113109
baseline_path.write_text(json.dumps(run.payload, indent=2))
114-
pytest.skip(f"Baseline updated for {system}: {baseline_path}")
110+
pytest.skip(f"Updated baseline for {system}")
115111

116112
_compare_grouped(
117113
got_payload=run.payload,

0 commit comments

Comments
 (0)