Skip to content

Commit 55f3721

Browse files
committed
parametrize the test and improved annotations
1 parent 8d87c43 commit 55f3721

File tree

1 file changed

+23
-31
lines changed

1 file changed

+23
-31
lines changed
Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,54 @@
11
from __future__ import annotations
22

3+
from typing import TYPE_CHECKING
4+
35
import numpy as np
6+
import pytest
47
import qtpy.QtCore as QC
58
from guidata.qthelpers import qt_app_context
69

7-
from plotpy.interfaces.items import IImageItemType
10+
from plotpy.interfaces.items import ICurveItemType, IImageItemType
811
from plotpy.tests.unit.utils import create_window, drag_mouse
912
from plotpy.tools import DisplayCoordsTool
1013

11-
12-
def test_display_coords_on_curve():
13-
"""Test display coordinates tool on a curve."""
14-
with qt_app_context(exec_loop=False) as qapp:
15-
win, tool = create_window(DisplayCoordsTool)
16-
drag_mouse(win, qapp, np.array([0.5]), np.array([0.5]), click=False)
17-
drag_mouse(win, qapp, np.array([0.5]), np.array([0.5]), click=True)
18-
drag_mouse(
19-
win,
20-
qapp,
21-
np.array([0.5]),
22-
np.array([0.5]),
23-
click=True,
24-
mod=QC.Qt.KeyboardModifier.AltModifier,
25-
)
26-
drag_mouse(
27-
win,
28-
qapp,
29-
np.array([0.5]),
30-
np.array([0.5]),
31-
click=True,
32-
mod=QC.Qt.KeyboardModifier.ControlModifier,
33-
)
14+
if TYPE_CHECKING:
15+
from plotpy.interfaces.items import IItemType
3416

3517

36-
def test_display_coords_on_image():
37-
"""Test display coordinates tool on an image."""
18+
@pytest.mark.parametrize("active_item", [ICurveItemType, IImageItemType, None])
19+
def test_display_coords(active_item: type[IItemType] | None):
20+
"""Test display coordinates tool on a curve and on an image."""
3821
with qt_app_context(exec_loop=False) as qapp:
39-
win, tool = create_window(DisplayCoordsTool, active_item_type=IImageItemType)
22+
win, tool = create_window(DisplayCoordsTool, active_item_type=active_item)
23+
plot = win.manager.get_plot()
24+
25+
# The is no way to test a condition while the mouse is moving so it is
26+
# not possible to test the display of the coordinates while the mouse is moving.
27+
assert plot.curve_pointer is False and plot.canvas_pointer is False
4028
drag_mouse(win, qapp, np.array([0.5]), np.array([0.5]), click=False)
29+
assert plot.curve_pointer is False and plot.canvas_pointer is False
4130
drag_mouse(win, qapp, np.array([0.5]), np.array([0.5]), click=True)
31+
assert plot.curve_pointer is False and plot.canvas_pointer is False
4232
drag_mouse(
4333
win,
4434
qapp,
4535
np.array([0.5]),
4636
np.array([0.5]),
47-
click=True,
37+
click=False,
4838
mod=QC.Qt.KeyboardModifier.AltModifier,
4939
)
40+
assert plot.curve_pointer is False and plot.canvas_pointer is False
5041
drag_mouse(
5142
win,
5243
qapp,
5344
np.array([0.5]),
5445
np.array([0.5]),
55-
click=True,
46+
click=False,
5647
mod=QC.Qt.KeyboardModifier.ControlModifier,
5748
)
49+
assert plot.curve_pointer is False and plot.canvas_pointer is False
5850

5951

6052
if __name__ == "__main__":
61-
test_display_coords_on_curve()
62-
test_display_coords_on_image()
53+
for item in (ICurveItemType, IImageItemType):
54+
test_display_coords(item)

0 commit comments

Comments
 (0)