Last change
on this file since f159d1b 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
|
Rev | Line | |
---|
[488c49d] | 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 |
---|
[83eb5208] | 10 | from sas.qtgui.Utilities.GuiUtils import Communicate |
---|
| 11 | from sas.qtgui.UnitTesting.TestUtils import * |
---|
[488c49d] | 12 | |
---|
[464cd07] | 13 | if not QApplication.instance(): |
---|
| 14 | app = QApplication(sys.argv) |
---|
[488c49d] | 15 | |
---|
| 16 | class 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 | |
---|
| 40 | if __name__ == "__main__": |
---|
| 41 | unittest.main() |
---|
Note: See
TracBrowser
for help on using the repository browser.