Skip to content

Commit

Permalink
test_access_om3_config.py: Added test_runconfig_ocn_cpl_dt_equals_run…
Browse files Browse the repository at this point in the history
…seq_coupling_timestep
  • Loading branch information
CodeGat committed Oct 17, 2024
1 parent cac6a39 commit f12a53b
Showing 1 changed file with 65 additions and 2 deletions.
67 changes: 65 additions & 2 deletions src/model_config_tests/qa/test_access_om3_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Check warning on line 20 in src/model_config_tests/qa/test_access_om3_config.py

View check run for this annotation

Codecov / codecov/patch

src/model_config_tests/qa/test_access_om3_config.py#L20

Added line #L20 was not covered by tests


def error_runseq_variable_none(variable: str) -> str:
return f"nuopc.runseq: {variable} does not exist."

Check warning on line 24 in src/model_config_tests/qa/test_access_om3_config.py

View check run for this annotation

Codecov / codecov/patch

src/model_config_tests/qa/test_access_om3_config.py#L24

Added line #L24 was not covered by tests


################################
# ACCESS-OM3-specific Fixtures #
################################


@pytest.fixture(scope="class")
def nuopc_runconfig(control_path: Path) -> Runconfig:
runconfig_path: Path = control_path / "nuopc.runconfig"

Check warning on line 34 in src/model_config_tests/qa/test_access_om3_config.py

View check run for this annotation

Codecov / codecov/patch

src/model_config_tests/qa/test_access_om3_config.py#L34

Added line #L34 was not covered by tests

return Runconfig(runconfig_path)

Check warning on line 36 in src/model_config_tests/qa/test_access_om3_config.py

View check run for this annotation

Codecov / codecov/patch

src/model_config_tests/qa/test_access_om3_config.py#L36

Added line #L36 was not covered by tests


@pytest.fixture(scope="class")
def nuopc_runseq(control_path: Path) -> list[str]:
runseq_path: Path = control_path / "nuopc.runseq"

Check warning on line 41 in src/model_config_tests/qa/test_access_om3_config.py

View check run for this annotation

Codecov / codecov/patch

src/model_config_tests/qa/test_access_om3_config.py#L41

Added line #L41 was not covered by tests

with open(runseq_path) as f:

Check warning on line 43 in src/model_config_tests/qa/test_access_om3_config.py

View check run for this annotation

Codecov / codecov/patch

src/model_config_tests/qa/test_access_om3_config.py#L43

Added line #L43 was not covered by tests
# FIXME: Find something better
return f.readlines()

Check warning on line 45 in src/model_config_tests/qa/test_access_om3_config.py

View check run for this annotation

Codecov / codecov/patch

src/model_config_tests/qa/test_access_om3_config.py#L45

Added line #L45 was not covered by tests


#########
# 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)

Check warning on line 63 in src/model_config_tests/qa/test_access_om3_config.py

View check run for this annotation

Codecov / codecov/patch

src/model_config_tests/qa/test_access_om3_config.py#L61-L63

Added lines #L61 - L63 were not covered by tests

assert rcfg_ocn_cpl_dt, error_runconfig_variable_none(

Check warning on line 65 in src/model_config_tests/qa/test_access_om3_config.py

View check run for this annotation

Codecov / codecov/patch

src/model_config_tests/qa/test_access_om3_config.py#L65

Added line #L65 was not covered by tests
rcfg_section, rcfg_variable
)

# Setup runseq variable
rseq_cpl_ts_match: str = [

Check warning on line 70 in src/model_config_tests/qa/test_access_om3_config.py

View check run for this annotation

Codecov / codecov/patch

src/model_config_tests/qa/test_access_om3_config.py#L70

Added line #L70 was not covered by tests
line for line in nuopc_runseq if re.match(r"@(\S*)", line)
][0]
rseq_cpl_ts = rseq_cpl_ts_match.group(1)

Check warning on line 73 in src/model_config_tests/qa/test_access_om3_config.py

View check run for this annotation

Codecov / codecov/patch

src/model_config_tests/qa/test_access_om3_config.py#L73

Added line #L73 was not covered by tests

assert rseq_cpl_ts, error_runseq_variable_none("coupling timestep")

Check warning on line 75 in src/model_config_tests/qa/test_access_om3_config.py

View check run for this annotation

Codecov / codecov/patch

src/model_config_tests/qa/test_access_om3_config.py#L75

Added line #L75 was not covered by tests

assert rcfg_ocn_cpl_dt == rseq_cpl_ts

Check warning on line 77 in src/model_config_tests/qa/test_access_om3_config.py

View check run for this annotation

Codecov / codecov/patch

src/model_config_tests/qa/test_access_om3_config.py#L77

Added line #L77 was not covered by tests

0 comments on commit f12a53b

Please sign in to comment.