Skip to content

Commit 5047fd2

Browse files
committed
test some non-tested events
1 parent 9651705 commit 5047fd2

1 file changed

Lines changed: 116 additions & 0 deletions

File tree

plotpy/tests/unit/test_events.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
"""
2+
This files tests the vent handlers not covered by other tests.
3+
"""
4+
5+
from typing import Callable
6+
7+
import numpy as np
8+
import pytest
9+
import qtpy.QtCore as QC
10+
import qtpy.QtWidgets as QW
11+
from guidata.qthelpers import exec_dialog, qt_app_context
12+
13+
from plotpy.plot.plotwidget import PlotDialog, PlotWindow
14+
from plotpy.tests.unit.utils import (
15+
create_window,
16+
drag_mouse,
17+
scroll_wheel,
18+
)
19+
from plotpy.tools.selection import SelectTool
20+
21+
# guitest: show
22+
23+
24+
def _zoom_with_mouse(qapp: QW.QApplication, win: PlotWindow | PlotDialog):
25+
drag_mouse(
26+
win,
27+
qapp,
28+
np.array([0.5, 0.8]),
29+
np.array([0.5, 0.5]),
30+
btn=QC.Qt.MouseButton.RightButton,
31+
)
32+
33+
34+
def _zoom_with_wheel(qapp: QW.QApplication, win: PlotWindow | PlotDialog):
35+
scroll_wheel(
36+
win,
37+
qapp,
38+
(0.5, 0.5),
39+
360,
40+
0,
41+
mods=QC.Qt.KeyboardModifier.ControlModifier,
42+
)
43+
44+
45+
@pytest.mark.parametrize(
46+
"zoom_func",
47+
[_zoom_with_mouse, _zoom_with_wheel],
48+
)
49+
def test_zoom(
50+
zoom_func: Callable[[QW.QApplication, PlotWindow | PlotDialog], None],
51+
):
52+
with qt_app_context(exec_loop=False) as qapp:
53+
win, _ = create_window(SelectTool)
54+
win.show()
55+
56+
plot = win.manager.get_plot()
57+
plot.unselect_all()
58+
59+
axis_x, axis_y = plot.get_active_axes()
60+
61+
x_min0, x_max0 = plot.get_axis_limits(axis_x)
62+
y_min0, y_max0 = plot.get_axis_limits(axis_y)
63+
64+
zoom_func(qapp, win)
65+
66+
x_min1, x_max1 = plot.get_axis_limits(axis_x)
67+
y_min1, y_max1 = plot.get_axis_limits(axis_y)
68+
69+
print(x_min0, x_max0, y_min0, y_max0)
70+
print(x_min1, x_max1, y_min1, y_max1)
71+
assert x_min1 > x_min0
72+
assert x_max1 < x_max0
73+
assert y_min1 < y_min0
74+
assert y_max1 > y_max0
75+
76+
exec_dialog(win)
77+
78+
79+
def test_pan():
80+
with qt_app_context(exec_loop=False) as qapp:
81+
win, _ = create_window(SelectTool)
82+
win.show()
83+
84+
plot = win.manager.get_plot()
85+
plot.unselect_all()
86+
87+
axis_x, axis_y = plot.get_active_axes()
88+
89+
x_min0, x_max0 = plot.get_axis_limits(axis_x)
90+
y_min0, y_max0 = plot.get_axis_limits(axis_y)
91+
92+
drag_mouse(
93+
win,
94+
qapp,
95+
np.linspace(0.5, 0, 100),
96+
np.linspace(0.5, 0, 100),
97+
btn=QC.Qt.MouseButton.MiddleButton,
98+
)
99+
100+
x_min1, x_max1 = plot.get_axis_limits(axis_x)
101+
y_min1, y_max1 = plot.get_axis_limits(axis_y)
102+
103+
print(x_min0, x_max0, y_min0, y_max0)
104+
print(x_min1, x_max1, y_min1, y_max1)
105+
# assert x_min1 > x_min0
106+
# assert x_max1 > x_max0
107+
# assert y_min1 > y_min0
108+
# assert y_max1 > y_max0
109+
110+
exec_dialog(win)
111+
112+
113+
if __name__ == "__main__":
114+
test_zoom(_zoom_with_mouse)
115+
test_zoom(_zoom_with_wheel)
116+
test_pan()

0 commit comments

Comments
 (0)