Skip to content

Commit

Permalink
Merge pull request #83 from ZviBaratz/fix
Browse files Browse the repository at this point in the history
Missing ImageType fix
  • Loading branch information
ZviBaratz committed Nov 9, 2021
2 parents 759619e + 23e6bf2 commit 14ee36f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/dicom_parser/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ def is_mosaic(self) -> bool:
bool
Whether the image is a mosaic encoded volume
"""
return "MOSAIC" in self.header.get("ImageType")
return "MOSAIC" in self.header.get("ImageType", "")

@property
def is_multi_frame(self) -> bool:
Expand Down
13 changes: 12 additions & 1 deletion tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
class ImageTestCase(TestCase):
@classmethod
def setUpClass(cls):
cls.image = Image(TEST_IMAGE_PATH)
cls.rsfmri_image = Image(TEST_RSFMRI_IMAGE_PATH)
cls.siemens_dwi = Image(TEST_SIEMENS_DWI_PATH)
cls.multi_frame = Image(TEST_MULTIFRAME)

def setUp(self):
self.image = Image(TEST_IMAGE_PATH)

def test_initialization_with_string_path(self):
image = Image(TEST_IMAGE_PATH)
self.assertIsInstance(image, Image)
Expand Down Expand Up @@ -246,3 +248,12 @@ def test_multiframe_property_with_non_multi_frame(self):
self.assertIsNone(self.image.multi_frame)
self.assertIsNone(self.rsfmri_image.multi_frame)
self.assertIsNone(self.siemens_dwi.multi_frame)

def test_data_returned_with_missing_image_type(self):
del self.image.header.raw["ImageType"]
try:
self.image.data
except Exception as e:
self.fail(
f"Exception raised retreiving data for an image with a missing ImageType header field: {e}" # noqa: E501
)

0 comments on commit 14ee36f

Please sign in to comment.