Skip to content

Commit d9483a4

Browse files
committed
slight improvement to colormap editor test
1 parent 640608d commit d9483a4

File tree

1 file changed

+39
-15
lines changed

1 file changed

+39
-15
lines changed

plotpy/tests/features/test_colormap_manager.py

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,58 @@
1111

1212
# guitest: show
1313

14+
import pytest
1415
import qtpy.QtCore as QC
1516
import qtpy.QtGui as QG
1617
from guidata.env import execenv
1718
from guidata.qthelpers import exec_dialog, qt_app_context
1819

19-
from plotpy.mathutils.colormap import ALL_COLORMAPS
20+
from plotpy.mathutils.colormap import ALL_COLORMAPS, delete_cmap, get_cmap
2021
from plotpy.widgets.colormap.manager import ColorMapManager
2122
from plotpy.widgets.colormap.widget import EditableColormap
2223

2324

24-
def test_colormap_manager() -> None:
25+
@pytest.fixture
26+
def test_cmap(cmap_name="Kinda Viridis"):
27+
cmap = EditableColormap(
28+
[QG.QColor(QC.Qt.GlobalColor.blue), QG.QColor(QC.Qt.GlobalColor.yellow)],
29+
name=cmap_name,
30+
)
31+
yield cmap
32+
33+
delete_cmap(get_cmap(cmap_name))
34+
35+
36+
def test_colormap_manager(test_cmap: EditableColormap) -> None:
2537
"""Test the colormap manager widget."""
26-
with qt_app_context():
38+
with qt_app_context(exec_loop=False):
2739
red = QG.QColor(QC.Qt.GlobalColor.red)
28-
blue = QG.QColor(QC.Qt.GlobalColor.blue)
29-
yellow = QG.QColor(QC.Qt.GlobalColor.yellow)
30-
cmap = EditableColormap(blue, yellow, name="kinda_viridis")
31-
ALL_COLORMAPS["kinda_viridis"] = cmap
32-
dlg = ColorMapManager(None, active_colormap="YlGn")
33-
dlg.colormap_editor.colormap_widget.add_handle_at_relative_pos(0.5, red)
34-
dlg.get_colormap()
35-
dlg.colormap_editor.update_colormap_widget()
36-
dlg.colormap_editor.update_current_dataset()
37-
result = exec_dialog(dlg)
40+
cmap_editor = ColorMapManager(None, active_colormap="YlGn")
41+
cmap_editor.show()
42+
43+
with execenv.context(accept_dialogs=True):
44+
cmap_editor.save_colormap(test_cmap)
45+
cmap_editor.colormap_editor.colormap_widget.add_handle_at_relative_pos(0.5, red)
46+
cmap_editor.get_colormap()
47+
cmap_editor.colormap_editor.update_colormap_widget()
48+
cmap_editor.colormap_editor.update_current_dataset()
49+
50+
# set the colormap to last one
51+
with execenv.context(accept_dialogs=True):
52+
cmap_editor.remove_colormap()
53+
54+
result = exec_dialog(cmap_editor)
3855
execenv.print("Dialog result:", result)
39-
cmap = dlg.get_colormap()
56+
cmap = cmap_editor.get_colormap()
4057
execenv.print("Selected colormap:", None if cmap is None else cmap.name)
58+
delete_cmap(test_cmap)
4159

4260

4361
if __name__ == "__main__":
44-
test_colormap_manager()
62+
test_name = "Kinda Viridis"
63+
new_colormap = EditableColormap(
64+
[QG.QColor(QC.Qt.GlobalColor.blue), QG.QColor(QC.Qt.GlobalColor.yellow)],
65+
name=test_name,
66+
)
67+
test_colormap_manager(new_colormap)
68+
delete_cmap(get_cmap(test_name))

0 commit comments

Comments
 (0)