Skip to content

Commit f497555

Browse files
committed
tests: basic gui test
1 parent 98b4faa commit f497555

File tree

5 files changed

+111
-6
lines changed

5 files changed

+111
-6
lines changed

shapeout2/gui/main.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,16 @@ def adopt_slot(self, slot_state):
278278
raise ValueError("Slot not in pipeline: {}".format(slot_id))
279279
self.adopt_pipeline(state)
280280

281-
def add_dataslot(self):
281+
def add_dataslot(self, paths=None):
282282
"""Adds a dataslot to the pipeline"""
283-
fnames, _ = QtWidgets.QFileDialog.getOpenFileNames(
284-
parent=self,
285-
caption="Select an RT-DC measurement",
286-
directory=self.settings.get_path(name="rtdc import dataset"),
287-
filter="RT-DC Files (*.rtdc)")
283+
if paths is None:
284+
fnames, _ = QtWidgets.QFileDialog.getOpenFileNames(
285+
parent=self,
286+
caption="Select an RT-DC measurement",
287+
directory=self.settings.get_path(name="rtdc import dataset"),
288+
filter="RT-DC Files (*.rtdc)")
289+
else:
290+
fnames = paths
288291

289292
if fnames:
290293
self.toolButton_new_plot.setEnabled(True)

shapeout2/gui/matrix/block_matrix.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,45 @@ def __setstate__(self, state):
5050
def adopt_pipeline(self, pipeline_state):
5151
self.__setstate__(pipeline_state)
5252

53+
def get_widget(self, slot_id=None, filt_plot_id=None):
54+
"""Convenience function for testing"""
55+
if slot_id is None and filt_plot_id is not None:
56+
# get a filter or a plot
57+
w = self.data_matrix.filter_widgets + self.plot_matrix.plot_widgets
58+
for wi in w:
59+
if wi.identifier == filt_plot_id:
60+
break
61+
else:
62+
raise KeyError(
63+
"Widget identifier '{}' not found!".format(filt_plot_id))
64+
return wi
65+
elif slot_id is not None and filt_plot_id is None:
66+
# get a slot
67+
for wi in self.data_matrix.dataset_widgets:
68+
if wi.identifier == slot_id:
69+
break
70+
else:
71+
raise KeyError(
72+
"Widget identifier '{}' not found!".format(filt_plot_id))
73+
return wi
74+
elif slot_id is not None and filt_plot_id is not None:
75+
# get a matrix element
76+
wd = self.data_matrix.element_widget_dict
77+
wp = self.plot_matrix.element_widget_dict
78+
fpd = wd[slot_id]
79+
fpp = wp[slot_id]
80+
if filt_plot_id in fpp:
81+
wi = fpp[filt_plot_id]
82+
elif filt_plot_id in fpd:
83+
wi = fpd[filt_plot_id]
84+
else:
85+
raise KeyError(
86+
"Widget identifier '{}' not found!".format(filt_plot_id))
87+
return wi
88+
else:
89+
raise ValueError(
90+
"One of `slot_id` or `filt_plot_id` must be specified!")
91+
5392
def invalidate_elements(self, invalid_dm, invalid_pm):
5493
for slot_id, filt_id in invalid_dm:
5594
em = self.data_matrix.get_matrix_element(slot_id, filt_id)

shapeout2/gui/matrix/data_matrix.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,17 @@ def element_width(self):
158158
width = 67
159159
return width
160160

161+
@property
162+
def element_widget_dict(self):
163+
els = {}
164+
for ii, ws in enumerate(self.dataset_widgets):
165+
elsd = {}
166+
for jj, wf in enumerate(self.filter_widgets):
167+
it = self.glo.itemAtPosition(ii+1, jj+1)
168+
elsd[wf.identifier] = it.widget()
169+
els[ws.identifier] = elsd
170+
return els
171+
161172
@property
162173
def filter_widgets(self):
163174
filters = []

shapeout2/gui/matrix/plot_matrix.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ def data_matrix(self):
9090
raise KeyError("DataMatrix not found!")
9191
return ch
9292

93+
@property
94+
def element_widget_dict(self):
95+
els = {}
96+
for ii, ws in enumerate(self.data_matrix.dataset_widgets):
97+
elsd = {}
98+
for jj, wf in enumerate(self.plot_widgets):
99+
it = self.glo.itemAtPosition(ii+1, jj)
100+
elsd[wf.identifier] = it.widget()
101+
els[ws.identifier] = elsd
102+
return els
103+
93104
@property
94105
def element_width(self):
95106
"""Data matrix element width (without 2px spacing)"""

tests/test_gui_basic.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""Test of data set functionalities"""
2+
import pathlib
3+
4+
from PyQt5 import QtCore
5+
6+
from shapeout2.gui.main import ShapeOut2
7+
8+
9+
def test_simple(qtbot):
10+
"""Open the main window and close it again"""
11+
main_window = ShapeOut2()
12+
main_window.close()
13+
14+
15+
def test_matrix_slots(qtbot):
16+
mw = ShapeOut2()
17+
qtbot.addWidget(mw)
18+
19+
# add a dataslot
20+
path = pathlib.Path(__file__).parent / "data" / "calibration_beads_47.rtdc"
21+
mw.add_dataslot(paths=[path])
22+
# add another one
23+
mw.add_dataslot(paths=[path])
24+
25+
assert len(mw.pipeline.slot_ids) == 2, "we added those"
26+
assert len(mw.pipeline.filter_ids) == 1, "automatically added"
27+
28+
# activate a dataslot
29+
slot_id = mw.pipeline.slot_ids[0]
30+
filt_id = mw.pipeline.filter_ids[0]
31+
em = mw.block_matrix.get_widget(slot_id, filt_id)
32+
qtbot.mouseClick(em, QtCore.Qt.LeftButton)
33+
# did that work?
34+
assert mw.pipeline.is_element_active(slot_id, filt_id)
35+
slot_id2 = mw.pipeline.slot_ids[1]
36+
assert not mw.pipeline.is_element_active(slot_id2, filt_id)
37+
38+
# remove a dataslot
39+
wd = mw.block_matrix.get_widget(slot_id=slot_id)
40+
wd.action_remove()
41+
assert not mw.pipeline.is_element_active(slot_id2, filt_id)

0 commit comments

Comments
 (0)