diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2025-07-07 08:46:46 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2025-07-09 10:36:33 +0200 |
| commit | aec72ac51d8c8649b252622ea316b8dd0bcd1ad7 (patch) | |
| tree | 965079bf5833eb53582656f7e947eedeb3d81692 /sources/pyside6/tests | |
| parent | 0c4e02bcc990e98ffe9ba882ae0bd9ddfe523c85 (diff) | |
Speed up QtWidgets tests testing QDialog
Use the timer logic introduced for qfontdialog to close the dialog.
Reduces test time from 0.984s to 0.073s.
Pick-to: 6.9 6.8
Change-Id: I5ac1dd8da9f2b814ccea4ea9a8fddb03395620c9
Reviewed-by: Ece Cinucen <ece.cinucen@qt.io>
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'sources/pyside6/tests')
| -rw-r--r-- | sources/pyside6/tests/QtWidgets/qdialog_test.py | 26 | ||||
| -rw-r--r-- | sources/pyside6/tests/QtWidgets/qinputdialog_get_test.py | 33 |
2 files changed, 49 insertions, 10 deletions
diff --git a/sources/pyside6/tests/QtWidgets/qdialog_test.py b/sources/pyside6/tests/QtWidgets/qdialog_test.py index 6d36dfb20..c75f2eb8e 100644 --- a/sources/pyside6/tests/QtWidgets/qdialog_test.py +++ b/sources/pyside6/tests/QtWidgets/qdialog_test.py @@ -13,15 +13,28 @@ from init_paths import init_test_paths init_test_paths(False) from PySide6.QtCore import Slot, QTimer -from PySide6.QtWidgets import QDialog, QMainWindow +from PySide6.QtWidgets import QApplication, QDialog, QMainWindow from helper.timedqapplication import TimedQApplication +def is_exposed(widget): + result = False + if widget.isVisible(): + handle = widget.windowHandle() + if handle: + result = handle.isExposed() + return result + + class Window(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("Main") self.dialog = None + self._timer = QTimer() + self._timer.setInterval(50) + self._timer.timeout.connect(self._timer_handler) + self._timer.start() @Slot() def execDialog(self): @@ -33,6 +46,13 @@ class Window(QMainWindow): dialog.exec() self.close() + @Slot() + def _timer_handler(self): + """Periodically check for the dialog to appear and close it.""" + for widget in QApplication.topLevelWidgets(): + if isinstance(widget, QDialog) and is_exposed(widget): + widget.reject() + class DialogExecTest(TimedQApplication): """Test whether the parent-child relationship (dialog/main window) is removed when @@ -44,7 +64,9 @@ class DialogExecTest(TimedQApplication): def testExec(self): self._window.show() - QTimer.singleShot(500, self._window.execDialog) + while not is_exposed(self._window): + QApplication.processEvents() + QTimer.singleShot(0, self._window.execDialog) self.app.exec() self.assertTrue(self._window.dialog() is None) diff --git a/sources/pyside6/tests/QtWidgets/qinputdialog_get_test.py b/sources/pyside6/tests/QtWidgets/qinputdialog_get_test.py index fa6455f14..32ee4857e 100644 --- a/sources/pyside6/tests/QtWidgets/qinputdialog_get_test.py +++ b/sources/pyside6/tests/QtWidgets/qinputdialog_get_test.py @@ -16,29 +16,46 @@ from PySide6.QtWidgets import QApplication, QInputDialog, QDialog from helper.usesqapplication import UsesQApplication -def close_dialog(): - for w in QApplication.topLevelWidgets(): - if isinstance(w, QDialog): - w.reject() +def is_exposed(widget): + result = False + if widget.isVisible(): + handle = widget.windowHandle() + if handle: + result = handle.isExposed() + return result class TestInputDialog(UsesQApplication): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self._timer = None + + def setUp(self): + super().setUp() + if not self._timer: + self._timer = QTimer() + self._timer.setInterval(50) + self._timer.timeout.connect(self._timer_handler) + self._timer.start() + + def _timer_handler(self): + """Periodically check for the dialog to appear and close it.""" + for widget in QApplication.topLevelWidgets(): + if isinstance(widget, QDialog) and is_exposed(widget): + widget.reject() + def testGetDouble(self): - QTimer.singleShot(500, close_dialog) self.assertEqual(QInputDialog.getDouble(None, "title", "label"), (0.0, False)) def testGetInt(self): - QTimer.singleShot(500, close_dialog) self.assertEqual(QInputDialog.getInt(None, "title", "label"), (0, False)) def testGetItem(self): - QTimer.singleShot(500, close_dialog) (item, bool) = QInputDialog.getItem(None, "title", "label", ["1", "2", "3"]) self.assertEqual(str(item), "1") def testGetText(self): - QTimer.singleShot(500, close_dialog) (text, bool) = QInputDialog.getText(None, "title", "label") self.assertEqual(str(text), "") |
