Skip to content

fix: Second fix for napari repository tests - #1445

Merged
Czaki merged 1 commit into
developfrom
fix_napari_repo_0_8_1
Aug 4, 2026
Merged

fix: Second fix for napari repository tests#1445
Czaki merged 1 commit into
developfrom
fix_napari_repo_0_8_1

Conversation

@Czaki

@Czaki Czaki commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

closes #1438

Summary by Sourcery

Adjust napari image view behavior and related tests for compatibility with newer napari versions and stable test execution.

Enhancements:

  • Make scale bar visibility toggling compatible with both older and newer napari versions by switching between viewer.scale_bar and viewer.canvas.overlays.scale_bar as needed.

Tests:

  • Update napari image view integration tests to use typed qtbot/tmp_path parameters and explicitly show/hide the image view during filter tests.

Summary by CodeRabbit

  • Bug Fixes
    • Improved scale bar compatibility across supported napari versions.
    • Preserved nanometer unit handling for older napari releases.
  • Tests
    • Improved image-view integration test reliability by explicitly managing display visibility and strengthening test validation.

@sourcery-ai

sourcery-ai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts napari-based tests and scale bar handling to be compatible with newer napari versions while preserving behavior on older versions.

Flow diagram for updated napari scale bar toggling logic

flowchart TD
    A[toggle_scale_bar] --> B{_napari_le_7_0}
    B -- true --> C[viewer.scale_bar.unit = nm]
    B -- false --> D[skip unit change]
    C --> E{_napari_gt_8_0}
    D --> E
    E -- true --> F[viewer.canvas.overlays.scale_bar.visible = not viewer.canvas.overlays.scale_bar.visible]
    E -- false --> G[viewer.scale_bar.visible = not viewer.scale_bar.visible]
Loading

File-Level Changes

Change Details Files
Strengthen the napari image view integration test to use typed parameters and explicit widget show/hide, improving reliability with pytest-qt and Qt event handling.
  • Import pathlib.Path and pytestqt.QtBot to support type annotations and explicit usage in tests.
  • Add type annotations for qtbot, tmp_path, filter_value, ch_property, and image_view in the integration filter test.
  • Call image_view.show() before interacting with signals and filters to ensure the widget is properly initialized.
  • Call image_view.hide() at the end of the test to clean up the widget state after assertions.
  • Add type annotations to the inner check_parameters helper for clarity and static checking.
package/tests/test_PartSeg/test_channel_control.py
Update napari scale bar toggling logic to handle both pre-0.8 and post-0.8 napari APIs without breaking existing behavior.
  • Guard scale bar unit assignment under the _napari_le_7_0 flag, preserving existing behavior for older napari.
  • Use viewer.canvas.overlays.scale_bar.visible when _napari_gt_8_0 is true to match the new napari API.
  • Fallback to viewer.scale_bar.visible for non-_napari_gt_8_0 environments to maintain compatibility with earlier napari versions.
  • Preserve toggle semantics by inverting the current visibility state in both code paths.
package/PartSeg/common_gui/napari_image_view.py

Assessment against linked issues

Issue Objective Addressed Explanation
#1438 Fix the failing napari repository workflow tests (on ubuntu-24.04, Python 3.14) by updating PartSeg’s napari integration code and associated tests so they are compatible with the current napari version.

Possibly linked issues

  • [test-bot] napari repos test fail #1438: The PR updates napari image view scale bar handling and related tests to fix the reported napari workflow failures.
  • [test-bot] napari repos test fail #1438: The PR updates tests and napari_image_view scale bar handling to fix the failing napari workflow run.
  • #unknown: PR updates napari image view scale bar handling and integration tests, directly addressing the reported napari CI test failures.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sonarqubecloud

