Skip to content

Commit a4340b5

Browse files
committed
Merge remote-tracking branch 'Codra/develop-2.1_tools-unit-tests' into develop
2 parents 64e895b + 21ffc8d commit a4340b5

16 files changed

Lines changed: 801 additions & 55 deletions
0 Bytes
Binary file not shown.

plotpy/locale/fr/LC_MESSAGES/plotpy.po

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
msgid ""
77
msgstr ""
88
"Project-Id-Version: \n"
9-
"POT-Creation-Date: 2024-03-01 10:00+0100\n"
9+
"POT-Creation-Date: 2024-03-01 10:13+0100\n"
1010
"PO-Revision-Date: 2019-02-20 14:42+0100\n"
1111
"Last-Translator: \n"
1212
"Language-Team: \n"
@@ -1468,7 +1468,7 @@ msgid "Right-click on the curve to enable/disable downsampling"
14681468
msgstr ""
14691469
"Clic droit sur la courbe pour activer/désactiver le sous-échantillonnage"
14701470

1471-
#: plotpy\tests\tools\test_edit_point.py:47 plotpy\tools\curve.py:836
1471+
#: plotpy\tests\tools\test_edit_point.py:47 plotpy\tools\curve.py:837
14721472
msgid "Insert point"
14731473
msgstr "Insérer un point"
14741474

@@ -1650,71 +1650,71 @@ msgstr "Curseur horizontal"
16501650
msgid "Cross cursor"
16511651
msgstr "Curseur croix"
16521652

1653-
#: plotpy\tools\curve.py:50
1653+
#: plotpy\tools\curve.py:51
16541654
msgid "Signal statistics"
16551655
msgstr "Statistiques du signal"
16561656

1657-
#: plotpy\tools\curve.py:156
1657+
#: plotpy\tools\curve.py:157
16581658
msgid "Antialiasing (curves)"
16591659
msgstr "Anticrénelage (courbes)"
16601660

1661-
#: plotpy\tools\curve.py:190
1661+
#: plotpy\tools\curve.py:191
16621662
msgid "Point selection"
16631663
msgstr "Sélection d'un point"
16641664

1665-
#: plotpy\tools\curve.py:340
1665+
#: plotpy\tools\curve.py:341
16661666
msgid "Multi-point selection"
16671667
msgstr "Sélection multi-points"
16681668

1669-
#: plotpy\tools\curve.py:629
1669+
#: plotpy\tools\curve.py:630
16701670
msgid "Insertion index"
16711671
msgstr "Index d'insertion"
16721672

1673-
#: plotpy\tools\curve.py:631
1673+
#: plotpy\tools\curve.py:632
16741674
msgid "New value"
16751675
msgstr "Nouvelle valeur"
16761676

1677-
#: plotpy\tools\curve.py:633
1677+
#: plotpy\tools\curve.py:634
16781678
msgid "After"
16791679
msgstr "Après"
16801680

1681-
#: plotpy\tools\curve.py:633
1681+
#: plotpy\tools\curve.py:634
16821682
msgid "Before"
16831683
msgstr "Avant"
16841684

1685-
#: plotpy\tools\curve.py:633
1685+
#: plotpy\tools\curve.py:634
16861686
msgid "Location"
16871687
msgstr "Position"
16881688

1689-
#: plotpy\tools\curve.py:661
1689+
#: plotpy\tools\curve.py:662
16901690
msgid "Edit point"
16911691
msgstr "Modifier le point"
16921692

1693-
#: plotpy\tools\curve.py:837
1693+
#: plotpy\tools\curve.py:838
16941694
msgid "Before inserting a new point, please select an existing curve point."
16951695
msgstr "Avant d'insérer un nouveau point, sélectionner un point existant."
16961696

1697-
#: plotpy\tools\curve.py:844
1697+
#: plotpy\tools\curve.py:845
16981698
msgid "Insert new value"
16991699
msgstr "Insérer une nouvelle valeur"
17001700

