Refactor download_url test into TestDownloadUrl class#8829
Refactor download_url test into TestDownloadUrl class#8829e-mny wants to merge 3 commits intoProject-MONAI:devfrom
Conversation
for more information, see https://pre-commit.ci
📝 WalkthroughWalkthroughThis PR adds a new test class Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/testing_data/data_config.json (1)
88-92:⚠️ Potential issue | 🟡 MinorTwo URLs were missed in the HF migration.
images.nrrd_example(line 89) andconfigs.test_meta_file(line 165) still point atgithub.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/.... Per the PR objective (issue#8510), all test data URLs should move to the HF dataset. Please migrate these too (or note why they're exempt).#!/bin/bash # Confirm remaining GitHub Releases URLs in the config. rg -n 'MONAI-extra-test-data' tests/testing_data/data_config.jsonAlso applies to: 163-168
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/testing_data/data_config.json` around lines 88 - 92, The two remaining test-data entries images.nrrd_example and configs.test_meta_file still point to the old GitHub release; update their "url" fields to the corresponding HuggingFace dataset URLs used by the rest of the config (replace the github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/... links with the HF dataset path), and if the file content or location changed on HF, update the "hash_val" (keeping "hash_type": "sha256") to the new checksum; after changing images.nrrd_example and configs.test_meta_file in data_config.json, run the repo search used in the PR verification (e.g., rg -n 'MONAI-extra-test-data' tests/testing_data/data_config.json) to ensure no remaining GitHub-release links remain.
🧹 Nitpick comments (1)
tests/test_utils.py (1)
195-215: Consider sourcing URL/hash fromtesting_data_configinstead of hard-coding.
wsi_generic_tiffindata_config.jsonalready holds the same URL/hash_type/hash_val. Usingtesting_data_config("images", "wsi_generic_tiff", ...)would avoid duplication and keep the test in sync if the config is ever updated.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/test_utils.py` around lines 195 - 215, The test_download_url test currently hard-codes SAMPLE_TIFF, SAMPLE_TIFF_HASH and SAMPLE_TIFF_HASH_TYPE; replace those with values loaded from the shared test config by calling testing_data_config("images", "wsi_generic_tiff", "url"), testing_data_config("images", "wsi_generic_tiff", "hash_val") and testing_data_config("images", "wsi_generic_tiff", "hash_type") (or destructure a single call if helper returns all fields) and pass those into download_url instead of the constants; update imports in tests/test_utils.py to include testing_data_config and keep the existing download_url usage and assertions unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/test_utils.py`:
- Around line 209-215: Replace the second transient download with a
deterministic hash-mismatch check: first download SAMPLE_TIFF once (guarded by
skip_if_downloading_fails()) into a temp filepath (e.g., model.tiff) using
download_url, then call download_url again with the same filepath but with the
incorrect hash_val to trigger the hash-validation branch and
assertRaises(RuntimeError); this avoids re-downloading to model_bad.tiff and
eliminates network flakiness—use the symbols download_url,
skip_if_downloading_fails, SAMPLE_TIFF, and SAMPLE_TIFF_HASH_TYPE to locate and
modify the test.
---
Outside diff comments:
In `@tests/testing_data/data_config.json`:
- Around line 88-92: The two remaining test-data entries images.nrrd_example and
configs.test_meta_file still point to the old GitHub release; update their "url"
fields to the corresponding HuggingFace dataset URLs used by the rest of the
config (replace the
github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/... links
with the HF dataset path), and if the file content or location changed on HF,
update the "hash_val" (keeping "hash_type": "sha256") to the new checksum; after
changing images.nrrd_example and configs.test_meta_file in data_config.json, run
the repo search used in the PR verification (e.g., rg -n 'MONAI-extra-test-data'
tests/testing_data/data_config.json) to ensure no remaining GitHub-release links
remain.
---
Nitpick comments:
In `@tests/test_utils.py`:
- Around line 195-215: The test_download_url test currently hard-codes
SAMPLE_TIFF, SAMPLE_TIFF_HASH and SAMPLE_TIFF_HASH_TYPE; replace those with
values loaded from the shared test config by calling
testing_data_config("images", "wsi_generic_tiff", "url"),
testing_data_config("images", "wsi_generic_tiff", "hash_val") and
testing_data_config("images", "wsi_generic_tiff", "hash_type") (or destructure a
single call if helper returns all fields) and pass those into download_url
instead of the constants; update imports in tests/test_utils.py to include
testing_data_config and keep the existing download_url usage and assertions
unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: d4c21ce8-3d39-4944-869e-df48b5adeeb6
📒 Files selected for processing (2)
tests/test_utils.pytests/testing_data/data_config.json
|
Please have a look at the DCO issue, we should be able to do a remedial commit to sort it. |
Fixes #8510
Description
Types of changes
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests --disttests.