sonarqubecloud Bot commented Aug 3, 2026

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In toggle_scale_bar, consider handling the unit consistently for both napari versions (e.g., when _napari_gt_8_0 is true, set the unit on viewer.canvas.overlays.scale_bar as well) to avoid version-dependent discrepancies.
  • The version checks _napari_le_7_0 and _napari_gt_8_0 in toggle_scale_bar assume mutually exclusive ranges; if there are intermediate versions, you may want a more explicit branching or a fallback to prevent unexpected AttributeErrors.
  • In test_image_view_integration_filter, you might wrap the image_view.show()/hide() calls in a try/finally to ensure hide() is always executed even if the test fails midway.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `toggle_scale_bar`, consider handling the unit consistently for both napari versions (e.g., when `_napari_gt_8_0` is true, set the unit on `viewer.canvas.overlays.scale_bar` as well) to avoid version-dependent discrepancies.
- The version checks `_napari_le_7_0` and `_napari_gt_8_0` in `toggle_scale_bar` assume mutually exclusive ranges; if there are intermediate versions, you may want a more explicit branching or a fallback to prevent unexpected AttributeErrors.
- In `test_image_view_integration_filter`, you might wrap the `image_view.show()`/`hide()` calls in a try/finally to ensure `hide()` is always executed even if the test fails midway.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Czaki Czaki added this to the 0.17.1 milestone Aug 3, 2026
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds version-aware napari scale-bar visibility handling. It also adds type annotations and explicit image-view visibility management to an integration test.

Changes

Napari compatibility

Layer / File(s) Summary
Version-aware scale-bar visibility
package/PartSeg/common_gui/napari_image_view.py
toggle_scale_bar uses viewer.canvas.overlays.scale_bar.visible for napari versions above 0.8.0 and viewer.scale_bar.visible otherwise.
Image-view integration test setup
package/tests/test_PartSeg/test_channel_control.py
The test adds fixture type annotations and shows image_view before assertions, then hides it after the test.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies fixes for napari repository test failures, which matches the main pull request change.
Linked Issues check ✅ Passed The changes target napari compatibility and test execution issues described in issue #1438.
Out of Scope Changes check ✅ Passed All changes support napari repository test fixes and remain within the scope of issue #1438.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix_napari_repo_0_8_1

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
package/PartSeg/common_gui/napari_image_view.py (1)

248-251: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add regression coverage for both scale-bar API branches.

The changed test covers channel filtering, but it does not call toggle_scale_bar. Add a focused test that verifies visibility toggling through viewer.scale_bar for legacy napari versions and viewer.canvas.overlays.scale_bar for newer versions. napari 0.8.0 exposes viewer.scale_bar; newer source documents the overlay path from 0.8.1. (github.com)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@package/PartSeg/common_gui/napari_image_view.py` around lines 248 - 251, Add
focused regression coverage for toggle_scale_bar, exercising both version
branches: verify legacy versions toggle viewer.scale_bar.visible and newer
versions toggle viewer.canvas.overlays.scale_bar.visible. Use the existing
napari-version branching or fixtures and assert visibility changes in both
directions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@package/PartSeg/common_gui/napari_image_view.py`:
- Around line 248-251: Add focused regression coverage for toggle_scale_bar,
exercising both version branches: verify legacy versions toggle
viewer.scale_bar.visible and newer versions toggle
viewer.canvas.overlays.scale_bar.visible. Use the existing napari-version
branching or fixtures and assert visibility changes in both directions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d35f7e9e-5a8c-43b5-868f-e7c1fdbcfa7d

📥 Commits

Reviewing files that changed from the base of the PR and between 800ff7f and 6d83342.

📒 Files selected for processing (2)
  • package/PartSeg/common_gui/napari_image_view.py
  • package/tests/test_PartSeg/test_channel_control.py

@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.56%. Comparing base (800ff7f) to head (6d83342).

Files with missing lines Patch % Lines
package/PartSeg/common_gui/napari_image_view.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1445      +/-   ##
===========================================
- Coverage    92.56%   92.56%   -0.01%     
===========================================
  Files          211      211              
  Lines        33224    33230       +6     
===========================================
+ Hits         30755    30760       +5     
- Misses        2469     2470       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Czaki
Czaki merged commit d2fa7ba into develop Aug 4, 2026
58 of 59 checks passed
@Czaki
Czaki deleted the fix_napari_repo_0_8_1 branch August 4, 2026 08:15
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.

[test-bot] napari repos test fail

1 participant