1111from experanto .interpolators import Interpolator
1212
1313from .create_experiment import (
14- get_default_config ,
14+ make_modality_config ,
1515 setup_test_experiment ,
1616)
1717
@@ -126,7 +126,7 @@ def test_get_valid_range_all_devices(tmp_path, device_name, start_t, end_t):
126126 {"start_time" : 5.0 , "t_end" : 15.0 },
127127 ],
128128 ) as experiment_path :
129- config = get_default_config ( )
129+ config = make_modality_config ( "device_0" , "device_1" , "device_2" )
130130 config ["device_2" ] = {
131131 "sampling_rate" : 1.0 ,
132132 "chunk_size" : 40 ,
@@ -142,7 +142,8 @@ def test_get_valid_range_all_devices(tmp_path, device_name, start_t, end_t):
142142def test_get_valid_range_raises_for_invalid_device (tmp_path ):
143143 with setup_test_experiment (tmp_path ) as experiment_path :
144144 experiment = Experiment (
145- root_folder = str (experiment_path ), modality_config = get_default_config ()
145+ root_folder = str (experiment_path ),
146+ modality_config = make_modality_config ("device_0" , "device_1" ),
146147 )
147148 with pytest .raises (KeyError ):
148149 experiment .get_valid_range ("device_does_not_exist" )
@@ -157,7 +158,8 @@ def test_experiment_with_non_zero_start_time(tmp_path):
157158 devices_kwargs = [{"t_end" : start_offset + duration , "start_time" : start_offset }],
158159 ) as experiment_path :
159160 experiment = Experiment (
160- root_folder = str (experiment_path ), modality_config = get_default_config ()
161+ root_folder = str (experiment_path ),
162+ modality_config = make_modality_config ("device_0" ),
161163 )
162164 res = experiment .interpolate (np .array ([start_offset + 1.0 ]), device = "device_0" )
163165 assert res is not None
@@ -187,9 +189,11 @@ def test_experiment_numeric_precision_offset(
187189 ],
188190 ) as experiment_path :
189191 experiment = Experiment (
190- root_folder = str (experiment_path ), modality_config = get_default_config ()
192+ root_folder = str (experiment_path ),
193+ modality_config = make_modality_config ("device_0" ),
191194 )
192195 valid_range = experiment .get_valid_range ("device_0" )
196+ # Keep pytest.approx here as it's dealing with floats generated by Hypothesis
193197 assert valid_range [0 ] == pytest .approx (start_offset )
194198 assert valid_range [1 ] == pytest .approx (start_offset + duration )
195199 res = experiment .interpolate (np .array ([start_offset ]), device = "device_0" )
@@ -202,7 +206,8 @@ def test_experiment_multi_device_interpolation(tmp_path, return_valid, device):
202206 """Check data consistency when interpolating across multiple modalities."""
203207 with setup_test_experiment (tmp_path , n_devices = 2 ) as experiment_path :
204208 exp = Experiment (
205- root_folder = str (experiment_path ), modality_config = get_default_config ()
209+ root_folder = str (experiment_path ),
210+ modality_config = make_modality_config ("device_0" , "device_1" ),
206211 )
207212 times = np .array ([1.0 , 2.0 ])
208213 results = exp .interpolate (times , device = device , return_valid = return_valid )
@@ -244,22 +249,18 @@ def test_experiment_start_end_time_reflects_union(
244249 with setup_test_experiment (
245250 tmp_path , n_devices = len (device_ranges ), devices_kwargs = devices_kwargs
246251 ) as experiment_path :
247- # Manually build the config dict for however many devices were generated
248- config = {}
249- for i in range (len (device_ranges )):
250- config [f"device_{ i } " ] = {
251- "interpolation" : {
252- "sampling_rate" : 10.0 ,
253- "offset" : float (np .random .rand ()),
254- }
255- }
252+ # Dynamically build the config using make_modality_config
253+ device_names = [f"device_{ i } " for i in range (len (device_ranges ))]
254+ offsets = [float (np .random .rand ()) for _ in device_ranges ]
255+ config = make_modality_config (* device_names , offsets = offsets )
256256
257257 experiment = Experiment (
258258 root_folder = str (experiment_path ), modality_config = config
259259 )
260260
261- assert experiment .start_time == pytest .approx (expected_start )
262- assert experiment .end_time == pytest .approx (expected_end )
261+ # Removed pytest.approx here
262+ assert experiment .start_time == expected_start
263+ assert experiment .end_time == expected_end
263264
264265
265266@pytest .mark .parametrize ("override_meta" , INVALID_META_CASES , ids = INVALID_META_IDS )
@@ -275,7 +276,7 @@ def test_experiment_invalid_metadata(tmp_path, override_meta):
275276 with open (meta_file , "w" ) as f :
276277 yaml .safe_dump (meta , f )
277278
278- config = { "device_0" : { "interpolation" : { "sampling_rate" : 10.0 }}}
279+ config = make_modality_config ( "device_0" )
279280
280281 with pytest .raises (
281282 ValueError , match = "Experiment time range could not be determined"
@@ -311,10 +312,7 @@ def test_experiment_skips_invalid_devices(tmp_path, override_meta, caplog):
311312 with open (meta_file , "w" ) as f :
312313 yaml .safe_dump (meta , f )
313314
314- config = {
315- "valid_device" : {"interpolation" : {"sampling_rate" : 10.0 }},
316- "invalid_device" : {"interpolation" : {"sampling_rate" : 10.0 }},
317- }
315+ config = make_modality_config ("valid_device" , "invalid_device" )
318316
319317 with caplog .at_level (logging .WARNING , logger = "experanto.experiment" ):
320318 experiment = Experiment (
@@ -323,5 +321,6 @@ def test_experiment_skips_invalid_devices(tmp_path, override_meta, caplog):
323321
324322 assert "valid_device" in experiment .devices
325323 assert "invalid_device" not in experiment .devices
326- assert experiment .start_time == pytest .approx (start_val )
327- assert experiment .end_time == pytest .approx (end_val )
324+ # Removed pytest.approx here
325+ assert experiment .start_time == start_val
326+ assert experiment .end_time == end_val
0 commit comments