source: sasview/src/sas/qtgui/UnitTesting/TestUtilsTest.py @ 4a9786d8

Last change on this file since 4a9786d8 was 464cd07, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Use singleton QApplication in unit tests to avoid issues on Ubuntu. SASVIEW-485

  • Property mode set to 100644
File size: 1.1 KB
Line 
1import sys
2import unittest
3
4from PyQt4.QtGui import *
5from PyQt4.QtTest import QTest
6from PyQt4.QtCore import *
7from mock import MagicMock
8
9# Local
10from sas.qtgui.Utilities.GuiUtils import Communicate
11from sas.qtgui.UnitTesting.TestUtils import *
12
13if not QApplication.instance():
14    app = QApplication(sys.argv)
15
16class TestUtilsTest(unittest.TestCase):
17    '''Test TestUtils'''
18
19    def testQtSignalSpy(self):
20        '''Create the Spy the correct way'''
21        test_string = 'my precious'
22
23        def signalReceived(signal):
24            # Test the signal callback
25            self.assertEqual(signal, test_string)
26
27        communicator = Communicate()
28        communicator.statusBarUpdateSignal.connect(signalReceived)
29
30        # Define the signal spy for testing
31        widget = QWidget()
32        spy = QtSignalSpy(widget, communicator.statusBarUpdateSignal)
33
34        # Emit a signal
35        communicator.statusBarUpdateSignal.emit(test_string)
36
37        # Was the signal caught by the signal spy?
38        self.assertEqual(spy.count(), 1)
39
40if __name__ == "__main__":
41    unittest.main()
Note: See TracBrowser for help on using the repository browser.