From fd4846b0e96cf6543c52426ebdc8aea7b6a8c6bd Mon Sep 17 00:00:00 2001 From: Huite Bootsma Date: Tue, 15 Oct 2024 10:34:42 +0200 Subject: [PATCH] Better test coverage for meshkernel utils --- tests/test_meshkernel_utils.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/test_meshkernel_utils.py b/tests/test_meshkernel_utils.py index 8dca2a350..50f23df23 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