Skip to content

Commit

Permalink
Better test coverage for meshkernel utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Huite committed Oct 15, 2024
1 parent 769c76b commit fd4846b
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions tests/test_meshkernel_utils.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
from enum import IntEnum
from unittest.mock import MagicMock

import pytest
import shapely.geometry as sg

from xugrid import meshkernel_utils as mku
from xugrid.constants import MissingOptionalModule

from . import requires_meshkernel

try:
import meshkernel as mk

except ImportError:
pass
mk = MagicMock()
mk.RefinementType = IntEnum(
"RefinementType", ["WAVE_COURANT", "REFINEMENT_LEVELS", "RIDGE_DETECTION"]
)


class Dummy(IntEnum):
A = 1
B = 2
C = 3


@requires_meshkernel
def test_either_string_or_enum():
assert (
mku.either_string_or_enum("wave_courant", mk.RefinementType)
Expand All @@ -28,7 +41,7 @@ def test_either_string_or_enum():
with pytest.raises(ValueError, match="Invalid option"):
mku.either_string_or_enum("none", mk.RefinementType)
with pytest.raises(TypeError, match="Option should be one of"):
mku.either_string_or_enum(mk.AveragingMethod.MAX, mk.RefinementType)
mku.either_string_or_enum(Dummy.A, mk.RefinementType)


@requires_meshkernel
Expand All @@ -42,3 +55,9 @@ def test_to_geometry_list():
)
actual = mku.to_geometry_list(polygon)
assert isinstance(actual, mk.GeometryList)


def test_missing_optional_module():
abc = MissingOptionalModule("abc")
with pytest.raises(ImportError, match="abc is required for this functionality"):
abc.attr

0 comments on commit fd4846b

Please sign in to comment.