Skip to content

Commit

Permalink
Parametrize for loops
Browse files Browse the repository at this point in the history
  • Loading branch information
maddenp-noaa committed Jun 24, 2024
1 parent 1ab0f37 commit e015477
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 50 deletions.
13 changes: 8 additions & 5 deletions src/uwtools/tests/drivers/test_chgres_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import f90nml # type: ignore
from iotaa import refs
from pytest import fixture
from pytest import fixture, mark

from uwtools.drivers.chgres_cube import ChgresCube
from uwtools.drivers.driver import Driver
Expand Down Expand Up @@ -83,8 +83,9 @@ def driverobj(config, cycle):
# Tests


def test_ChgresCube():
for method in [
@mark.parametrize(
"method",
[
"_driver_config",
"_resources",
"_run_via_batch_submission",
Expand All @@ -97,8 +98,10 @@ def test_ChgresCube():
"_validate",
"_write_runscript",
"run",
]:
assert getattr(ChgresCube, method) is getattr(Driver, method)
],
)
def test_ChgresCube(method):
assert getattr(ChgresCube, method) is getattr(Driver, method)


def test_ChgresCube_namelist_file(caplog, driverobj):
Expand Down
11 changes: 7 additions & 4 deletions src/uwtools/tests/drivers/test_fv3.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ def true():
# Tests


def test_FV3():
for method in [
@mark.parametrize(
"method",
[
"_driver_config",
"_resources",
"_run_via_batch_submission",
Expand All @@ -95,8 +96,10 @@ def test_FV3():
"_validate",
"_write_runscript",
"run",
]:
assert getattr(FV3, method) is getattr(Driver, method)
],
)
def test_FV3(method):
assert getattr(FV3, method) is getattr(Driver, method)


def test_FV3_boundary_files(driverobj):
Expand Down
13 changes: 8 additions & 5 deletions src/uwtools/tests/drivers/test_global_equiv_resol.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from unittest.mock import DEFAULT as D
from unittest.mock import patch

from pytest import fixture
from pytest import fixture, mark

from uwtools.drivers.driver import Driver
from uwtools.drivers.global_equiv_resol import GlobalEquivResol
Expand Down Expand Up @@ -43,8 +43,9 @@ def driverobj(config):
# Tests


def test_GlobalEquivResol():
for method in [
@mark.parametrize(
"method",
[
"_driver_config",
"_resources",
"_run_via_batch_submission",
Expand All @@ -58,8 +59,10 @@ def test_GlobalEquivResol():
"_write_runscript",
"run",
"runscript",
]:
assert getattr(GlobalEquivResol, method) is getattr(Driver, method)
],
)
def test_GlobalEquivResol(method):
assert getattr(GlobalEquivResol, method) is getattr(Driver, method)


def test_GlobalEquivResol_input_file(driverobj):
Expand Down
13 changes: 8 additions & 5 deletions src/uwtools/tests/drivers/test_jedi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import yaml
from iotaa import asset, external
from pytest import fixture
from pytest import fixture, mark

from uwtools.config.formats.yaml import YAMLConfig
from uwtools.drivers import jedi, jedi_base
Expand Down Expand Up @@ -77,8 +77,9 @@ def driverobj(config, cycle):
# Tests


def test_JEDI():
for method in [
@mark.parametrize(
"method",
[
"_driver_config",
"_resources",
"_run_via_batch_submission",
Expand All @@ -91,8 +92,10 @@ def test_JEDI():
"_write_runscript",
"run",
"runscript",
]:
assert getattr(JEDI, method) is getattr(JEDIBase, method)
],
)
def test_JEDI(method):
assert getattr(JEDI, method) is getattr(JEDIBase, method)


def test_JEDI_configuration_file(driverobj):
Expand Down
13 changes: 8 additions & 5 deletions src/uwtools/tests/drivers/test_make_solo_mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
from unittest.mock import patch

from pytest import fixture
from pytest import fixture, mark

from uwtools.drivers.driver import Driver
from uwtools.drivers.make_solo_mosaic import MakeSoloMosaic
Expand Down Expand Up @@ -44,8 +44,9 @@ def driverobj(config):
# Tests


def test_MakeSoloMosaic():
for method in [
@mark.parametrize(
"method",
[
"_driver_config",
"_resources",
"_run_via_batch_submission",
Expand All @@ -58,8 +59,10 @@ def test_MakeSoloMosaic():
"_write_runscript",
"run",
"runscript",
]:
assert getattr(MakeSoloMosaic, method) is getattr(Driver, method)
],
)
def test_MakeSoloMosaic(method):
assert getattr(MakeSoloMosaic, method) is getattr(Driver, method)


def test_MakeSoloMosaic_provisioned_run_directory(driverobj):
Expand Down
16 changes: 9 additions & 7 deletions src/uwtools/tests/drivers/test_mpas.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ def driverobj(config, cycle):
# Tests


