@@ -13,30 +13,50 @@ def _write_index(ens_path: Path, index_data: dict) -> Path:
1313 return index_file
1414
1515
16+ ENSEMBLE_ID = "6ec3d3f0-8b5b-4a3f-9c1a-3f6a3b0f1c11"
17+ EXPERIMENT_ID = "1f2e3d4c-5b6a-4978-8899-aabbccddeeff"
18+ PRIOR_ENSEMBLE_ID = "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d"
19+
20+
21+ def _index_data (** overrides ) -> dict :
22+ data = {
23+ "id" : ENSEMBLE_ID ,
24+ "experiment_id" : EXPERIMENT_ID ,
25+ "ensemble_size" : 10 ,
26+ "iteration" : 3 ,
27+ "name" : "batch_0" ,
28+ "prior_ensemble_id" : PRIOR_ENSEMBLE_ID ,
29+ "started_at" : "2023-01-01T00:00:00+00:00" ,
30+ "everest_realization_info" : {
31+ "0" : {"model_realization" : 0 , "perturbation" : - 1 },
32+ "1" : {"model_realization" : 0 , "perturbation" : 0 },
33+ },
34+ }
35+ data .update (overrides )
36+ return data
37+
38+
1639@pytest .mark .parametrize (
1740 ("original" , "expected" ),
1841 [
1942 pytest .param (
20- {
21- "id" : "ens-id" ,
22- "ensemble" : {"name" : "batch_0" , "iteration" : 0 , "is_improvement" : True },
23- },
24- {"id" : "ens-id" , "ensemble" : {"name" : "batch_0" , "iteration" : 0 }},
25- id = "removes_is_improvement" ,
43+ _index_data (is_improvement = True ),
44+ _index_data (),
45+ id = "removes_is_improvement_true" ,
2646 ),
2747 pytest .param (
28- { "ensemble" : { "name" : "batch_1" , "iteration" : 1 , " is_improvement" : False }} ,
29- { "ensemble" : { "name" : "batch_1" , "iteration" : 1 }} ,
48+ _index_data ( is_improvement = False ) ,
49+ _index_data () ,
3050 id = "removes_is_improvement_false" ,
3151 ),
3252 pytest .param (
33- { "ensemble" : { "name" : "batch_5" , "iteration" : 3 , " is_improvement" : True }} ,
34- { "ensemble" : { "name" : "batch_5" , "iteration" : 3 }} ,
35- id = "removes_is_improvement_other_values " ,
53+ _index_data ( is_improvement = None ) ,
54+ _index_data () ,
55+ id = "removes_is_improvement_none " ,
3656 ),
3757 pytest .param (
38- { "ensemble" : { "name" : "batch_0" , "iteration" : 0 }} ,
39- { "ensemble" : { "name" : "batch_0" , "iteration" : 0 }} ,
58+ _index_data () ,
59+ _index_data () ,
4060 id = "leaves_untouched_when_missing" ,
4161 ),
4262 ],
@@ -68,12 +88,3 @@ def test_that_migration_does_not_fail_on_unexpectedly_structured_dirs(tmp_path):
6888 migrate (root )
6989
7090 assert not_an_ensemble .read_text (encoding = "utf-8" ) == "{}"
71-
72-
73- def test_that_migration_does_not_fail_on_index_without_ensemble_entry (tmp_path ):
74- root = tmp_path / "project"
75- index_file = _write_index (root / "ensembles" / "ensemble_1" , {"id" : "ens-id" })
76-
77- migrate (root )
78-
79- assert json .loads (index_file .read_text (encoding = "utf-8" )) == {"id" : "ens-id" }
0 commit comments