-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Refactor download_url test into TestDownloadUrl class #8829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
d02da49
867287e
6296784
8a6b6f6
66af964
43f508b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,6 +184,37 @@ 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" | ||
|
|
||
|
|
||
| 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, | ||
| ) | ||
|
Comment on lines
+209
to
+215
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
- with self.assertRaises(RuntimeError):
+ with self.assertRaises(ValueError):
download_url(
url=SAMPLE_TIFF,
filepath=os.path.join(tempdir, "model_bad.tiff"),
hash_val="0" * 64,
hash_type=SAMPLE_TIFF_HASH_TYPE,
)Also worth wrapping network exceptions here so CI flakes don't masquerade as assertion failures — but per 🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| def test_pretrained_networks(network, input_param, device): | ||
| with skip_if_downloading_fails(): | ||
| return network(**input_param).to(device) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.