def test_MPAS():
for method in [
@mark.parametrize(
"method",
[
"_driver_config",
"_resources",
"_run_via_batch_submission",
Expand All @@ -134,8 +135,10 @@ def test_MPAS():
"run",
"runscript",
"streams_file",
]:
assert getattr(MPAS, method) is getattr(MPASBase, method)
],
)
def test_MPAS(method):
assert getattr(MPAS, method) is getattr(MPASBase, method)


def test_MPAS_boundary_files(driverobj, cycle):
Expand All @@ -148,9 +151,8 @@ def test_MPAS_boundary_files(driverobj, cycle):
infile_path = Path(driverobj._driver_config["lateral_boundary_conditions"]["path"])
infile_path.mkdir()
for n in ns:
(
infile_path / f"lbc.{(cycle+dt.timedelta(hours=n)).strftime('%Y-%m-%d_%H.%M.%S')}.nc"
).touch()
path = infile_path / f"lbc.{(cycle+dt.timedelta(hours=n)).strftime('%Y-%m-%d_%H.%M.%S')}.nc"
path.touch()
driverobj.boundary_files()
assert all(link.is_symlink() for link in links)

Expand Down
11 changes: 7 additions & 4 deletions src/uwtools/tests/drivers/test_mpas_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ def driverobj(config, cycle):
# Tests


def test_MPASInit():
for method in [
@mark.parametrize(
"method",
[
"_driver_config",
"_resources",
"_run_via_batch_submission",
Expand All @@ -116,8 +117,10 @@ def test_MPASInit():
"run",
"runscript",
"streams_file",
]:
assert getattr(MPASInit, method) is getattr(MPASBase, method)
],
)
def test_MPASInit(method):
assert getattr(MPASInit, method) is getattr(MPASBase, method)


def test_MPASInit_boundary_files(cycle, driverobj):
Expand Down
13 changes: 8 additions & 5 deletions src/uwtools/tests/drivers/test_orog_gsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from unittest.mock import DEFAULT as D
from unittest.mock import patch

from pytest import fixture
from pytest import fixture, mark

from uwtools.drivers.driver import Driver
from uwtools.drivers.orog_gsl import OrogGSL
Expand Down Expand Up @@ -51,8 +51,9 @@ def driverobj(config):
# Tests


def test_OrogGSL():
for method in [
@mark.parametrize(
"method",
[
"_driver_config",
"_resources",
"_run_via_batch_submission",
Expand All @@ -66,8 +67,10 @@ def test_OrogGSL():
"_write_runscript",
"run",
"runscript",
]:
assert getattr(OrogGSL, method) is getattr(Driver, method)
],
)
def test_OrogGSL(method):
assert getattr(OrogGSL, method) is getattr(Driver, method)


def test_OrogGSL_input_grid_file(driverobj):
Expand Down
13 changes: 8 additions & 5 deletions src/uwtools/tests/drivers/test_ungrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from unittest.mock import patch

import f90nml # type: ignore
from pytest import fixture
from pytest import fixture, mark

from uwtools.drivers import ungrib
from uwtools.drivers.driver import Driver
Expand Down Expand Up @@ -56,8 +56,9 @@ def driverobj(config, cycle):
# Tests


def test_Ungrib():
for method in [
@mark.parametrize(
"method",
[
"_driver_config",
"_resources",
"_run_via_batch_submission",
Expand All @@ -71,8 +72,10 @@ def test_Ungrib():
"_write_runscript",
"run",
"runscript",
]:
assert getattr(Ungrib, method) is getattr(Driver, method)
],
)
def test_Ungrib(method):
assert getattr(Ungrib, method) is getattr(Driver, method)


def test_Ungrib_gribfiles(driverobj, tmp_path):
Expand Down
13 changes: 8 additions & 5 deletions src/uwtools/tests/utils/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pathlib import Path
from unittest.mock import patch

from pytest import fixture, raises
from pytest import fixture, mark, raises

from uwtools.exceptions import UWError
from uwtools.utils import file
Expand Down Expand Up @@ -58,8 +58,9 @@ def test__stdinproxy():
assert file._stdinproxy().read() == msg1 # <-- the NEW message


def test_get_file_format():
for ext, file_type in {
@mark.parametrize(
"ext,file_type",
{
"atparse": "atparse",
"bash": "sh",
"cfg": "ini",
Expand All @@ -70,8 +71,10 @@ def test_get_file_format():
"sh": "sh",
"yaml": "yaml",
"yml": "yaml",
}.items():
assert file.get_file_format(Path(f"a.{ext}")) == file_type
}.items(),
)
def test_get_file_format(ext, file_type):
assert file.get_file_format(Path(f"a.{ext}")) == file_type


def test_get_file_format_unrecognized():
Expand Down

0 comments on commit e015477

Please sign in to comment.