11"""
2- Unit‑tests for SimulationSuiteConfig ⇄ SimulationConfig behaviour.
3-
2+ Unit‑tests for SimulationSuiteConfig ⇄ SimulationConfig behavior.
43Covered
54-------
65* suite‑level defaults propagate into children
76* child‑level overrides win
8- * missing required keys always raise (allow_missing removed)
7+ * missing required keys always raise (allow_missing removed)
98"""
109
1110from typing import Dict
1918# ---------------------------------------------------------------------------
2019# constants
2120# ---------------------------------------------------------------------------
22-
2321ROOT_ENV , CHILD_A , CHILD_B = "env/root" , "env/a" , "env/b"
2422DEVICE , RUN_DIR = "cpu" , "./runs/test"
2523
2624
27- def _build (cfg : Dict ):
28- return SimulationSuiteConfig (OmegaConf .create (cfg ))
25+ @pytest .fixture
26+ def build_simulation_suite_config ():
27+ def _build (cfg : Dict ):
28+ # First create the OmegaConf object
29+ dict_config = OmegaConf .create (cfg )
30+
31+ # Convert to a Python dictionary
32+ regular_dict = OmegaConf .to_container (dict_config , resolve = True )
33+
34+ # Now create the SimulationSuiteConfig using the model_validate method
35+ return SimulationSuiteConfig .model_validate (regular_dict )
36+
37+ return _build
2938
3039
3140# ---------------------------------------------------------------------------
3241# propagation & overrides
3342# ---------------------------------------------------------------------------
34-
35-
36- def test_propogate_defaults_and_overrides ():
43+ def test_propagate_defaults_and_overrides (build_simulation_suite_config ):
3744 cfg = {
3845 "env" : ROOT_ENV ,
3946 "num_envs" : 4 ,
@@ -45,9 +52,8 @@ def test_propogate_defaults_and_overrides():
4552 "b" : {"env" : CHILD_B , "num_envs" : 8 }, # overrides num_envs
4653 },
4754 }
48- suite = _build (cfg )
55+ suite = build_simulation_suite_config (cfg )
4956 a , b = suite .simulations ["a" ], suite .simulations ["b" ]
50-
5157 # device and num_envs both propagated, even though num_envs has a default
5258 assert (a .device , a .num_envs ) == (DEVICE , 4 )
5359 assert (b .device , b .num_envs ) == (DEVICE , 8 )
@@ -56,20 +62,17 @@ def test_propogate_defaults_and_overrides():
5662# ---------------------------------------------------------------------------
5763# allow_extra – child nodes
5864# ---------------------------------------------------------------------------
59-
60-
6165@pytest .mark .parametrize (
6266 "has_extra, should_pass" ,
6367 [
6468 (False , True ),
6569 (True , False ),
6670 ],
6771)
68- def test_allow_extra_child_keys (has_extra , should_pass ):
72+ def test_allow_extra_child_keys (build_simulation_suite_config , has_extra , should_pass ):
6973 child_node = {"env" : CHILD_A }
7074 if has_extra :
7175 child_node ["foo" ] = "bar" # <- unknown key
72-
7376 cfg = {
7477 "env" : ROOT_ENV ,
7578 "num_envs" : 4 ,
@@ -78,21 +81,18 @@ def test_allow_extra_child_keys(has_extra, should_pass):
7881 "run_dir" : RUN_DIR ,
7982 "simulations" : {"sim" : child_node },
8083 }
81-
8284 if should_pass :
83- suite = _build (cfg )
85+ suite = build_simulation_suite_config (cfg )
8486 assert suite .simulations ["sim" ].device == DEVICE
8587 else :
8688 with pytest .raises (ValueError ):
87- _build (cfg )
89+ build_simulation_suite_config (cfg )
8890
8991
9092# ---------------------------------------------------------------------------
9193# missing required keys should always error
9294# ---------------------------------------------------------------------------
93-
94-
95- def test_missing_device_always_errors ():
95+ def test_missing_device_always_errors (build_simulation_suite_config ):
9696 cfg = {
9797 "env" : ROOT_ENV ,
9898 "num_envs" : 4 ,
@@ -101,10 +101,10 @@ def test_missing_device_always_errors():
101101 "simulations" : {"sim" : {}}, # required 'device' omitted
102102 }
103103 with pytest .raises (ValidationError ):
104- _build (cfg )
104+ build_simulation_suite_config (cfg )
105105
106106
107- def test_missing_suite_env_is_allowed ():
107+ def test_missing_suite_env_is_allowed (build_simulation_suite_config ):
108108 cfg = {
109109 "run_dir" : RUN_DIR ,
110110 "device" : DEVICE ,
@@ -116,5 +116,5 @@ def test_missing_suite_env_is_allowed():
116116 }
117117 },
118118 }
119- suite = _build (cfg )
119+ suite = build_simulation_suite_config (cfg )
120120 assert suite .simulations ["sim" ].env == CHILD_A
0 commit comments