Skip to content

Commit 83a2c7d

Browse files
committed
Improving UTs: refactoring start of TestMIANodeController.test_filter_widget
1 parent 8402e00 commit 83a2c7d

File tree

2 files changed

+83
-41
lines changed

2 files changed

+83
-41
lines changed

populse_mia/tests/run_mia_test.py

Lines changed: 66 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import subprocess
3636
import sys
3737
import tempfile
38+
import time
3839

3940
# import threading
4041
import unittest
@@ -68,6 +69,7 @@
6869
QModelIndex,
6970
QPoint,
7071
Qt,
72+
QTimer,
7173
qInstallMessageHandler,
7274
)
7375
from PyQt5.QtTest import QSignalSpy, QTest
@@ -319,36 +321,60 @@ class TestMIACase(unittest.TestCase):
319321
- tearDownClass: called after tests in the individual class
320322
"""
321323

322-
def add_visualized_tag(self, tag):
323-
"""With the "Visualized tags" pop-up open, selects a tag to display.
324+
def add_visualized_tag(self, input_filter, tag, timeout=5000):
325+
"""
326+
Selects a tag to display from the "Visualized tags" pop-up.
327+
328+
This method waits for the tag selection dialog to become available
329+
within the given timeout period, locates the specified tag in the
330+
tag list, selects it, and confirms the dialog.
324331
325-
- Should be called, with a delay, before opening the "Visualized tags"
326-
pop-up, i.e.:
327-
QTimer.singleShot(1000, lambda:self.add_visualized_tag(
328-
'AcquisitionDate'))
329-
It's currently not the case
330-
(see TestMIANodeController.test_filter_widget()).
332+
:param input_filter: The input filter containing the dialog
333+
with visualized tags.
334+
:param tag (str): The tag name to select and visualize.
335+
:param timeout (int): Maximum time to wait for the dialog to appear,
336+
in milliseconds. Defaults to 5000 ms.
331337
332-
:param tag: the tag to be displayed (str)
338+
:raises RuntimeError: If the dialog or visualized tags widget is
339+
not found.
340+
:raises ValueError: If the specified tag is not found in the list.
333341
"""
342+
start_time = time.time()
343+
timeout_secs = timeout / 1000
334344

335-
w = self._app.activeWindow()
345+
while time.time() - start_time < timeout_secs:
336346

337-
if isinstance(w, QDialog):
338-
visualized_tags = w.layout().itemAt(0).widget()
339-
tags_list = visualized_tags.list_widget_tags
347+
if getattr(input_filter, "dialog", None):
348+
break
340349

341-
if version.parse(QT_VERSION_STR) == version.parse("5.9.2"):
342-
found_item = tags_list.findItems(tag, Qt.MatchExactly)
350+
self._app.processEvents()
351+
time.sleep(0.01)
343352

344-
else:
345-
found_item = tags_list.findItems(
346-
tag, Qt.MatchFlag.MatchExactly
347-
)
353+
else:
354+
raise RuntimeError("Dialog not available")
348355

349-
tags_list.setCurrentItem(found_item[0])
350-
visualized_tags.click_select_tag()
351-
w.accept()
356+
dialog = input_filter.dialog
357+
visualized_tags = dialog.layout().itemAt(0).widget()
358+
359+
if not visualized_tags:
360+
raise RuntimeError(
361+
"PopUpVisualizedTags widget not found in dialog"
362+
)
363+
364+
tag_list_widget = visualized_tags.list_widget_tags
365+
match_flag = (
366+
Qt.MatchExactly
367+
if version.parse(QT_VERSION_STR) == version.parse("5.9.2")
368+
else Qt.MatchFlag.MatchExactly
369+
)
370+
matching_items = tag_list_widget.findItems(tag, match_flag)
371+
372+
if not matching_items:
373+
raise ValueError(f"Tag '{tag}' not found in the list")
374+
375+
tag_list_widget.setCurrentItem(matching_items[0])
376+
visualized_tags.click_select_tag()
377+
dialog.accept()
352378

353379
def clean_uts_packages(self, proc_lib_view):
354380
"""
@@ -7411,7 +7437,7 @@ def test_display_filter(self):
74117437
config = Config(properties_path=self.properties_path)
74127438
config.setControlV1(False)
74137439

7414-
@unittest.skip("skip this test until it has been repaired.")
7440+
# @unittest.skip("skip this test until it has been repaired.")
74157441
def test_filter_widget(self):
74167442
"""Places a node of the "Input_Filter" process, feeds in documents
74177443
and opens up the "FilterWidget()" to modify its parameters.
@@ -7480,7 +7506,7 @@ def test_filter_widget(self):
74807506
input_filter = ppl_edt_tabs.filter_widget
74817507

74827508
index_DOCUMENT_1 = input_filter.table_data.get_scan_row(DOCUMENT_1)
7483-
# index_DOCUMENT_2 = input_filter.table_data.get_scan_row(DOCUMENT_2)
7509+
index_DOCUMENT_2 = input_filter.table_data.get_scan_row(DOCUMENT_2)
74847510

