88import pytest
99
1010from tests .regression .helpers import run_codeentropy_with_config
11+ from tests .regression .cases import discover_cases
1112
1213
1314def _group_index (payload : dict [str , Any ]) -> dict [str , dict [str , Any ]]:
14- """Return the groups mapping from a regression payload.
15-
16- Args:
17- payload: Parsed JSON payload.
18-
19- Returns:
20- Mapping of group id to group data.
21-
22- Raises:
23- TypeError: If payload["groups"] is not a dict.
24- """
15+ """Return the groups mapping from a regression payload."""
2516 groups = payload .get ("groups" , {})
2617 if not isinstance (groups , dict ):
2718 raise TypeError ("payload['groups'] must be a dict" )
@@ -35,17 +26,7 @@ def _compare_grouped(
3526 rtol : float ,
3627 atol : float ,
3728) -> None :
38- """Compare grouped regression outputs against baseline values.
39-
40- Args:
41- got_payload: Newly produced payload.
42- baseline_payload: Baseline payload.
43- rtol: Relative tolerance.
44- atol: Absolute tolerance.
45-
46- Raises:
47- AssertionError: If any required group/component differs from baseline.
48- """
29+ """Compare grouped regression outputs against baseline values."""
4930 got_groups = _group_index (got_payload )
5031 base_groups = _group_index (baseline_payload )
5132
@@ -100,50 +81,35 @@ def _compare_grouped(
10081
10182
10283@pytest .mark .regression
103- @pytest .mark .parametrize (
104- "system" ,
105- [
106- "dna" ,
107- pytest .param ("benzaldehyde" , marks = pytest .mark .slow ),
108- pytest .param ("benzene" , marks = pytest .mark .slow ),
109- pytest .param ("cyclohexane" , marks = pytest .mark .slow ),
110- pytest .param ("ethyl-acetate" , marks = pytest .mark .slow ),
111- pytest .param ("methane" , marks = pytest .mark .slow ),
112- pytest .param ("methanol" , marks = pytest .mark .slow ),
113- pytest .param ("octonol" , marks = pytest .mark .slow ),
114- pytest .param ("water" , marks = pytest .mark .slow ),
115- ],
116- )
84+ @pytest .mark .parametrize ("case" , discover_cases ())
11785def test_regression_matches_baseline (
118- tmp_path : Path , system : str , request : pytest .FixtureRequest
86+ tmp_path : Path , case , request : pytest .FixtureRequest
11987) -> None :
120- """Run a regression test for one system and compare to its baseline.
121-
122- Args:
123- tmp_path: Pytest-provided temporary directory.
124- system: System name parameter.
125- request: Pytest request fixture for reading CLI options.
126- """
127- repo_root = Path (__file__ ).resolve ().parents [2 ]
128- config_path = (
129- repo_root / "tests" / "regression" / "configs" / system / "config.yaml"
130- )
131- baseline_path = repo_root / "tests" / "regression" / "baselines" / f"{ system } .json"
88+ """Run a regression test for one system and compare to its baseline."""
89+ system = case .system
90+ config_path = case .config_path
91+ baseline_path = case .baseline_path
13292
13393 assert config_path .exists (), f"Missing config: { config_path } "
13494 assert baseline_path .exists (), f"Missing baseline: { baseline_path } "
13595
13696 baseline_payload = json .loads (baseline_path .read_text ())
137- run = run_codeentropy_with_config (workdir = tmp_path , config_src = config_path )
97+
98+ run = run_codeentropy_with_config (
99+ workdir = tmp_path ,
100+ config_src = config_path ,
101+ )
138102
139103 if request .config .getoption ("--codeentropy-debug" ):
140104 print ("\n [CodeEntropy regression debug]" )
105+ print ("system:" , system )
141106 print ("workdir:" , run .workdir )
142107 print ("job_dir:" , run .job_dir )
143108 print ("output_json:" , run .output_json )
144109 print ("payload copy saved:" , run .workdir / "codeentropy_output.json" )
145110
146111 if request .config .getoption ("--update-baselines" ):
112+ baseline_path .parent .mkdir (parents = True , exist_ok = True )
147113 baseline_path .write_text (json .dumps (run .payload , indent = 2 ))
148114 pytest .skip (f"Baseline updated for { system } : { baseline_path } " )
149115
0 commit comments