Skip to content

Commit 7862618

Browse files
authored
Merge pull request #153 from samcunliffe/test-toolbar-icons-change-when-selected
A simple test of `NapariNavigationToolbar._update_buttons_checked`.
2 parents 4c87a89 + f3cc982 commit 7862618

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy