35
35
import subprocess
36
36
import sys
37
37
import tempfile
38
+ import time
38
39
39
40
# import threading
40
41
import unittest
68
69
QModelIndex ,
69
70
QPoint ,
70
71
Qt ,
72
+ QTimer ,
71
73
qInstallMessageHandler ,
72
74
)
73
75
from PyQt5 .QtTest import QSignalSpy , QTest
@@ -319,36 +321,60 @@ class TestMIACase(unittest.TestCase):
319
321
- tearDownClass: called after tests in the individual class
320
322
"""
321
323
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.
324
331
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.
331
337
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.
333
341
"""
342
+ start_time = time .time ()
343
+ timeout_secs = timeout / 1000
334
344
335
- w = self . _app . activeWindow ()
345
+ while time . time () - start_time < timeout_secs :
336
346
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
340
349
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 )
343
352
344
- else :
345
- found_item = tags_list .findItems (
346
- tag , Qt .MatchFlag .MatchExactly
347
- )
353
+ else :
354
+ raise RuntimeError ("Dialog not available" )
348
355
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 ()
352
378
353
379
def clean_uts_packages (self , proc_lib_view ):
354
380
"""
@@ -7411,7 +7437,7 @@ def test_display_filter(self):
7411
7437
config = Config (properties_path = self .properties_path )
7412
7438
config .setControlV1 (False )
7413
7439
7414
- @unittest .skip ("skip this test until it has been repaired." )
7440
+ # @unittest.skip("skip this test until it has been repaired.")
7415
7441
def test_filter_widget (self ):
7416
7442
"""Places a node of the "Input_Filter" process, feeds in documents
7417
7443
and opens up the "FilterWidget()" to modify its parameters.
@@ -7480,7 +7506,7 @@ def test_filter_widget(self):
7480
7506
input_filter = ppl_edt_tabs .filter_widget
7481
7507
7482
7508
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 )
7484
7510
7485
7511
# Tries to search for an empty string and asserts that none of the
7486
7512
# documents are hidden
@@ -7490,16 +7516,17 @@ def test_filter_widget(self):
7490
7516
# FIXME: Only for the Windows version, the method isRowHidden()
7491
7517
# does not seem to give the expected result. Waiting to look at
7492
7518
# 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 ))
7494
7520
# Test "DOCUMENT_2" is not hidden
7495
7521
# FIXME: Only for the Windows version, the method isRowHidden()
7496
7522
# does not seem to give the expected result. Waiting to look at
7497
7523
# 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 ))
7499
7525
7500
7526
# Searches for "DOCUMENT_2" and verifies that "DOCUMENT_1" is hidden
7501
7527
input_filter .search_str (DOCUMENT_2 )
7502
7528
self .assertTrue (input_filter .table_data .isRowHidden (index_DOCUMENT_1 ))
7529
+ self .assertFalse (input_filter .table_data .isRowHidden (index_DOCUMENT_2 ))
7503
7530
7504
7531
# Resets the search bar and assert that none of the documents
7505
7532
# are hidden
@@ -7509,29 +7536,35 @@ def test_filter_widget(self):
7509
7536
# FIXME: Only for the Windows version, the method isRowHidden()
7510
7537
# does not seem to give the expected result. Waiting to look at
7511
7538
# 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 ))
7513
7540
# Test "DOCUMENT_1" is not hidden
7514
7541
# FIXME: Only for the Windows version, the method isRowHidden()
7515
7542
# does not seem to give the expected result. Waiting to look at
7516
7543
# 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 ))
7518
7545
7519
7546
# Opens the "Visualized tags" pop up and adds the "AcquisitionDate" tag
7520
7547
# QTimer.singleShot(1000, lambda:self.add_visualized_tag(
7521
7548
# 'AcquisitionDate'))
7549
+ QTimer .singleShot (
7550
+ 100 ,
7551
+ lambda : self .add_visualized_tag (
7552
+ input_filter , "AcquisitionDate" , timeout = 5000
7553
+ ),
7554
+ )
7522
7555
input_filter .update_tags ()
7523
- self .add_visualized_tag ("AcquisitionDate" )
7556
+ # self.add_visualized_tag("AcquisitionDate")
7524
7557
# FIXME: The following statement is always True (not the correct test)
7525
7558
self .assertTrue (
7526
7559
type (input_filter .table_data .get_tag_column ("AcquisitionDate" ))
7527
7560
== int
7528
7561
)
7529
7562
7530
7563
# 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 ()
7535
7568
7536
7569
input_filter .push_button_tag_filter .setText (TAG_FILENAME )
7537
7570
# TODO: select tag to filter with
0 commit comments