diff --git a/tests/package/base.py b/tests/package/base.py index dd9b940e5..6d8563956 100644 --- a/tests/package/base.py +++ b/tests/package/base.py @@ -1,5 +1,6 @@ """Test import of subpackages with base cyclops install.""" +import numpy as np import pytest @@ -21,3 +22,27 @@ def test_import_cyclops(): import cyclops.monitor with pytest.raises(ImportError): import cyclops.report + + +def test_medical_image_feature_without_monai(): + """Test that the MedicalImage feature raises an error without MONAI installed.""" + from cyclops.data.features.medical_image import MedicalImage + + feat = MedicalImage() + # create a dummy image + img = np.random.rand(10, 10, 10) + + # test encode_example + with pytest.raises( + RuntimeError, + match="The MONAI library is required to use the `MedicalImage` feature.*", + ): + feat.encode_example(img) + + # test decode_example + dummy_val = {"path": "/dummy/local/path", "bytes": None} + with pytest.raises( + RuntimeError, + match="The MONAI library is required to use the `MedicalImage` feature.*", + ): + feat.decode_example(dummy_val)