diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2025-07-03 13:47:56 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2025-07-09 10:36:18 +0200 |
| commit | 0c4e02bcc990e98ffe9ba882ae0bd9ddfe523c85 (patch) | |
| tree | 6a438a1f3f376c26451d2173fd8c258c6f588561 /sources/pyside6/tests | |
| parent | 481b48982752f492ad99c6bb3d3f66788095a72b (diff) | |
QtWidgets test qfontdialog_test.py: Fix the test to run
Disable native dialogs and add a timer closing the widget opened by
the static getFont() function. With that. the test can enabled.
Pick-to: 6.9 6.8
Change-Id: Iee9b0a341aa13527f5edcb10fd2188d111cee841
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Reviewed-by: Ece Cinucen <ece.cinucen@qt.io>
Diffstat (limited to 'sources/pyside6/tests')
| -rw-r--r-- | sources/pyside6/tests/QtWidgets/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | sources/pyside6/tests/QtWidgets/qfontdialog_test.py | 39 |
2 files changed, 34 insertions, 8 deletions
diff --git a/sources/pyside6/tests/QtWidgets/CMakeLists.txt b/sources/pyside6/tests/QtWidgets/CMakeLists.txt index 9bb2fad67..57d8c5c9d 100644 --- a/sources/pyside6/tests/QtWidgets/CMakeLists.txt +++ b/sources/pyside6/tests/QtWidgets/CMakeLists.txt @@ -87,8 +87,7 @@ PYSIDE_TEST(qapplication_exit_segfault_test.py) PYSIDE_TEST(pyside3069.py) PYSIDE_TEST(qdialog_test.py) PYSIDE_TEST(qdynamic_signal.py) -# TODO: This passes, but requires manual button clicking (at least on mac) -#PYSIDE_TEST(qfontdialog_test.py) +PYSIDE_TEST(qfontdialog_test.py) PYSIDE_TEST(qformlayout_test.py) PYSIDE_TEST(qgraphicsitem_test.py) PYSIDE_TEST(qgraphicsitem_isblocked_test.py) diff --git a/sources/pyside6/tests/QtWidgets/qfontdialog_test.py b/sources/pyside6/tests/QtWidgets/qfontdialog_test.py index dd4209d10..d9868a9eb 100644 --- a/sources/pyside6/tests/QtWidgets/qfontdialog_test.py +++ b/sources/pyside6/tests/QtWidgets/qfontdialog_test.py @@ -11,21 +11,48 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) +from PySide6.QtCore import QTimer from PySide6.QtGui import QFont -from PySide6.QtWidgets import QFontDialog +from PySide6.QtWidgets import QApplication, QDialog, QFontDialog 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 TestFontDialog(TimedQApplication): - def testGetFont(self): - QFontDialog.getFont() + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self._timer = None + + def setUp(self, timeout=100): + super().setUp(timeout) + if not self._timer: + self._timer = QTimer() + self._timer.setInterval(50) + self._timer.timeout.connect(self._timer_handler) + self._timer.start() - def testGetFontQDialog(self): - QFontDialog.getFont(QFont("FreeSans", 10)) + 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.accept() def testGetFontQDialogQString(self): - QFontDialog.getFont(QFont("FreeSans", 10), None, "Select font") + r = QFontDialog.getFont(QFont("FreeSans", 10), None, "Select font", + QFontDialog.FontDialogOption.DontUseNativeDialog) + self.assertTrue(type(r) is tuple) + self.assertEqual(len(r), 2) + self.assertTrue(r[0]) + self.assertTrue(type(r[1]) is QFont) if __name__ == '__main__': |
