Skip to content

Commit ec31b16

Browse files
committed
Update tests
1 parent a88d823 commit ec31b16

File tree

1 file changed

+43
-36
lines changed

1 file changed

+43
-36
lines changed

tests/test_mop.py

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,24 @@
33

44
import pandas as pd
55
import pytest
6-
from access_mopper.configurations import ACCESS_ESM16_CMIP6
6+
from access_mopper import ACCESS_ESM_CMORiser
77

88
DATA_DIR = Path(__file__).parent / "data"
99

1010

1111
@pytest.fixture
12-
def model():
13-
# Create and save the model
14-
model_instance = ACCESS_ESM16_CMIP6(
15-
experiment_id="piControl-spinup",
16-
realization_index="1",
17-
initialization_index="1",
18-
physics_index="1",
19-
forcing_index="1",
20-
parent_mip_era="no parent",
21-
parent_activity_id="no parent",
22-
parent_experiment_id="no parent",
23-
parent_source_id="no parent",
24-
parent_variant_label="no parent",
25-
parent_time_units="no parent",
26-
branch_method="no parent",
27-
branch_time_in_parent=0.0,
28-
branch_time_in_child=0.0,
29-
)
30-
model_instance.save_to_file("model.json")
31-
return model_instance
12+
def parent_experiment_config():
13+
return {
14+
"parent_experiment_id": "piControl",
15+
"parent_activity_id": "CMIP",
16+
"parent_source_id": "ACCESS-ESM1-5",
17+
"parent_variant_label": "r1i1p1f1",
18+
"parent_time_units": "days since 0001-01-01 00:00:00",
19+
"parent_mip_era": "CMIP6",
20+
"branch_time_in_child": 0.0,
21+
"branch_time_in_parent": 54786.0,
22+
"branch_method": "standard",
23+
}
3224

3325

3426
def test_model_function():
@@ -46,46 +38,61 @@ def load_filtered_variables(mappings):
4638
@pytest.mark.parametrize(
4739
"cmor_name", load_filtered_variables("Mappings_CMIP6_Amon.json")
4840
)
49-
def test_cmorise_CMIP6_Amon(model, cmor_name):
41+
def test_cmorise_CMIP6_Amon(parent_experiment_config, cmor_name):
5042
file_pattern = DATA_DIR / "esm1-6/atmosphere/aiihca.pa-101909_mon.nc"
5143
try:
52-
model.cmorise(
53-
file_paths=file_pattern,
44+
cmoriser = ACCESS_ESM_CMORiser(
45+
input_paths=file_pattern,
5446
compound_name="Amon." + cmor_name,
55-
cmor_dataset_json="model.json",
56-
mip_table="CMIP6_Amon.json",
47+
experiment_id="historical",
48+
source_id="ACCESS-ESM1-5",
49+
variant_label="r1i1p1f1",
50+
grid_label="gn",
51+
activity_id="CMIP",
52+
parent_info=parent_experiment_config,
5753
)
54+
cmoriser.run()
5855
except Exception as e:
5956
pytest.fail(f"Failed processing {cmor_name} with table CMIP6_Amon.json: {e}")
6057

6158

6259
@pytest.mark.parametrize(
6360
"cmor_name", load_filtered_variables("Mappings_CMIP6_Lmon.json")
6461
)
65-
def test_cmorise_CMIP6_Lmon(model, cmor_name):
62+
def test_cmorise_CMIP6_Lmon(parent_experiment_config, cmor_name):
6663
file_pattern = DATA_DIR / "esm1-6/atmosphere/aiihca.pa-101909_mon.nc"
6764
try:
68-
model.cmorise(
69-
file_paths=file_pattern,
65+
cmoriser = ACCESS_ESM_CMORiser(
66+
input_paths=file_pattern,
7067
compound_name="Lmon." + cmor_name,
71-
cmor_dataset_json="model.json",
72-
mip_table="CMIP6_Lmon.json",
68+
experiment_id="historical",
69+
source_id="ACCESS-ESM1-5",
70+
variant_label="r1i1p1f1",
71+
grid_label="gn",
72+
activity_id="CMIP",
73+
parent_info=parent_experiment_config,
7374
)
75+
cmoriser.run()
7476
except Exception as e:
7577
pytest.fail(f"Failed processing {cmor_name} with table CMIP6_Lmon.json: {e}")
7678

7779

7880
@pytest.mark.parametrize(
7981
"cmor_name", load_filtered_variables("Mappings_CMIP6_Emon.json")
8082
)
81-
def test_cmorise_CMIP6_Emon(model, cmor_name):
83+
def test_cmorise_CMIP6_Emon(parent_experiment_config, cmor_name):
8284
file_pattern = DATA_DIR / "esm1-6/atmosphere/aiihca.pa-101909_mon.nc"
8385
try:
84-
model.cmorise(
85-
file_paths=file_pattern,
86+
cmoriser = ACCESS_ESM_CMORiser(
87+
input_paths=file_pattern,
8688
compound_name="Emon." + cmor_name,
87-
cmor_dataset_json="model.json",
88-
mip_table="CMIP6_Emon.json",
89+
experiment_id="historical",
90+
source_id="ACCESS-ESM1-5",
91+
variant_label="r1i1p1f1",
92+
grid_label="gn",
93+
activity_id="CMIP",
94+
parent_info=parent_experiment_config,
8995
)
96+
cmoriser.run()
9097
except Exception as e:
9198
pytest.fail(f"Failed processing {cmor_name} with table CMIP6_Emon.json: {e}")

0 commit comments

Comments
 (0)