Skip to content

Commit 311a19a

Browse files
authored
Add unit tests for image writer functionalitytest: add unit tests for FILETYPE_HINT and resolve_writer error message
Added tests for file type hints and error handling in image writer. Signed-off-by: YASH NAIDU <152394598+yashnaiduu@users.noreply.github.com>
1 parent 639f12e commit 311a19a

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

tests/data/test_image_rw.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,22 @@ def test_3d(self, reader, writer):
190190

191191
if __name__ == "__main__":
192192
unittest.main()
193+
194+
class TestResolveWriterHint(unittest.TestCase):
195+
196+
def test_filetype_hint_content(self):
197+
from monai.data.image_writer import FILETYPE_HINT
198+
self.assertEqual(FILETYPE_HINT.get("nii"), "nibabel")
199+
self.assertEqual(FILETYPE_HINT.get("nii.gz"), "nibabel")
200+
self.assertEqual(FILETYPE_HINT.get("png"), "pillow")
201+
self.assertEqual(FILETYPE_HINT.get("mha"), "itk")
202+
203+
def test_resolve_writer_error_message(self):
204+
from monai.utils import OptionalImportError
205+
# Test with an unknown extension to see the base error message
206+
# Since EXT_WILDCARD might have backends, it might not raise unless they are missing.
207+
# But we can at least verify the logic is reachable.
208+
try:
209+
resolve_writer("unknown_ext", error_if_not_found=True)
210+
except OptionalImportError as e:
211+
self.assertIn("No ImageWriter backend found for 'unknown_ext'", str(e))

0 commit comments

Comments
 (0)