Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions test_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Manual environment check for versions of PyTorch and MONAI.

This script helps verify the runtime versions of key libraries during manual testing
of writer error messages or environment troubleshooting.

Note:
- This is intended for manual execution only.
- Consider moving to a diagnostics folder or integrating into automated tests.
"""

import torch
import monai

print("Torch version:", torch.__version__)
print("MONAI version:", monai.__version__)
21 changes: 21 additions & 0 deletions test_writer_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from monai.data.image_writer import resolve_writer, OptionalImportError, SUPPORTED_WRITERS, EXT_WILDCARD, ITKWriter

# Fake extension to simulate unsupported file type
ext = "fakeext"

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

# Temporarily clear fallback writers to simulate no support scenario
SUPPORTED_WRITERS[EXT_WILDCARD] = ()

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

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