Skip to content

Commit fc99400

Browse files
committed
fix colormap tests
1 parent f1342d8 commit fc99400

2 files changed

Lines changed: 61 additions & 56 deletions

File tree

plotpy/tests/features/test_colormap_editor.py

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,66 +17,67 @@
1717
import qtpy.QtCore as QC
1818
import qtpy.QtGui as QG
1919
import qtpy.QtWidgets as QW
20+
from guidata.qthelpers import qt_app_context
2021

2122
from plotpy.widgets.colormap_editor import ColorMapEditor
2223
from plotpy.widgets.colormap_widget import CustomQwtLinearColormap
2324

24-
if __name__ == "__main__":
25-
print("Initialization of a default colormap editor widget")
26-
app = QW.QApplication([])
27-
editor = ColorMapEditor(None)
28-
red = QG.QColor(QC.Qt.GlobalColor.red)
29-
green = QG.QColor(QC.Qt.GlobalColor.green)
30-
editor.colormap_widget.add_handle_at_relative_pos(0.5, red)
31-
editor.show()
32-
app.exec_()
3325

34-
cmap_tuples = editor.get_colormap().to_tuples()
35-
print(
36-
"Initialization of a new colormap editor with the previous colormap: ",
37-
cmap_tuples,
38-
)
39-
new_cmap = CustomQwtLinearColormap.from_iterable(cmap_tuples)
40-
print(f"{new_cmap.to_tuples()}")
41-
editor = ColorMapEditor(None, colormap=new_cmap)
42-
editor.show()
43-
app.exec_()
26+
def test_colormap_manager():
27+
with qt_app_context(exec_loop=True):
28+
print("Initialization of a default colormap editor widget")
29+
editor = ColorMapEditor(None)
30+
red = QG.QColor(QC.Qt.GlobalColor.red)
31+
green = QG.QColor(QC.Qt.GlobalColor.green)
32+
editor.colormap_widget.add_handle_at_relative_pos(0.5, red)
33+
editor.show()
34+
35+
cmap_tuples = editor.get_colormap().to_tuples()
36+
print(
37+
"Initialization of a new colormap editor with the previous colormap: ",
38+
cmap_tuples,
39+
)
40+
new_cmap = CustomQwtLinearColormap.from_iterable(cmap_tuples)
41+
print(f"{new_cmap.to_tuples()}")
42+
editor = ColorMapEditor(None, colormap=new_cmap)
43+
editor.show()
44+
45+
cmap_tuples = editor.get_colormap().to_tuples()
46+
print(
47+
"Initialization of a new default colormap editor, "
48+
"modified post-initialization with the previous colormap: ",
49+
cmap_tuples,
50+
)
51+
new_cmap = CustomQwtLinearColormap.from_iterable(cmap_tuples)
52+
editor = ColorMapEditor(None)
53+
editor.set_colormap(new_cmap)
54+
editor.show()
4455

45-
cmap_tuples = editor.get_colormap().to_tuples()
46-
print(
47-
"Initialization of a new default colormap editor, "
48-
"modified post-initialization with the previous colormap: ",
49-
cmap_tuples,
50-
)
51-
new_cmap = CustomQwtLinearColormap.from_iterable(cmap_tuples)
52-
editor = ColorMapEditor(None)
53-
editor.set_colormap(new_cmap)
54-
editor.show()
55-
app.exec_()
56+
cmap_tuples = editor.get_colormap().to_tuples()
57+
cmap_tuples = tuple((int(val * 255 + 1), color) for val, color in cmap_tuples)
58+
print(
59+
"Initialization of a new default colormap editor, "
60+
"modified post-initialization with the previous colormap with stops scaled by "
61+
"255 + 1: ",
62+
cmap_tuples,
63+
)
64+
new_cmap = CustomQwtLinearColormap.from_iterable(cmap_tuples)
65+
editor = ColorMapEditor(None)
66+
editor.set_colormap(new_cmap)
67+
editor.show()
5668

57-
cmap_tuples = editor.get_colormap().to_tuples()
58-
cmap_tuples = tuple((int(val * 255 + 1), color) for val, color in cmap_tuples)
59-
print(
60-
"Initialization of a new default colormap editor, "
61-
"modified post-initialization with the previous colormap with stops scaled by "
62-
"255 + 1: ",
63-
cmap_tuples,
64-
)
65-
new_cmap = CustomQwtLinearColormap.from_iterable(cmap_tuples)
66-
editor = ColorMapEditor(None)
67-
editor.set_colormap(new_cmap)
68-
editor.show()
69-
app.exec_()
69+
print(
70+
"Initialization of a new default colormap editor, "
71+
"modified post-initialization with the previous colormap where the red stop is "
72+
"replaced with a green stop: ",
73+
cmap_tuples,
74+
)
7075

71-
print(
72-
"Initialization of a new default colormap editor, "
73-
"modified post-initialization with the previous colormap where the red stop is "
74-
"replaced with a green stop: ",
75-
cmap_tuples,
76-
)
76+
editor = ColorMapEditor(None)
77+
editor.set_colormap(new_cmap)
78+
editor.colormap_widget.edit_color_stop(1, None, green)
79+
editor.show()
7780

78-
editor = ColorMapEditor(None)
79-
editor.set_colormap(new_cmap)
80-
editor.colormap_widget.edit_color_stop(1, None, green)
81-
editor.show()
82-
app.exec_()
81+
82+
if __name__ == "__main__":
83+
test_colormap_manager()

plotpy/tests/features/test_colormap_manager.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
from plotpy.widgets.colormap_manager import ColorMapManager
2020
from plotpy.widgets.colormap_widget import CustomQwtLinearColormap
2121

22-
if __name__ == "__main__":
22+
23+
def test_colormap_manager():
2324
with qt_app_context(exec_loop=True):
2425
# app = QW.QApplication([])
2526
red = QG.QColor(QC.Qt.GlobalColor.red)
@@ -33,4 +34,7 @@
3334
editor.colormap_editor.update_colormap_widget()
3435
editor.colormap_editor.update_current_dataset()
3536
editor.show()
36-
# app.exec_()
37+
38+
39+
if __name__ == "__main__":
40+
test_colormap_manager()

0 commit comments

Comments
 (0)