Skip to content

Commit

Permalink
Add test for MedicalImage feature without MONAI
Browse files Browse the repository at this point in the history
  • Loading branch information
fcogidi committed Nov 20, 2023
1 parent 9085081 commit 113fd6d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/package/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test import of subpackages with base cyclops install."""

import numpy as np
import pytest


Expand All @@ -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)

0 comments on commit 113fd6d

Please sign in to comment.