diff --git a/tests/test_meshkernel_utils.py b/tests/test_meshkernel_utils.py index 8dca2a35..50f23df2 100644 --- a/tests/test_meshkernel_utils.py +++ b/tests/test_meshkernel_utils.py @@ -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) @@ -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 @@ -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