74857511
# Tries to search for an empty string and asserts that none of the
74867512
# documents are hidden
@@ -7490,16 +7516,17 @@ def test_filter_widget(self):
74907516
# FIXME: Only for the Windows version, the method isRowHidden()
74917517
# does not seem to give the expected result. Waiting to look at
74927518
# this, we comment ..
7493-
# self.assertFalse(input_filter.table_data.isRowHidden(index_DOCUMENT_1))
7519+
self.assertFalse(input_filter.table_data.isRowHidden(index_DOCUMENT_1))
74947520
# Test "DOCUMENT_2" is not hidden
74957521
# FIXME: Only for the Windows version, the method isRowHidden()
74967522
# does not seem to give the expected result. Waiting to look at
74977523
# this, we comment ..
7498-
# self.assertFalse(input_filter.table_data.isRowHidden(index_DOCUMENT_2))
7524+
self.assertFalse(input_filter.table_data.isRowHidden(index_DOCUMENT_2))
74997525

75007526
# Searches for "DOCUMENT_2" and verifies that "DOCUMENT_1" is hidden
75017527
input_filter.search_str(DOCUMENT_2)
75027528
self.assertTrue(input_filter.table_data.isRowHidden(index_DOCUMENT_1))
7529+
self.assertFalse(input_filter.table_data.isRowHidden(index_DOCUMENT_2))
75037530

75047531
# Resets the search bar and assert that none of the documents
75057532
# are hidden
@@ -7509,29 +7536,35 @@ def test_filter_widget(self):
75097536
# FIXME: Only for the Windows version, the method isRowHidden()
75107537
# does not seem to give the expected result. Waiting to look at
75117538
# this, we comment ..
7512-
# self.assertFalse(input_filter.table_data.isRowHidden(index_DOCUMENT_1))
7539+
self.assertFalse(input_filter.table_data.isRowHidden(index_DOCUMENT_1))
75137540
# Test "DOCUMENT_1" is not hidden
75147541
# FIXME: Only for the Windows version, the method isRowHidden()
75157542
# does not seem to give the expected result. Waiting to look at
75167543
# this, we comment ..
7517-
# self.assertFalse(input_filter.table_data.isRowHidden(index_DOCUMENT_2))
7544+
self.assertFalse(input_filter.table_data.isRowHidden(index_DOCUMENT_2))
75187545

75197546
# Opens the "Visualized tags" pop up and adds the "AcquisitionDate" tag
75207547
# QTimer.singleShot(1000, lambda:self.add_visualized_tag(
75217548
# 'AcquisitionDate'))
7549+
QTimer.singleShot(
7550+
100,
7551+
lambda: self.add_visualized_tag(
7552+
input_filter, "AcquisitionDate", timeout=5000
7553+
),
7554+
)
75227555
input_filter.update_tags()
7523-
self.add_visualized_tag("AcquisitionDate")
7556+
# self.add_visualized_tag("AcquisitionDate")
75247557
# FIXME: The following statement is always True (not the correct test)
75257558
self.assertTrue(
75267559
type(input_filter.table_data.get_tag_column("AcquisitionDate"))
75277560
== int
75287561
)
75297562

75307563
# Updates the tag to filter with
7531-
# with patch.object(
7532-
# PopUpSelectTagCountTable, 'exec_', return_value=True
7533-
# ):
7534-
input_filter.update_tag_to_filter()
7564+
with patch.object(
7565+
PopUpSelectTagCountTable, "exec_", return_value=True
7566+
):
7567+
input_filter.update_tag_to_filter()
75357568

75367569
input_filter.push_button_tag_filter.setText(TAG_FILENAME)
75377570
# TODO: select tag to filter with

populse_mia/user_interface/pipeline_manager/node_controller.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,24 +1065,29 @@ def update_tag_to_filter(self):
10651065

10661066
def update_tags(self):
10671067
"""Update the list of visualized tags."""
1068-
dialog = QDialog()
1068+
1069+
if hasattr(self, "dialog") and self.dialog:
1070+
self.dialog.deleteLater()
1071+
self.dialog = None
1072+
1073+
self.dialog = QDialog()
10691074
visualized_tags = PopUpVisualizedTags(self.project, self.visible_tags)
10701075
layout = QVBoxLayout()
10711076
layout.addWidget(visualized_tags)
10721077
buttons_layout = QHBoxLayout()
10731078
buttons = QDialogButtonBox(
10741079
QDialogButtonBox.Ok | QDialogButtonBox.Cancel
10751080
)
1076-
buttons.accepted.connect(dialog.accept)
1077-
buttons.rejected.connect(dialog.reject)
1081+
buttons.accepted.connect(self.dialog.accept)
1082+
buttons.rejected.connect(self.dialog.reject)
10781083
buttons_layout.addWidget(buttons)
10791084
layout.addLayout(buttons_layout)
1080-
dialog.setLayout(layout)
1081-
dialog.show()
1082-
dialog.setMinimumHeight(600)
1083-
dialog.setMinimumWidth(600)
1085+
self.dialog.setLayout(layout)
1086+
self.dialog.show()
1087+
self.dialog.setMinimumHeight(600)
1088+
self.dialog.setMinimumWidth(600)
10841089

1085-
if dialog.exec():
1090+
if self.dialog.exec():
10861091
new_visibilities = []
10871092

10881093
for x in range(visualized_tags.list_widget_selected_tags.count()):
@@ -1107,6 +1112,10 @@ def update_tags(self):
11071112
fields.model().sort(0)
11081113
fields.addItem("All visualized tags")
11091114

1115+
# Clean up the dialog reference at the end
1116+
self.dialog.deleteLater()
1117+
self.dialog = None
1118+
11101119

11111120
# Node controller V1 style
11121121
class NodeController(QWidget):

0 commit comments

Comments
 (0)