settings.py
1 """Tests for PyBitmessage settings""" 2 import threading 3 import time 4 5 from PyQt4 import QtCore, QtGui, QtTest 6 7 from bmconfigparser import config 8 from bitmessageqt import settings 9 10 from .main import TestBase 11 12 13 class TestSettings(TestBase): 14 """A test case for the "Settings" dialog""" 15 def setUp(self): 16 super(TestSettings, self).setUp() 17 self.dialog = settings.SettingsDialog(self.window) 18 19 def test_udp(self): 20 """Test the effect of checkBoxUDP""" 21 udp_setting = config.safeGetBoolean('bitmessagesettings', 'udp') 22 self.assertEqual(udp_setting, self.dialog.checkBoxUDP.isChecked()) 23 self.dialog.checkBoxUDP.setChecked(not udp_setting) 24 self.dialog.accept() 25 self.assertEqual( 26 not udp_setting, 27 config.safeGetBoolean('bitmessagesettings', 'udp')) 28 time.sleep(5) 29 for thread in threading.enumerate(): 30 if thread.name == 'Announcer': # find Announcer thread 31 if udp_setting: 32 self.fail( 33 'Announcer thread is running while udp set to False') 34 break 35 else: 36 if not udp_setting: 37 self.fail('No Announcer thread found while udp set to True') 38 39 def test_styling(self): 40 """Test custom windows style and font""" 41 style_setting = config.safeGet('bitmessagesettings', 'windowstyle') 42 font_setting = config.safeGet('bitmessagesettings', 'font') 43 self.assertIs(style_setting, None) 44 self.assertIs(font_setting, None) 45 style_control = self.dialog.comboBoxStyle 46 self.assertEqual( 47 style_control.currentText(), self.app.get_windowstyle()) 48 49 def call_font_dialog(): 50 """A function to get the open font dialog and accept it""" 51 font_dialog = QtGui.QApplication.activeModalWidget() 52 self.assertTrue(isinstance(font_dialog, QtGui.QFontDialog)) 53 selected_font = font_dialog.currentFont() 54 self.assertEqual( 55 config.safeGet('bitmessagesettings', 'font'), '{},{}'.format( 56 selected_font.family(), selected_font.pointSize())) 57 58 font_dialog.accept() 59 self.dialog.accept() 60 self.assertEqual( 61 config.safeGet('bitmessagesettings', 'windowstyle'), 62 style_control.currentText()) 63 64 def click_font_button(): 65 """Use QtTest to click the button""" 66 QtTest.QTest.mouseClick( 67 self.dialog.buttonFont, QtCore.Qt.LeftButton) 68 69 style_count = style_control.count() 70 self.assertGreater(style_count, 1) 71 for i in range(style_count): 72 if i != style_control.currentIndex(): 73 style_control.setCurrentIndex(i) 74 break 75 76 QtCore.QTimer.singleShot(30, click_font_button) 77 QtCore.QTimer.singleShot(60, call_font_dialog) 78 time.sleep(2)