Skip to content

Commit 14ccd76

Browse files
Fix #7980: Add detailed error messages with installation suggestions for image writers, cleanup tests
1 parent 7cc1fee commit 14ccd76

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

test_env.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1-
import torch, monai
1+
"""
2+
Manual environment check for versions of PyTorch and MONAI.
3+
4+
This script helps verify the runtime versions of key libraries during manual testing
5+
of writer error messages or environment troubleshooting.
6+
7+
Note:
8+
- This is intended for manual execution only.
9+
- Consider moving to a diagnostics folder or integrating into automated tests.
10+
"""
11+
12+
import torch
13+
import monai
14+
215
print("Torch version:", torch.__version__)
316
print("MONAI version:", monai.__version__)

test_writer_error.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
from monai.data.image_writer import resolve_writer, OptionalImportError, SUPPORTED_WRITERS, EXT_WILDCARD, ITKWriter
22

3+
# Fake extension to simulate unsupported file type
34
ext = "fakeext"
45

56
print(f"Before clearing fallback writers: {SUPPORTED_WRITERS.get(EXT_WILDCARD)}")
67

7-
# Temporarily clear fallback writers to simulate no support
8+
# Temporarily clear fallback writers to simulate no support scenario
89
SUPPORTED_WRITERS[EXT_WILDCARD] = ()
910

1011
try:
12+
# Try resolving writer for fake unsupported extension with error flag
1113
writers = resolve_writer(ext, error_if_not_found=True)
1214
except OptionalImportError as e:
15+
# Catch and print the enhanced OptionalImportError with package hints
1316
print("Caught OptionalImportError:", e)
1417
finally:
15-
# Restore the fallback writers to avoid side effects
18+
# Restore the fallback writers to avoid side effects on other tests
1619
SUPPORTED_WRITERS[EXT_WILDCARD] = (ITKWriter,)
1720

1821
print(f"After restoring fallback writers: {SUPPORTED_WRITERS.get(EXT_WILDCARD)}")

0 commit comments

Comments
 (0)