Skip to content

Commit

Permalink
Split accessom3 tests into folder
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-seaice committed Sep 2, 2024
1 parent d102d1c commit 003717f
Showing 1 changed file with 3 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,95 +5,13 @@
import pytest

import payu
from payu.models.cesm_cmeps import Runconfig

from test.common import cd, tmpdir, ctrldir, labdir, workdir, write_config, config_path
from test.common import config as config_orig
from test.common import make_inputs, make_exe

NCPU = 24


@pytest.fixture()
def runconfig_path():
return os.path.join('test', 'resources', 'nuopc.runconfig')


@pytest.fixture()
def runconfig(runconfig_path):
return Runconfig(runconfig_path)


# Runconfig tests:

@pytest.mark.parametrize(
"section, variable, expected",
[
("ALLCOMP_attributes", "OCN_model", "mom"),
("CLOCK_attributes", "restart_n", "1"),
("DOES_NOT_EXIST", "OCN_model", None),
("ALLCOMP_attributes", "DOES_NOT_EXIST", None),
("allcomp_attributes", "OCN_model", None), # verify case sensitivity in section
("ALLCOMP_attributes", "ocn_model", None), # verify case sensitivity in variable
("ATM_attributes", "perpetual", ".false."), # correctly read booleans
("ICE_attributes", "eps_imesh", "1e-13"), # correctly read commented value
("MED_attributes", "histaux_atm2med_file1_flds", "Faxa_swndr:Faxa_swvdr:Faxa_swndf:Faxa_swvdf"), # correctly read long colon separated value
]
)
def test_runconfig_get(section, variable, expected, runconfig):
"""Test getting values from a nuopc.runconfig file"""
assert runconfig.get(section, variable) == expected


def test_runconfig_get_default(runconfig):
"""Test getting default values from a nuopc.runconfig file"""
assert runconfig.get("DOES_NOT_EXIST", "DOES_NOT_EXIST", value="default") == "default"


def test_runconfig_get_component_list(runconfig):
"""Test getting component_list from a nuopc.runconfig file"""
COMP_LIST = ['MED', 'ATM', 'ICE', 'OCN', 'ROF']
assert runconfig.get_component_list() == COMP_LIST


@pytest.mark.parametrize(
"section, variable, new_variable",
[
("ALLCOMP_attributes", "OCN_model", "pop"),
("CLOCK_attributes", "restart_n", "2"),
]
)
def test_runconfig_set(section, variable, new_variable, runconfig):
"""Test setting values in a nuopc.runconfig file"""
runconfig.set(section, variable, new_variable)

assert runconfig.get(section, variable) == new_variable


def test_runconfig_set_error(runconfig):
"""Test error setting values in a nuopc.runconfig file that don't exist"""
with pytest.raises(
NotImplementedError,
match='Cannot set value of variable that does not already exist'
):
runconfig.set("DOES_NOT_EXIST", "OCN_model", "value")
runconfig.set("ALLCOMP_attributes", "DOES_NOT_EXIST", "value")


def test_runconfig_set_write_get(runconfig):
"""Test updating the values in a nuopc.runconfig file"""
assert runconfig.get("CLOCK_attributes", "restart_n") == "1"

runconfig.set("CLOCK_attributes", "restart_n", "2")

runconfig_path_tmp = os.path.join(tmpdir, "nuopc.runconfig.tmp")
runconfig.write(file=runconfig_path_tmp)

runconfig_updated = Runconfig(runconfig_path_tmp)
assert runconfig_updated.get("CLOCK_attributes", "restart_n") == "2"

os.remove(runconfig_path_tmp)

MODEL = 'access-om3'

# Tests of cesm_cmeps

Expand Down Expand Up @@ -137,7 +55,7 @@ def cmeps_config():
# Create a config.yaml and nuopc.runconfig file

config = copy.deepcopy(config_orig)
config['model'] = 'access-om3'
config['model'] = MODEL
config['ncpus'] = NCPU

write_config(config)
Expand Down Expand Up @@ -261,7 +179,7 @@ def test__setup_checks_io(cmeps_config, modelio_patch):


@pytest.mark.parametrize("modelio_patch", [
{"pio_typename": "netcdf4s"},
{"pio_typename": "netcdf4c"},
{"pio_typename": "netcdf", "pio_root": NCPU+1},
{"pio_numiotasks": NCPU+1},
{"pio_numiotasks": 1, "pio_root": NCPU},
Expand Down

0 comments on commit 003717f

Please sign in to comment.