Skip to content

Commit

Permalink
Merge branch 'test' of github.com:ESadek-MO/iris-esmf-regrid into test
Browse files Browse the repository at this point in the history
  • Loading branch information
ESadek-MO committed Nov 24, 2023
2 parents a020fb0 + 16b340e commit 10b241b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
18 changes: 14 additions & 4 deletions esmf_regrid/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@ class Method(Enum):

class NormType(Enum):
"""holds enums for norm types."""

FRACAREA = esmpy.api.constants.NormType.FRACAREA
DSTAREA = esmpy.api.constants.NormType.DSTAREA


method_dict = {
"conservative": Constants.Method.CONSERVATIVE,
"bilinear": Constants.Method.BILINEAR,
"nearest": Constants.Method.NEAREST}
"nearest": Constants.Method.NEAREST,
}

norm_dict = {
"fracarea": Constants.NormType.FRACAREA,
"dstarea": Constants.NormType.DSTAREA}
"dstarea": Constants.NormType.DSTAREA,
}


def check_method(method):
"""
Expand All @@ -39,9 +44,12 @@ def check_method(method):
elif method in method_dict.values():
result = method
else:
raise ValueError(f"Method must be a member of `Constants.Method` enum, instead got {method}")
raise ValueError(
f"Method must be a member of `Constants.Method` enum, instead got {method}"
)
return result


def check_norm(norm):
"""
Checks that normtype is a member of the `Constants.NormType` enum, else raises
Expand All @@ -52,5 +60,7 @@ def check_norm(norm):
elif norm in norm_dict.values():
result = norm
else:
raise ValueError(f"NormType must be a member of `Constants.NormType` enum, instead got {norm}")
raise ValueError(
f"NormType must be a member of `Constants.NormType` enum, instead got {norm}"
)
return result
10 changes: 6 additions & 4 deletions esmf_regrid/tests/unit/esmf_regridder/test_Constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

from esmf_regrid import check_method, check_norm, Constants


@pytest.mark.parametrize(
"method",
[
["conservative", Constants.Method.CONSERVATIVE],
["bilinear", Constants.Method.BILINEAR],
["nearest", Constants.Method.NEAREST]
]
["nearest", Constants.Method.NEAREST],
],
)
def test_check_method_validates(method):
"""Tests that `check_method()` converts strings to enum"""
Expand All @@ -27,12 +28,13 @@ def test_invalid_method():
with pytest.raises(AttributeError):
_ = check_method(Constants.Method.OTHER)


@pytest.mark.parametrize(
"norm",
[
["fracarea", Constants.NormType.FRACAREA],
["dstarea", Constants.NormType.DSTAREA]
]
["dstarea", Constants.NormType.DSTAREA],
],
)
def test_check_norm_validates(norm):
"""Tests that `check_norm()` converts strings to enum"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def test_flat_cubes():
expected_cube.data = result_transposed.data
assert expected_cube == result_transposed


@pytest.mark.parametrize("nsi", [0, 1])
@pytest.mark.parametrize(
"method", [Constants.Method.BILINEAR, Constants.Method.NEAREST]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def test_flat_cubes():
expected_cube.data = result.data
assert expected_cube == result


@pytest.mark.parametrize("nsi", [0, 1])
@pytest.mark.parametrize(
"method", [Constants.Method.BILINEAR, Constants.Method.NEAREST]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ def test_invalid_args():
tgt, tgt, method=Constants.Method.BILINEAR
)
with pytest.raises(ValueError):
_ = regrid_unstructured_to_rectilinear(
face_src, tgt, method="other"
)
_ = regrid_unstructured_to_rectilinear(face_src, tgt, method="other")
with pytest.raises(ValueError) as excinfo:
_ = regrid_unstructured_to_rectilinear(
node_src, tgt, method=Constants.Method.CONSERVATIVE
Expand Down

0 comments on commit 10b241b

Please sign in to comment.