Skip to content

Commit c3c4190

Browse files
author
Lee Miller
committed
Use QtTest and QTimer.singleShot() to check the font dialog
1 parent d46af08 commit c3c4190

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

src/bitmessageqt/tests/settings.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
import threading
33
import time
44

5-
from main import TestBase
5+
from PyQt4 import QtCore, QtGui, QtTest
6+
67
from bmconfigparser import config
78
from bitmessageqt import settings
89

10+
from .main import TestBase
11+
912

1013
class TestSettings(TestBase):
1114
"""A test case for the "Settings" dialog"""
@@ -41,13 +44,34 @@ def test_styling(self):
4144
self.assertIs(font_setting, None)
4245
style_control = self.dialog.comboBoxStyle
4346
self.assertEqual(style_control.currentText(), 'GTK+')
47+
48+
def call_font_dialog():
49+
"""A function to get the open font dialog and accept it"""
50+
font_dialog = QtGui.QApplication.activeModalWidget()
51+
self.assertTrue(isinstance(font_dialog, QtGui.QFontDialog))
52+
selected_font = font_dialog.currentFont()
53+
self.assertEqual(
54+
config.safeGet('bitmessagesettings', 'font'), '{},{}'.format(
55+
selected_font.family(), selected_font.pointSize()))
56+
57+
font_dialog.accept()
58+
self.dialog.accept()
59+
self.assertEqual(
60+
config.safeGet('bitmessagesettings', 'windowstyle'),
61+
style_control.currentText())
62+
63+
def click_font_button():
64+
"""Use QtTest to click the button"""
65+
QtTest.QTest.mouseClick(
66+
self.dialog.buttonFont, QtCore.Qt.LeftButton)
67+
4468
style_count = style_control.count()
4569
self.assertGreater(style_count, 1)
4670
for i in range(style_count):
4771
if i != style_control.currentIndex():
4872
style_control.setCurrentIndex(i)
4973
break
50-
self.dialog.accept()
51-
self.assertEqual(
52-
config.safeGet('bitmessagesettings', 'windowstyle'),
53-
style_control.currentText())
74+
75+
QtCore.QTimer.singleShot(30, click_font_button)
76+
QtCore.QTimer.singleShot(60, call_font_dialog)
77+
time.sleep(2)

0 commit comments

Comments
 (0)