1701-
#: plotpy\tools\curve.py:1091
1701+
#: plotpy\tools\curve.py:1095
17021702
msgid "Downsample"
17031703
msgstr "Sous-échantillonner"
17041704

1705-
#: plotpy\tools\curve.py:1138 plotpy\tools\curve.py:1150
1705+
#: plotpy\tools\curve.py:1142 plotpy\tools\curve.py:1154
17061706
msgid "Export"
17071707
msgstr "Exporter"
17081708

1709-
#: plotpy\tools\curve.py:1142
1709+
#: plotpy\tools\curve.py:1146
17101710
msgid "Text file"
17111711
msgstr "Fichier texte"
17121712

1713-
#: plotpy\tools\curve.py:1151
1713+
#: plotpy\tools\curve.py:1155
17141714
msgid "Unable to export item data."
17151715
msgstr "Impossible d'exporter les données de l'objet sélectionné."
17161716

1717-
#: plotpy\tools\curve.py:1153
1717+
#: plotpy\tools\curve.py:1157
17181718
msgid "Error message:"
17191719
msgstr "Message d'erreur :"
17201720

@@ -2289,3 +2289,6 @@ msgstr "Rotation et rognage"
22892289
#: plotpy\widgets\rotatecrop.py:219
22902290
msgid "Show cropping rectangle"
22912291
msgstr "Afficher le rectangle de rognage"
2292+
2293+
#~ msgid "Save"
2294+
#~ msgstr "Enregistrer"

plotpy/locale/plotpy.pot

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
msgid ""
66
msgstr ""
77
"Project-Id-Version: PACKAGE VERSION\n"
8-
"POT-Creation-Date: 2024-03-01 10:00+0100\n"
8+
"POT-Creation-Date: 2024-03-01 10:13+0100\n"
99
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1010
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1111
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -1416,7 +1416,7 @@ msgstr ""
14161416
msgid "Right-click on the curve to enable/disable downsampling"
14171417
msgstr ""
14181418

1419-
#: plotpy\tests\tools\test_edit_point.py:47 plotpy\tools\curve.py:836
1419+
#: plotpy\tests\tools\test_edit_point.py:47 plotpy\tools\curve.py:837
14201420
msgid "Insert point"
14211421
msgstr ""
14221422

@@ -1594,71 +1594,71 @@ msgstr ""
15941594
msgid "Cross cursor"
15951595
msgstr ""
15961596

1597-
#: plotpy\tools\curve.py:50
1597+
#: plotpy\tools\curve.py:51
15981598
msgid "Signal statistics"
15991599
msgstr ""
16001600

1601-
#: plotpy\tools\curve.py:156
1601+
#: plotpy\tools\curve.py:157
16021602
msgid "Antialiasing (curves)"
16031603
msgstr ""
16041604

1605-
#: plotpy\tools\curve.py:190
1605+
#: plotpy\tools\curve.py:191
16061606
msgid "Point selection"
16071607
msgstr ""
16081608

1609-
#: plotpy\tools\curve.py:340
1609+
#: plotpy\tools\curve.py:341
16101610
msgid "Multi-point selection"
16111611
msgstr ""
16121612

1613-
#: plotpy\tools\curve.py:629
1613+
#: plotpy\tools\curve.py:630
16141614
msgid "Insertion index"
16151615
msgstr ""
16161616

1617-
#: plotpy\tools\curve.py:631
1617+
#: plotpy\tools\curve.py:632
16181618
msgid "New value"
16191619
msgstr ""
16201620

1621-
#: plotpy\tools\curve.py:633
1621+
#: plotpy\tools\curve.py:634
16221622
msgid "After"
16231623
msgstr ""
16241624

1625-
#: plotpy\tools\curve.py:633
1625+
#: plotpy\tools\curve.py:634
16261626
msgid "Before"
16271627
msgstr ""
16281628

