Skip to content

Commit 19ce7f6

Browse files
authored
Merge branch 'dev' into 8832-hashvalueerror
2 parents 606e7ca + 7f6b7e5 commit 19ce7f6

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/test_utils.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,37 @@ def test_download_url(self):
217217
download_url(url=SAMPLE_TIFF, filepath=model_path, hash_val="0" * 64, hash_type=SAMPLE_TIFF_HASH_TYPE)
218218

219219

220+
SAMPLE_TIFF = "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/CMU-1.tiff"
221+
SAMPLE_TIFF_HASH = "73a7e89bc15576587c3d68e55d9bf92f09690280166240b48ff4b48230b13bcd"
222+
SAMPLE_TIFF_HASH_TYPE = "sha256"
223+
224+
225+
class TestDownloadUrl(unittest.TestCase):
226+
"""Exercise ``download_url`` success and hash-mismatch paths."""
227+
228+
def test_download_url(self):
229+
"""Download a sample TIFF and validate hash handling.
230+
231+
Raises:
232+
RuntimeError: When the downloaded file's hash does not match.
233+
"""
234+
with tempfile.TemporaryDirectory() as tempdir:
235+
with skip_if_downloading_fails():
236+
download_url(
237+
url=SAMPLE_TIFF,
238+
filepath=os.path.join(tempdir, "model.tiff"),
239+
hash_val=SAMPLE_TIFF_HASH,
240+
hash_type=SAMPLE_TIFF_HASH_TYPE,
241+
)
242+
with self.assertRaises(RuntimeError):
243+
download_url(
244+
url=SAMPLE_TIFF,
245+
filepath=os.path.join(tempdir, "model_bad.tiff"),
246+
hash_val="0" * 64,
247+
hash_type=SAMPLE_TIFF_HASH_TYPE,
248+
)
249+
250+
220251
def test_pretrained_networks(network, input_param, device):
221252
with skip_if_downloading_fails():
222253
return network(**input_param).to(device)

0 commit comments

Comments
 (0)