Skip to content

Refactor download_url test into TestDownloadUrl class#8829

Open
e-mny wants to merge 3 commits intoProject-MONAI:devfrom
e-mny:dev
Open

Refactor download_url test into TestDownloadUrl class#8829
e-mny wants to merge 3 commits intoProject-MONAI:devfrom
e-mny:dev

Conversation

@e-mny
Copy link
Copy Markdown

@e-mny e-mny commented Apr 17, 2026

Fixes #8510

Description

  • The data_config.json needs to be updated with HF links in view of migrating to HF.
  • Implement download_url tests

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 17, 2026

📝 Walkthrough

Walkthrough

This PR adds a new test class TestDownloadUrl to verify the download_url function's hash validation capability against a remote TIFF file. Concurrently, it updates data_config.json to migrate all test resource URLs from GitHub Releases endpoints to the HuggingFace dataset repository. Both changes support the transition of testing data storage from GitHub to HuggingFace.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly describes the main change: refactoring download_url tests into a TestDownloadUrl class, matching the primary code modifications.
Description check ✅ Passed Description covers the linked issue, outlines both main changes (data_config.json migration and test implementation), and confirms all required testing types passed.
Linked Issues check ✅ Passed Changes fulfill issue #8510 objectives: migrates data URLs to HuggingFace dataset and implements download_url tests as required.
Out of Scope Changes check ✅ Passed All changes directly align with issue #8510: test class additions and data_config.json URL updates to HuggingFace endpoints are in scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🟡 Minor

Two URLs were missed in the HF migration.

images.nrrd_example (line 89) and configs.test_meta_file (line 165) still point at github.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.json

Also 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 from testing_data_config instead of hard-coding.

wsi_generic_tiff in data_config.json already holds the same URL/hash_type/hash_val. Using testing_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

📥 Commits

Reviewing files that changed from the base of the PR and between 1dc47a5 and 6296784.

📒 Files selected for processing (2)
  • tests/test_utils.py
  • tests/testing_data/data_config.json

Comment thread tests/test_utils.py
Copy link
Copy Markdown
Member

@ericspod ericspod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @e-mny sorry for losing track of the previous PR! This looks good now and will merge.

@ericspod
Copy link
Copy Markdown
Member

Please have a look at the DCO issue, we should be able to do a remedial commit to sort it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Moving Testing Data to HuggingFace

2 participants