|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +from typing import TYPE_CHECKING |
| 4 | + |
3 | 5 | import numpy as np |
| 6 | +import pytest |
4 | 7 | import qtpy.QtCore as QC |
5 | 8 | from guidata.qthelpers import qt_app_context |
6 | 9 |
|
7 | | -from plotpy.interfaces.items import IImageItemType |
| 10 | +from plotpy.interfaces.items import ICurveItemType, IImageItemType |
8 | 11 | from plotpy.tests.unit.utils import create_window, drag_mouse |
9 | 12 | from plotpy.tools import DisplayCoordsTool |
10 | 13 |
|
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 |
34 | 16 |
|
35 | 17 |
|
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.""" |
38 | 21 | 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 |
40 | 28 | 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 |
41 | 30 | 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 |
42 | 32 | drag_mouse( |
43 | 33 | win, |
44 | 34 | qapp, |
45 | 35 | np.array([0.5]), |
46 | 36 | np.array([0.5]), |
47 | | - click=True, |
| 37 | + click=False, |
48 | 38 | mod=QC.Qt.KeyboardModifier.AltModifier, |
49 | 39 | ) |
| 40 | + assert plot.curve_pointer is False and plot.canvas_pointer is False |
50 | 41 | drag_mouse( |
51 | 42 | win, |
52 | 43 | qapp, |
53 | 44 | np.array([0.5]), |
54 | 45 | np.array([0.5]), |
55 | | - click=True, |
| 46 | + click=False, |
56 | 47 | mod=QC.Qt.KeyboardModifier.ControlModifier, |
57 | 48 | ) |
| 49 | + assert plot.curve_pointer is False and plot.canvas_pointer is False |
58 | 50 |
|
59 | 51 |
|
60 | 52 | 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