Skip to content

Commit a5d9c93

Browse files
authored
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>
1 parent 99cd2d6 commit a5d9c93

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

tests/test_utils.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,32 @@ def skip_if_downloading_fails():
184184
raise rt_e
185185

186186

187+
SAMPLE_TIFF = (
188+
https://huggingface.co/datasets/MONAI/testing_data/resolve/main/CMU-1.tiff
189+
)
190+
191+
SAMPLE_TIFF_HASH = "73a7e89bc15576587c3d68e55d9bf92f09690280166240b48ff4b48230b13bcd"
192+
SAMPLE_TIFF_HASH_TYPE = "sha256"
193+
194+
def test_download_url():
195+
with tempfile.TemporaryDirectory() as tempdir:
196+
# successful download with correct hash
197+
download_url(
198+
url=SAMPLE_TIFF,
199+
filepath=os.path.join(tempdir, "model.tiff"),
200+
hash_val=SAMPLE_TIFF_HASH,
201+
hash_type=SAMPLE_TIFF_HASH_TYPE,
202+
)
203+
204+
# fails with wrong hash
205+
with self.assertRaises(RuntimeError):
206+
download_url(
207+
url=SAMPLE_TIFF,
208+
filepath=os.path.join(tempdir, "model_bad.tiff"),
209+
hash_val="wrong_hash",
210+
hash_type=SAMPLE_TIFF_HASH_TYPE,
211+
)
212+
187213
def test_pretrained_networks(network, input_param, device):
188214
with skip_if_downloading_fails():
189215
return network(**input_param).to(device)

0 commit comments

Comments
 (0)