diff --git a/test_env.py b/test_env.py new file mode 100644 index 0000000000..a85b35fb69 --- /dev/null +++ b/test_env.py @@ -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__) diff --git a/test_writer_error.py b/test_writer_error.py new file mode 100644 index 0000000000..a3f413aeb1 --- /dev/null +++ b/test_writer_error.py @@ -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)}")