1629-
#: plotpy\tools\curve.py:633
1629+
#: plotpy\tools\curve.py:634
16301630
msgid "Location"
16311631
msgstr ""
16321632

1633-
#: plotpy\tools\curve.py:661
1633+
#: plotpy\tools\curve.py:662
16341634
msgid "Edit point"
16351635
msgstr ""
16361636

1637-
#: plotpy\tools\curve.py:837
1637+
#: plotpy\tools\curve.py:838
16381638
msgid "Before inserting a new point, please select an existing curve point."
16391639
msgstr ""
16401640

1641-
#: plotpy\tools\curve.py:844
1641+
#: plotpy\tools\curve.py:845
16421642
msgid "Insert new value"
16431643
msgstr ""
16441644

1645-
#: plotpy\tools\curve.py:1091
1645+
#: plotpy\tools\curve.py:1095
16461646
msgid "Downsample"
16471647
msgstr ""
16481648

1649-
#: plotpy\tools\curve.py:1138 plotpy\tools\curve.py:1150
1649+
#: plotpy\tools\curve.py:1142 plotpy\tools\curve.py:1154
16501650
msgid "Export"
16511651
msgstr ""
16521652

1653-
#: plotpy\tools\curve.py:1142
1653+
#: plotpy\tools\curve.py:1146
16541654
msgid "Text file"
16551655
msgstr ""
16561656

1657-
#: plotpy\tools\curve.py:1151
1657+
#: plotpy\tools\curve.py:1155
16581658
msgid "Unable to export item data."
16591659
msgstr ""
16601660

1661-
#: plotpy\tools\curve.py:1153
1661+
#: plotpy\tools\curve.py:1157
16621662
msgid "Error message:"
16631663
msgstr ""
16641664

