source: sasview/src/sas/qtgui/UnitTesting/TestUtilsTest.py @ 03e04a4

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 03e04a4 was 53c771e, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Converted unit tests

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