From 3037a66484fcdcbf8e123ab512fca12c15609618 Mon Sep 17 00:00:00 2001 From: enoch <65853622+e-mny@users.noreply.github.com> Date: Thu, 15 Jan 2026 10:23:02 +0800 Subject: [PATCH 1/7] Update URLs in data_config.json to Hugging Face Signed-off-by: enoch <65853622+e-mny@users.noreply.github.com> --- tests/testing_data/data_config.json | 80 ++++++++++++++--------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/tests/testing_data/data_config.json b/tests/testing_data/data_config.json index 79033dd0d6..234efe2f7f 100644 --- a/tests/testing_data/data_config.json +++ b/tests/testing_data/data_config.json @@ -1,87 +1,87 @@ { "images": { "wsi_generic_tiff": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/CMU-1.tiff", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/CMU-1.tiff", "hash_type": "sha256", "hash_val": "73a7e89bc15576587c3d68e55d9bf92f09690280166240b48ff4b48230b13bcd" }, "wsi_aperio_svs": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/Aperio-CMU-1.svs", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/Aperio-CMU-1.svs", "hash_type": "sha256", "hash_val": "00a3d54482cd707abf254fe69dccc8d06b8ff757a1663f1290c23418c480eb30" }, "favicon": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/favicon.ico.zip", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/favicon.ico.zip", "hash_type": "sha256", "hash_val": "3a3635c8d8adb81feebc5926b4106e8eb643a24a4be2a69a9d35f9a578acadb5" }, "icon": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/icon.tar.gz", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/icon.tar.gz", "hash_type": "sha256", "hash_val": "90f24cd8f20f3932624da95190ce384302261acf0ea15b358f7832e3b6becac0" }, "mednist": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/MedNIST.tar.gz", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/MedNIST.tar.gz", "hash_type": "sha256", "hash_val": "f2f4881ff8799a170b10a403495f0ce0ad7486491901cde67a647e6627e7f916" }, "Prostate_T2W_AX_1": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/Prostate_T2W_AX_1.nii", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/Prostate_T2W_AX_1.nii", "hash_type": "sha256", "hash_val": "a14231f539c0f365a5f83f2a046969a9b9870e56ffd126fd8e7242364d25938a" }, "0000_t2_tse_tra_4": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/ProstateX-0000_t2_tse_tra_4.nii.gz", - "hash_type": "md5", - "hash_val": "adb3f1c4db66a6481c3e4a2a3033c7d5" + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/ProstateX-0000_t2_tse_tra_4.nii.gz", + "hash_type": "sha256", + "hash_val": "79202b407a54c61d446777718415845c278c0e28b12a940466c16cd5faf3603a" }, "0000_ep2d_diff_tra_7": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/ProstateX-0000_ep2d_diff_tra_7.nii.gz", - "hash_type": "md5", - "hash_val": "f12a11ad0ebb0b1876e9e010564745d2" + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/ProstateX-0000_ep2d_diff_tra_7.nii.gz", + "hash_type": "sha256", + "hash_val": "a61b2994426dc4fc1cb5192d7aee287446d3c4a57ee8802732fffb74e48bba0c" }, "ref_avg152T1_LR": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/avg152T1_LR_nifti.nii.gz", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/avg152T1_LR_nifti.nii.gz", "hash_type": "sha256", "hash_val": "c01a50caa7a563158ecda43d93a1466bfc8aa939bc16b06452ac1089c54661c8" }, "ref_avg152T1_RL": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/avg152T1_RL_nifti.nii.gz", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/avg152T1_RL_nifti.nii.gz", "hash_type": "sha256", "hash_val": "8a731128dac4de46ccb2cc60d972b98f75a52f21fb63ddb040ca96f0aed8b51a" }, "MNI152_T1_2mm": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/MNI152_T1_2mm.nii.gz", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/MNI152_T1_2mm.nii.gz", "hash_type": "sha256", "hash_val": "0585cd056bf5ccfb8bf97a5f6a66082d4e7caad525718fc11e40d80a827fcb92" }, "MNI152_T1_2mm_strucseg": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/MNI152_T1_2mm_strucseg.nii.gz", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/MNI152_T1_2mm_strucseg.nii.gz", "hash_type": "sha256", "hash_val": "eb4f1e596ca85aadaefc359d409fb9a3e27d733e6def04b996953b7c54bc26d4" }, "copd1_highres_INSP_STD_COPD_img": { - "url": "https://data.kitware.com/api/v1/file/62a0f067bddec9d0c4175c5a/download", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/copd1_highres_INSP_STD_COPD_img.nii.gz", "hash_type": "sha512", - "hash_val": "60193cd6ef0cf055c623046446b74f969a2be838444801bd32ad5bedc8a7eeecb343e8a1208769c9c7a711e101c806a3133eccdda7790c551a69a64b9b3701e9" + "hash_val": "9c10df5829d0ea682cd51d42b8646e2e9cbe89ce42582fb5aa819f3be6716ccf" }, "copd1_highres_EXP_STD_COPD_img": { - "url": "https://data.kitware.com/api/v1/item/62a0f045bddec9d0c4175c44/download", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/copd1_highres_EXP_STD_COPD_img.nii.gz", "hash_type": "sha512", - "hash_val": "841ef303958541474e66c2d1ccdc8b7ed17ba2f2681101307766b979a07979f2ec818ddf13791c3f1ac5a8ec3258d6ea45b692b4b4a838de9188602618972b6d" + "hash_val": "fb911fe9b5caa9f41750dfccd914f54dadf951f6d4f8b83d498e0480807f4903" }, "CT_2D_head_fixed": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/CT_2D_head_fixed.mha", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/CT_2D_head_fixed.mha", "hash_type": "sha256", "hash_val": "06f2ce6fbf6a59f0874c735555fcf71717f631156b1b0697c1752442f7fc1cc5" }, "CT_2D_head_moving": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/CT_2D_head_moving.mha", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/CT_2D_head_moving.mha", "hash_type": "sha256", "hash_val": "a37c5fe388c38b3f4ac564f456277d09d3982eda58c4da05ead8ee2332360f47" }, "DICOM_single": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/CT_DICOM_SINGLE.zip", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/CT_DICOM_SINGLE.zip", "hash_type": "sha256", "hash_val": "a41f6e93d2e3d68956144f9a847273041d36441da12377d6a1d5ae610e0a7023" }, @@ -93,69 +93,69 @@ }, "videos": { "endovis": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/d1_im.mp4", - "hash_type": "md5", - "hash_val": "9b103c07326439b0ea376018d7189384" + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/d1_im.mp4", + "hash_type": "sha256", + "hash_val": "e486b5e1651274a082e6d97081fba139a533ee7e4b684b424b21d582c019e159" }, "ultrasound": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/example_data_Ultrasound_Q000_04_tu_segmented_ultrasound_256.avi", - "hash_type": "md5", - "hash_val": "f0755960cc4a08a958561cda9a79a157" + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/example_data_Ultrasound_Q000_04_tu_segmented_ultrasound_256.avi", + "hash_type": "sha256", + "hash_val": "41a65c581ecff53c08f6bacc539daa3d7fbabefbf308a7e3c83e93a9453cc5c7" } }, "models": { "senet154-c7b49a05": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/senet154-c7b49a05.pth", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/senet154-c7b49a05.pth", "hash_type": "sha256", "hash_val": "c7b49a056b98b0bed65b0237c27acdead655e599669215573d357ad337460413" }, "se_resnet101-7e38fcc6": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/se_resnet101-7e38fcc6.pth", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/se_resnet101-7e38fcc6.pth", "hash_type": "sha256", "hash_val": "7e38fcc64eff3225a3ea4e6081efeb6087e8d5a61c204d94edc2ed1aab0b9d70" }, "se_resnet152-d17c99b7": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/se_resnet152-d17c99b7.pth", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/se_resnet152-d17c99b7.pth", "hash_type": "sha256", "hash_val": "d17c99b703dcca2d2507ddfb68f72625a2f7e23ee64396eb992f1b2cf7e6bdc1" }, "se_resnet50-ce0d4300": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/se_resnet50-ce0d4300.pth", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/se_resnet50-ce0d4300.pth", "hash_type": "sha256", "hash_val": "ce0d430017d3f4aa6b5658c72209f3bfffb060207fd26a2ef0b203ce592eba01" }, "se_resnext101_32x4d-3b2fe3d8": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/se_resnext101_32x4d-3b2fe3d8.pth", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/se_resnext101_32x4d-3b2fe3d8.pth", "hash_type": "sha256", "hash_val": "3b2fe3d8acb8de7d5976c4baf518f24a0237509272a69366e816682d3e57b989" }, "se_resnext50_32x4d-a260b3a4": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/se_resnext50_32x4d-a260b3a4.pth", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/se_resnext50_32x4d-a260b3a4.pth", "hash_type": "sha256", "hash_val": "a260b3a40f82dfe37c58d26a612bcf7bef0d27c6fed096226b0e4e9fb364168e" }, "ssl_pretrained_weights": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/ssl_pretrained_weights.pth", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/ssl_pretrained_weights.pth", "hash_type": "sha256", "hash_val": "c3564f40a6a051d3753a6d8fae5cc8eaf21ce8d82a9a3baf80748d15664055e8" }, "decoder_only_transformer_monai_generative_weights": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/decoder_only_transformer.pth", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/decoder_only_transformer.pth", "hash_type": "sha256", "hash_val": "f93de37d64d77cf91f3bde95cdf93d161aee800074c89a92aff9d5699120ec0d" }, "diffusion_model_unet_monai_generative_weights": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/diffusion_model_unet.pth", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/diffusion_model_unet.pth", "hash_type": "sha256", "hash_val": "0d2171b386902f5b4fd3e967b4024f63e353694ca45091b114970019d045beee" }, "autoencoderkl_monai_generative_weights": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/autoencoderkl.pth", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/autoencoderkl.pth", "hash_type": "sha256", "hash_val": "6e02c9540c51b16b9ba98b5c0c75d6b84b430afe9a3237df1d67a520f8d34184" }, "controlnet_monai_generative_weights": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/controlnet.pth", + "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/controlnet.pth", "hash_type": "sha256", "hash_val": "cd100d0c69f47569ae5b4b7df653a1cb19f5e02eff1630db3210e2646fb1ab2e" } From ae4b9616880e3a34347d03e3dbdb82741c17c668 Mon Sep 17 00:00:00 2001 From: Enoch Mok <65853622+e-mny@users.noreply.github.com> Date: Thu, 15 Jan 2026 10:32:16 +0800 Subject: [PATCH 2/7] Update data_config.json with correct hash_types Signed-off-by: Enoch Mok <65853622+e-mny@users.noreply.github.com> --- tests/testing_data/data_config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testing_data/data_config.json b/tests/testing_data/data_config.json index 234efe2f7f..495892d1bd 100644 --- a/tests/testing_data/data_config.json +++ b/tests/testing_data/data_config.json @@ -62,12 +62,12 @@ }, "copd1_highres_INSP_STD_COPD_img": { "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/copd1_highres_INSP_STD_COPD_img.nii.gz", - "hash_type": "sha512", + "hash_type": "sha256", "hash_val": "9c10df5829d0ea682cd51d42b8646e2e9cbe89ce42582fb5aa819f3be6716ccf" }, "copd1_highres_EXP_STD_COPD_img": { "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/copd1_highres_EXP_STD_COPD_img.nii.gz", - "hash_type": "sha512", + "hash_type": "sha256", "hash_val": "fb911fe9b5caa9f41750dfccd914f54dadf951f6d4f8b83d498e0480807f4903" }, "CT_2D_head_fixed": { From 99cd2d6ee521639bd1defa82bfddf2a8d6dea2fc Mon Sep 17 00:00:00 2001 From: Enoch Mok <65853622+e-mny@users.noreply.github.com> Date: Fri, 17 Apr 2026 09:36:05 +0800 Subject: [PATCH 3/7] Change hash types from sha256 to md5 and sha512 Updated hash types and values for various datasets in data_config.json. Signed-off-by: Enoch Mok <65853622+e-mny@users.noreply.github.com> --- tests/testing_data/data_config.json | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/testing_data/data_config.json b/tests/testing_data/data_config.json index 495892d1bd..a6f4e90940 100644 --- a/tests/testing_data/data_config.json +++ b/tests/testing_data/data_config.json @@ -32,13 +32,13 @@ }, "0000_t2_tse_tra_4": { "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/ProstateX-0000_t2_tse_tra_4.nii.gz", - "hash_type": "sha256", - "hash_val": "79202b407a54c61d446777718415845c278c0e28b12a940466c16cd5faf3603a" + "hash_type": "md5", + "hash_val": "adb3f1c4db66a6481c3e4a2a3033c7d5" }, "0000_ep2d_diff_tra_7": { "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/ProstateX-0000_ep2d_diff_tra_7.nii.gz", - "hash_type": "sha256", - "hash_val": "a61b2994426dc4fc1cb5192d7aee287446d3c4a57ee8802732fffb74e48bba0c" + "hash_type": "md5", + "hash_val": "f12a11ad0ebb0b1876e9e010564745d2" }, "ref_avg152T1_LR": { "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/avg152T1_LR_nifti.nii.gz", @@ -62,13 +62,13 @@ }, "copd1_highres_INSP_STD_COPD_img": { "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/copd1_highres_INSP_STD_COPD_img.nii.gz", - "hash_type": "sha256", - "hash_val": "9c10df5829d0ea682cd51d42b8646e2e9cbe89ce42582fb5aa819f3be6716ccf" + "hash_type": "sha512", + "hash_val": "60193cd6ef0cf055c623046446b74f969a2be838444801bd32ad5bedc8a7eeecb343e8a1208769c9c7a711e101c806a3133eccdda7790c551a69a64b9b3701e9" }, "copd1_highres_EXP_STD_COPD_img": { "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/copd1_highres_EXP_STD_COPD_img.nii.gz", - "hash_type": "sha256", - "hash_val": "fb911fe9b5caa9f41750dfccd914f54dadf951f6d4f8b83d498e0480807f4903" + "hash_type": "sha512", + "hash_val": "841ef303958541474e66c2d1ccdc8b7ed17ba2f2681101307766b979a07979f2ec818ddf13791c3f1ac5a8ec3258d6ea45b692b4b4a838de9188602618972b6d" }, "CT_2D_head_fixed": { "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/CT_2D_head_fixed.mha", @@ -94,13 +94,13 @@ "videos": { "endovis": { "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/d1_im.mp4", - "hash_type": "sha256", - "hash_val": "e486b5e1651274a082e6d97081fba139a533ee7e4b684b424b21d582c019e159" + "hash_type": "md5", + "hash_val": "9b103c07326439b0ea376018d7189384" }, "ultrasound": { "url": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/example_data_Ultrasound_Q000_04_tu_segmented_ultrasound_256.avi", - "hash_type": "sha256", - "hash_val": "41a65c581ecff53c08f6bacc539daa3d7fbabefbf308a7e3c83e93a9453cc5c7" + "hash_type": "md5", + "hash_val": "f0755960cc4a08a958561cda9a79a157" } }, "models": { From a5d9c9321b870ef76b2692c6aca21f8a145a63ef Mon Sep 17 00:00:00 2001 From: Enoch Mok <65853622+e-mny@users.noreply.github.com> Date: Fri, 17 Apr 2026 11:31:14 +0800 Subject: [PATCH 4/7] Implement download_url tests for SAMPLE_TIFF Add tests for downloading a sample TIFF file with hash validation. Signed-off-by: Enoch Mok <65853622+e-mny@users.noreply.github.com> --- tests/test_utils.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index e365237401..77bdcf9938 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -184,6 +184,32 @@ def skip_if_downloading_fails(): raise rt_e +SAMPLE_TIFF = ( + https://huggingface.co/datasets/MONAI/testing_data/resolve/main/CMU-1.tiff +) + +SAMPLE_TIFF_HASH = "73a7e89bc15576587c3d68e55d9bf92f09690280166240b48ff4b48230b13bcd" +SAMPLE_TIFF_HASH_TYPE = "sha256" + +def test_download_url(): + with tempfile.TemporaryDirectory() as tempdir: + # successful download with correct hash + download_url( + url=SAMPLE_TIFF, + filepath=os.path.join(tempdir, "model.tiff"), + hash_val=SAMPLE_TIFF_HASH, + hash_type=SAMPLE_TIFF_HASH_TYPE, + ) + + # fails with wrong hash + with self.assertRaises(RuntimeError): + download_url( + url=SAMPLE_TIFF, + filepath=os.path.join(tempdir, "model_bad.tiff"), + hash_val="wrong_hash", + hash_type=SAMPLE_TIFF_HASH_TYPE, + ) + def test_pretrained_networks(network, input_param, device): with skip_if_downloading_fails(): return network(**input_param).to(device) From 1af22aa2afb51cf5680290b9ec0c536a7da95482 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 17 Apr 2026 03:32:09 +0000 Subject: [PATCH 5/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 77bdcf9938..d0635819e9 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -200,7 +200,7 @@ def test_download_url(): hash_val=SAMPLE_TIFF_HASH, hash_type=SAMPLE_TIFF_HASH_TYPE, ) - + # fails with wrong hash with self.assertRaises(RuntimeError): download_url( From 0d1890d2bdab1346cb04c2e55a4848b62a3388a3 Mon Sep 17 00:00:00 2001 From: Enoch Mok <65853622+e-mny@users.noreply.github.com> Date: Fri, 17 Apr 2026 11:37:37 +0800 Subject: [PATCH 6/7] Fix assertion method in test_utils.py Signed-off-by: Enoch Mok <65853622+e-mny@users.noreply.github.com> --- tests/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index d0635819e9..bd330367f8 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -202,7 +202,7 @@ def test_download_url(): ) # fails with wrong hash - with self.assertRaises(RuntimeError): + with unittest.assertRaises(RuntimeError): download_url( url=SAMPLE_TIFF, filepath=os.path.join(tempdir, "model_bad.tiff"), From db6b130de8654a4d6b5ac58cfe8e701627c6b6f1 Mon Sep 17 00:00:00 2001 From: Enoch Mok <65853622+e-mny@users.noreply.github.com> Date: Fri, 17 Apr 2026 11:40:19 +0800 Subject: [PATCH 7/7] Refactor download_url test into TestDownloadUrl class Refactor test for download_url to use a class-based structure and improve hash validation. Signed-off-by: Enoch Mok <65853622+e-mny@users.noreply.github.com> --- tests/test_utils.py | 47 ++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index bd330367f8..026fcfc157 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -183,32 +183,35 @@ def skip_if_downloading_fails(): raise rt_e - -SAMPLE_TIFF = ( - https://huggingface.co/datasets/MONAI/testing_data/resolve/main/CMU-1.tiff -) - +SAMPLE_TIFF = "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/CMU-1.tiff" SAMPLE_TIFF_HASH = "73a7e89bc15576587c3d68e55d9bf92f09690280166240b48ff4b48230b13bcd" SAMPLE_TIFF_HASH_TYPE = "sha256" -def test_download_url(): - with tempfile.TemporaryDirectory() as tempdir: - # successful download with correct hash - download_url( - url=SAMPLE_TIFF, - filepath=os.path.join(tempdir, "model.tiff"), - hash_val=SAMPLE_TIFF_HASH, - hash_type=SAMPLE_TIFF_HASH_TYPE, - ) - # fails with wrong hash - with unittest.assertRaises(RuntimeError): - download_url( - url=SAMPLE_TIFF, - filepath=os.path.join(tempdir, "model_bad.tiff"), - hash_val="wrong_hash", - hash_type=SAMPLE_TIFF_HASH_TYPE, - ) +class TestDownloadUrl(unittest.TestCase): + """Exercise ``download_url`` success and hash-mismatch paths.""" + + def test_download_url(self): + """Download a sample TIFF and validate hash handling. + + Raises: + RuntimeError: When the downloaded file's hash does not match. + """ + with tempfile.TemporaryDirectory() as tempdir: + with skip_if_downloading_fails(): + download_url( + url=SAMPLE_TIFF, + filepath=os.path.join(tempdir, "model.tiff"), + hash_val=SAMPLE_TIFF_HASH, + hash_type=SAMPLE_TIFF_HASH_TYPE, + ) + with self.assertRaises(RuntimeError): + download_url( + url=SAMPLE_TIFF, + filepath=os.path.join(tempdir, "model_bad.tiff"), + hash_val="0" * 64, + hash_type=SAMPLE_TIFF_HASH_TYPE, + ) def test_pretrained_networks(network, input_param, device): with skip_if_downloading_fails():