source: sasview/src/sas/qtgui/UnitTesting/TestUtilsTest.py @ 6b43c58

Last change on this file since 6b43c58 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
RevLine 
[488c49d]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
[83eb5208]10from sas.qtgui.Utilities.GuiUtils import Communicate
11from sas.qtgui.UnitTesting.TestUtils import *
[488c49d]12
[464cd07]13if not QApplication.instance():
14    app = QApplication(sys.argv)
[488c49d]15
16class TestUtilsTest(unittest.TestCase):
17    '''Test TestUtils'''
18
19    def testQtSignalSpy(self):
20        '''Create the Spy the correct way'''
[5032ea68]21        test_string = 'my precious'
[488c49d]22
[5032ea68]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
[488c49d]31        widget = QWidget()
[5032ea68]32        spy = QtSignalSpy(widget, communicator.statusBarUpdateSignal)
[488c49d]33
34        # Emit a signal
[5032ea68]35        communicator.statusBarUpdateSignal.emit(test_string)
[488c49d]36
[5032ea68]37        # Was the signal caught by the signal spy?
38        self.assertEqual(spy.count(), 1)
[488c49d]39
40if __name__ == "__main__":
41    unittest.main()
Note: See TracBrowser for help on using the repository browser.