From c3c41902cf0f05d570d34ea12b1b97c58f5af482 Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Wed, 8 May 2024 01:01:39 +0300 Subject: [PATCH] Use QtTest and QTimer.singleShot() to check the font dialog --- src/bitmessageqt/tests/settings.py | 34 +++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/bitmessageqt/tests/settings.py b/src/bitmessageqt/tests/settings.py index 3c14183f..170f8f40 100644 --- a/src/bitmessageqt/tests/settings.py +++ b/src/bitmessageqt/tests/settings.py @@ -2,10 +2,13 @@ import threading import time -from main import TestBase +from PyQt4 import QtCore, QtGui, QtTest + from bmconfigparser import config from bitmessageqt import settings +from .main import TestBase + class TestSettings(TestBase): """A test case for the "Settings" dialog""" @@ -41,13 +44,34 @@ class TestSettings(TestBase): self.assertIs(font_setting, None) style_control = self.dialog.comboBoxStyle self.assertEqual(style_control.currentText(), 'GTK+') + + def call_font_dialog(): + """A function to get the open font dialog and accept it""" + font_dialog = QtGui.QApplication.activeModalWidget() + self.assertTrue(isinstance(font_dialog, QtGui.QFontDialog)) + selected_font = font_dialog.currentFont() + self.assertEqual( + config.safeGet('bitmessagesettings', 'font'), '{},{}'.format( + selected_font.family(), selected_font.pointSize())) + + font_dialog.accept() + self.dialog.accept() + self.assertEqual( + config.safeGet('bitmessagesettings', 'windowstyle'), + style_control.currentText()) + + def click_font_button(): + """Use QtTest to click the button""" + QtTest.QTest.mouseClick( + self.dialog.buttonFont, QtCore.Qt.LeftButton) + style_count = style_control.count() self.assertGreater(style_count, 1) for i in range(style_count): if i != style_control.currentIndex(): style_control.setCurrentIndex(i) break - self.dialog.accept() - self.assertEqual( - config.safeGet('bitmessagesettings', 'windowstyle'), - style_control.currentText()) + + QtCore.QTimer.singleShot(30, click_font_button) + QtCore.QTimer.singleShot(60, call_font_dialog) + time.sleep(2)