Last change
on this file since b2c8aef 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 | |
---|
1 | import sys |
---|
2 | import unittest |
---|
3 | |
---|
4 | from PyQt4.QtGui import * |
---|
5 | from PyQt4.QtTest import QTest |
---|
6 | from PyQt4.QtCore import * |
---|
7 | from mock import MagicMock |
---|
8 | |
---|
9 | # Local |
---|
10 | from sas.qtgui.Utilities.GuiUtils import Communicate |
---|
11 | from sas.qtgui.UnitTesting.TestUtils import * |
---|
12 | |
---|
13 | if not QApplication.instance(): |
---|
14 | app = QApplication(sys.argv) |
---|
15 | |
---|
16 | class 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 | |
---|
40 | if __name__ == "__main__": |
---|
41 | unittest.main() |
---|
Note: See
TracBrowser
for help on using the repository browser.