-
Notifications
You must be signed in to change notification settings - Fork 22
A simple test of NapariNavigationToolbar._update_buttons_checked
.
#153
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
Merged
dstansby
merged 1 commit into
matplotlib:main
from
samcunliffe:test-toolbar-icons-change-when-selected
Jun 12, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import pytest | ||
from qtpy.QtCore import QSize | ||
from qtpy.QtGui import QImage | ||
|
||
from napari_matplotlib import HistogramWidget, ScatterWidget, SliceWidget | ||
|
||
|
||
def _are_different(a: QImage, b: QImage) -> bool: | ||
""" | ||
Check that a and b are identical, pixel by pixel. Via a stupid nested for loop. | ||
""" | ||
assert not a.isNull() | ||
assert not b.isNull() | ||
assert a.size() == b.size() | ||
for x in range(a.width()): | ||
for y in range(a.height()): | ||
if a.pixel(x, y) != b.pixel(x, y): | ||
return True # exit quickly | ||
return False | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"Widget", [HistogramWidget, ScatterWidget, SliceWidget] | ||
) | ||
def test_mpl_toolbar_buttons_checked(make_napari_viewer, Widget): | ||
"""Test that the icons for checkable actions change when when a tool is selected. | ||
|
||
A simple test of NapariNavigationToolbar._update_buttons_checked. Make sure the | ||
checked and unchecked icons are not the same. | ||
""" | ||
checkable_actions = ["Zoom", "Pan"] | ||
|
||
viewer = make_napari_viewer() | ||
widget = Widget(viewer) | ||
|
||
# search through all of the icons for the ones whose icons are expected to | ||
# change when checked | ||
for action in widget.toolbar.actions(): | ||
if action.text() in checkable_actions: | ||
assert action.isChecked() is False | ||
assert action.isCheckable() is True | ||
unchecked = action.icon().pixmap(QSize(48, 48)).toImage() | ||
|
||
# simulate the user click (QTest.mouseClick can't take a QAction) | ||
action.trigger() | ||
|
||
assert action.isChecked() is True | ||
checked = action.icon().pixmap(QSize(48, 48)).toImage() | ||
assert _are_different(unchecked, checked) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.