Skip to content

Comments

Fixing SSIM Test Method Names#8746

Open
ericspod wants to merge 2 commits intoProject-MONAI:devfrom
ericspod:fix_ssim_test_names
Open

Fixing SSIM Test Method Names#8746
ericspod wants to merge 2 commits intoProject-MONAI:devfrom
ericspod:fix_ssim_test_names

Conversation

@ericspod
Copy link
Member

Description

This fixes erroneous test names flagged elsewhere by coderabbit.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • 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.
  • Documentation updated, tested make html command in the docs/ folder.

Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 22, 2026

📝 Walkthrough

Walkthrough

Six test methods in the multiscalessim metric test file were renamed to follow proper pytest naming conventions. Method names were updated to consistently use snake_case with the test_ prefix, enabling correct test discovery. No test logic or assertions were modified.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed Title accurately describes the main change: renaming test methods to follow pytest naming conventions.
Description check ✅ Passed Description covers the essential information and follows the template structure with appropriate checkboxes selected.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/metrics/test_compute_multiscalessim_metric.py (1)

75-79: ⚠️ Potential issue | 🟡 Minor

test_small_inputs is testing the wrong condition.

The input torch.randn(1, 1, 16, 16, 16) is a 5-D tensor (3 spatial dims) passed to a spatial_dims=2 metric. This raises ValueError due to a dimension mismatch — identical in kind to what test_input_ill_input_shape3d already covers. The intended scenario (a spatially-too-small 2-D input exhausted by MS-SSIM's downsampling cascade) is not exercised at all.

🛠️ Proposed fix
-    def test_small_inputs(self):
-        metric = MultiScaleSSIMMetric(spatial_dims=2)
-
-        with self.assertRaises(ValueError):
-            metric(torch.randn(1, 1, 16, 16, 16), torch.randn(1, 1, 16, 16, 16))
+    def test_small_inputs(self):
+        metric = MultiScaleSSIMMetric(spatial_dims=2)
+
+        with self.assertRaises(ValueError):
+            metric(torch.randn(1, 1, 4, 4), torch.randn(1, 1, 4, 4))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/metrics/test_compute_multiscalessim_metric.py` around lines 75 - 79,
The test_small_inputs currently passes 5-D tensors to
MultiScaleSSIMMetric(spatial_dims=2) causing a dimension-mismatch error (already
covered by test_input_ill_input_shape3d); change test_small_inputs to pass 4-D
tensors with valid rank but too-small spatial dimensions (e.g.,
torch.randn(1,1,8,8) or smaller) so the MS-SSIM downsampling cascade triggers a
ValueError; update the assertion to use those 4-D small spatial inputs and keep
the expect-ValueError assertion on MultiScaleSSIMMetric to avoid duplicating the
shape-mismatch case.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@tests/metrics/test_compute_multiscalessim_metric.py`:
- Around line 75-79: The test_small_inputs currently passes 5-D tensors to
MultiScaleSSIMMetric(spatial_dims=2) causing a dimension-mismatch error (already
covered by test_input_ill_input_shape3d); change test_small_inputs to pass 4-D
tensors with valid rank but too-small spatial dimensions (e.g.,
torch.randn(1,1,8,8) or smaller) so the MS-SSIM downsampling cascade triggers a
ValueError; update the assertion to use those 4-D small spatial inputs and keep
the expect-ValueError assertion on MultiScaleSSIMMetric to avoid duplicating the
shape-mismatch case.

@ericspod ericspod requested a review from wendell-hom February 22, 2026 12:31
@benediktjohannes
Copy link
Contributor

Hi @ericspod! Thanks for the fix, LGTM! I suggest that maybe changing this in tests/metrics/test_ssim_metric.py would maybe be a good addition for this in order to be consistent, how do you think about this? Thank you! And nice change!

@benediktjohannes
Copy link
Contributor

Unforetunately, it is not possible to add a code suggestion to other things than those edited in the PR (or at least I do think so), so I'll just add another PR in order to fix these issues so that you don't have to worry about this. 👍 And thanks again for the fix!

Copy link
Contributor

@benediktjohannes benediktjohannes left a comment

Choose a reason for hiding this comment

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

Nice changes! Thanks!

Copy link
Contributor

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

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

LGTM

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.

3 participants