From ad02a1e7417dcba7b5d4bf4cf8ab7a546ffefc2d Mon Sep 17 00:00:00 2001 From: Tommy Gatti Date: Mon, 9 Sep 2024 13:40:48 +1000 Subject: [PATCH 1/2] test_access_om3_config.py: Added test_runconfig_ocn_cpl_dt_equals_runseq_coupling_timestep --- .../qa/test_access_om3_config.py | 67 ++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/src/model_config_tests/qa/test_access_om3_config.py b/src/model_config_tests/qa/test_access_om3_config.py index 05aeb47..4243bca 100644 --- a/src/model_config_tests/qa/test_access_om3_config.py +++ b/src/model_config_tests/qa/test_access_om3_config.py @@ -3,12 +3,75 @@ """ACCESS-OM3 specific configuration tests""" +import re +from pathlib import Path + import pytest +from payu.models.cesm_cmeps import Runconfig + +######################### +# Valid field constants # +######################### + +# Error message functions + + +def error_runconfig_variable_none(section: str, variable: str) -> str: + return f"nuopc.runconfig: section '{section}' variable {variable} does not exist." + + +def error_runseq_variable_none(variable: str) -> str: + return f"nuopc.runseq: {variable} does not exist." + + +################################ +# ACCESS-OM3-specific Fixtures # +################################ + + +@pytest.fixture(scope="class") +def nuopc_runconfig(control_path: Path) -> Runconfig: + runconfig_path: Path = control_path / "nuopc.runconfig" + + return Runconfig(runconfig_path) + + +@pytest.fixture(scope="class") +def nuopc_runseq(control_path: Path) -> list[str]: + runseq_path: Path = control_path / "nuopc.runseq" + + with open(runseq_path) as f: + # FIXME: Find something better + return f.readlines() + + +######### +# Tests # +######### @pytest.mark.access_om3 class TestAccessOM3: """ACCESS-OM3 Specific configuration and metadata tests""" - def test_pass(self): - pass + def test_runconfig_ocn_cpl_dt_equals_runseq_coupling_timestep( + self, nuopc_runconfig: Runconfig, nuopc_runseq: list[str] + ): + # Setup runconfig variable + rcfg_section = "CLOCK_attributes" + rcfg_variable = "ocn_cpl_dt" + rcfg_ocn_cpl_dt = nuopc_runconfig.get(rcfg_section, rcfg_variable) + + assert rcfg_ocn_cpl_dt, error_runconfig_variable_none( + rcfg_section, rcfg_variable + ) + + # Setup runseq variable + rseq_cpl_ts_match: str = [ + line for line in nuopc_runseq if re.match(r"@(\S*)", line) + ][0] + rseq_cpl_ts = rseq_cpl_ts_match.group(1) + + assert rseq_cpl_ts, error_runseq_variable_none("coupling timestep") + + assert rcfg_ocn_cpl_dt == rseq_cpl_ts From 2c114ba43c1bfd12a17a5322d10fa88e11f430b4 Mon Sep 17 00:00:00 2001 From: Tommy Gatti Date: Wed, 30 Oct 2024 16:15:55 +1100 Subject: [PATCH 2/2] Update version of `model-config-tests` to `0.0.9` --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3702858..397c024 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "model_config_tests" -version = "0.0.7" +version = "0.0.8" authors = [ { name = "ACCESS-NRI" }, ]