Skip to content

Commit 606e7ca

Browse files
committed
addressed bugs and issues raised in previous commit
Signed-off-by: Enoch Mok <enochmokny@gmail.com>
1 parent 29ec2fe commit 606e7ca

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

tests/apps/test_download_and_extract.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ def test_actions(self):
4242
with self.assertLogs(logger="monai.apps", level="ERROR"):
4343
try:
4444
download_url(url, filepath, wrong_md5)
45-
except (ContentTooShortError, HTTPError, RuntimeError) as e:
46-
if isinstance(e, RuntimeError):
45+
except (ContentTooShortError, HTTPError, ValueError, RuntimeError) as e:
46+
if isinstance(e, ValueError):
4747
# FIXME: skip MD5 check as current downloading method may fail
48-
self.assertTrue(str(e).startswith("md5 check"))
48+
self.assertIn("hash check", str(e))
4949
return # skipping this test due the network connection errors
5050

5151
try:

tests/test_utils.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,8 @@ class TestDownloadUrl(unittest.TestCase):
198198
"""Exercise ``download_url`` success and hash-mismatch paths."""
199199

200200
def test_download_url(self):
201-
"""Download a sample TIFF and validate hash handling.
202-
203-
Raises:
204-
ValueError: When the downloaded file's hash does not match.
201+
"""
202+
Download a sample TIFF and validate hash handling.
205203
"""
206204
with tempfile.TemporaryDirectory() as tempdir:
207205
model_path = os.path.join(tempdir, "model.tiff")
@@ -210,9 +208,13 @@ def test_download_url(self):
210208
download_url(
211209
url=SAMPLE_TIFF, filepath=model_path, hash_val=SAMPLE_TIFF_HASH, hash_type=SAMPLE_TIFF_HASH_TYPE
212210
)
211+
212+
# Verify file exists before testing hash mismatch
213+
if not os.path.exists(model_path):
214+
self.skipTest("File was not downloaded successfully")
215+
213216
with self.assertRaises(ValueError):
214-
# checking for wrong hash
215-
download_url(filepath=model_path, hash_val="0" * 64, hash_type=SAMPLE_TIFF_HASH_TYPE)
217+
download_url(url=SAMPLE_TIFF, filepath=model_path, hash_val="0" * 64, hash_type=SAMPLE_TIFF_HASH_TYPE)
216218

217219

218220
def test_pretrained_networks(network, input_param, device):

0 commit comments

Comments
 (0)