plotpy/tests/tools/test_cross_section_line.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""Line cross section test"""
77

88
# guitest: show
9+
from __future__ import annotations
910

1011
from guidata.qthelpers import qt_app_context
1112

plotpy/tests/tools/test_cross_section_oblique.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
# guitest: show
99

10+
from __future__ import annotations
11+
1012
from plotpy.panels.csection.csitem import ObliqueCrossSectionItem
1113
from plotpy.panels.csection.cswidget import ObliqueCrossSection
1214
from plotpy.tests.tools import test_cross_section_line
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from __future__ import annotations
2+
3+
import qtpy.QtCore as QC
4+
from guidata.qthelpers import exec_dialog, qt_app_context
5+
6+
from plotpy.interfaces.items import IImageItemType
7+
from plotpy.tests.unit.utils import create_window
8+
from plotpy.tools import AspectRatioTool
9+
10+
11+
def test_aspect_ratio_tool():
12+
"""Test the aspect ratio tool."""
13+
with qt_app_context(exec_loop=False):
14+
win, tool = create_window(AspectRatioTool, active_item_type=IImageItemType)
15+
plot = win.manager.get_plot()
16+
17+
initial_aspect_ratio: float = plot.get_aspect_ratio()
18+
19+
new_ratio = 0.5
20+
21+
plot.set_aspect_ratio(new_ratio)
22+
tool.edit_aspect_ratio()
23+
assert plot.get_aspect_ratio() == new_ratio
24+
25+
plot.set_aspect_ratio(initial_aspect_ratio)
26+
tool.edit_aspect_ratio()
27+
assert plot.get_aspect_ratio() == initial_aspect_ratio
28+
29+
tool.lock_aspect_ratio(True)
30+
assert plot.lock_aspect_ratio is True
31+
tool.lock_aspect_ratio(False)
32+
assert plot.lock_aspect_ratio is False
33+
34+
exec_dialog(win)
35+
36+
37+
if __name__ == "__main__":
38+
test_aspect_ratio_tool()

plotpy/tests/unit/test_baseplot.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def test_baseplot_api():
2626
plot = win.get_plot()
2727
plot.manager.add_tool(SelectPointsTool)
2828
plot.manager.add_tool(EditPointTool)
29-
plot.manager.add_tool(DownSamplingTool) # noqa: F821
3029
plot.get_default_item()
3130
title = "Test title"
3231
plot.set_title(title)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from __future__ import annotations
2+
3+
import numpy as np
4+
from guidata.qthelpers import qt_app_context
5+
6+
from plotpy.interfaces.items import IImageItemType
7+
from plotpy.tests.unit.utils import create_window, drag_mouse
8+
from plotpy.tools import DisplayCoordsTool
9+
10+
11+
def test_display_coords_on_curve():
12+
"""Test display coordinates tool on a curve."""
13+
with qt_app_context(exec_loop=False) as qapp:
14+
win, tool = create_window(DisplayCoordsTool)
15+
drag_mouse(win, qapp, np.array([0.5]), np.array([0.5]), click=False)
16+
drag_mouse(win, qapp, np.array([0.5]), np.array([0.5]), click=True)
17+
18+
19+
def test_display_coords_on_image():
20+
"""Test display coordinates tool on an image."""
21+
with qt_app_context(exec_loop=False) as qapp:
22+
win, tool = create_window(DisplayCoordsTool, active_item_type=IImageItemType)
23+
drag_mouse(win, qapp, np.array([0.5]), np.array([0.5]), click=False)
24+
drag_mouse(win, qapp, np.array([0.5]), np.array([0.5]), click=True)
25+
26+
27+
if __name__ == "__main__":
28+
test_display_coords_on_curve()
29+
test_display_coords_on_image()
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from __future__ import annotations
2+
3+
import numpy as np
4+
import qtpy.QtCore as QC
5+
from guidata.qthelpers import exec_dialog, qt_app_context
6+
7+
from plotpy.tests.unit.utils import (
8+
CLICK,
9+
create_window,
10+
keyboard_event,
11+
mouse_event_at_relative_plot_pos,
12+
)
13+
from plotpy.tools import FreeFormTool, MultiLineTool
14+
15+
16+
def test_free_form_tool():
17+
"""Test the free form tool."""
18+
corners = np.array(((0.1, 0.1), (0.1, 0.8), (0.8, 0.8), (0.8, 0.1)))
19+
with qt_app_context(exec_loop=False) as qapp:
20+
win, tool = create_window(FreeFormTool)
21+
22+
# drag_mouse(win, qapp, x_path, y_path)
23+
for x, y in corners:
24+
mouse_event_at_relative_plot_pos(win, qapp, (x, y), CLICK)
25+
26+
assert tool.shape is not None
27+
28+
assert tool.shape.get_points().shape == corners.shape
29+
30+
exec_dialog(win)
31+
32+
33+
def test_multiline_tool():
34+
"""Test the multi line tool."""
35+
n = 100
36+
t = np.linspace(0, np.pi * 10, n)
37+
38+
# Create x and y arrays
39+
x_arr = t * np.cos(t) / n + 0.5
40+
y_arr = t * np.sin(t) / n + 0.5
41+
42+
with qt_app_context(exec_loop=False) as qapp:
43+
win, tool = create_window(MultiLineTool)
44+
45+
# drag_mouse(win, qapp, x_path, y_path)
46+
for x, y in zip(x_arr, y_arr):
47+
mouse_event_at_relative_plot_pos(win, qapp, (x, y), CLICK)
48+
49+
assert tool.shape is not None
50+
assert tool.shape.get_points().shape == np.array([x_arr, y_arr]).T.shape
51+
52+
# Delete last point
53+
keyboard_event(win, qapp, QC.Qt.Key.Key_Backspace)
54+
55+
points_count, _ = tool.shape.get_points().shape
56+
57+
assert points_count == (n - 1)
58+
59+
exec_dialog(win)
60+
61+
62+
if __name__ == "__main__":
63+
test_free_form_tool()
64+
test_multiline_tool()

0 commit comments

Comments
 (0)