Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f3cc982

Browse filesBrowse files
committed
A simple test of _update_buttons_checked.
A (slightly) dumb pixel-by-pixel test that the checked and unchecked icons are different.
1 parent ea2f7bc commit f3cc982
Copy full SHA for f3cc982

File tree

1 file changed

+49
-0
lines changed
Filter options

1 file changed

+49
-0
lines changed
+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import pytest
2+
from qtpy.QtCore import QSize
3+
from qtpy.QtGui import QImage
4+
5+
from napari_matplotlib import HistogramWidget, ScatterWidget, SliceWidget
6+
7+
8+
def _are_different(a: QImage, b: QImage) -> bool:
9+
"""
10+
Check that a and b are identical, pixel by pixel. Via a stupid nested for loop.
11+
"""
12+
assert not a.isNull()
13+
assert not b.isNull()
14+
assert a.size() == b.size()
15+
for x in range(a.width()):
16+
for y in range(a.height()):
17+
if a.pixel(x, y) != b.pixel(x, y):
18+
return True # exit quickly
19+
return False
20+
21+
22+
@pytest.mark.parametrize(
23+
"Widget", [HistogramWidget, ScatterWidget, SliceWidget]
24+
)
25+
def test_mpl_toolbar_buttons_checked(make_napari_viewer, Widget):
26+
"""Test that the icons for checkable actions change when when a tool is selected.
27+
28+
A simple test of NapariNavigationToolbar._update_buttons_checked. Make sure the
29+
checked and unchecked icons are not the same.
30+
"""
31+
checkable_actions = ["Zoom", "Pan"]
32+
33+
viewer = make_napari_viewer()
34+
widget = Widget(viewer)
35+
36+
# search through all of the icons for the ones whose icons are expected to
37+
# change when checked
38+
for action in widget.toolbar.actions():
39+
if action.text() in checkable_actions:
40+
assert action.isChecked() is False
41+
assert action.isCheckable() is True
42+
unchecked = action.icon().pixmap(QSize(48, 48)).toImage()
43+
44+
# simulate the user click (QTest.mouseClick can't take a QAction)
45+
action.trigger()
46+
47+
assert action.isChecked() is True
48+
checked = action.icon().pixmap(QSize(48, 48)).toImage()
49+
assert _are_different(unchecked, checked)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.