ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change
on this file since 9909967 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.6 KB
|
Line | |
---|
1 | import sys |
---|
2 | import unittest |
---|
3 | |
---|
4 | from PyQt4 import QtGui |
---|
5 | from PyQt4 import QtTest |
---|
6 | from PyQt4 import QtCore |
---|
7 | from mock import MagicMock |
---|
8 | |
---|
9 | # set up import paths |
---|
10 | import path_prepare |
---|
11 | |
---|
12 | # Local |
---|
13 | from sas.qtgui.MainWindow.MainWindow import MainSasViewWindow |
---|
14 | from sas.qtgui.MainWindow.MainWindow import SplashScreen |
---|
15 | |
---|
16 | if not QtGui.QApplication.instance(): |
---|
17 | app = QtGui.QApplication(sys.argv) |
---|
18 | |
---|
19 | class MainWindowTest(unittest.TestCase): |
---|
20 | """Test the Main Window GUI""" |
---|
21 | def setUp(self): |
---|
22 | """Create the GUI""" |
---|
23 | |
---|
24 | self.widget = MainSasViewWindow(None) |
---|
25 | |
---|
26 | def tearDown(self): |
---|
27 | """Destroy the GUI""" |
---|
28 | self.widget = None |
---|
29 | |
---|
30 | def testDefaults(self): |
---|
31 | """Test the GUI in its default state""" |
---|
32 | self.assertIsInstance(self.widget, QtGui.QMainWindow) |
---|
33 | self.assertIsInstance(self.widget.centralWidget(), QtGui.QWorkspace) |
---|
34 | |
---|
35 | def testSplashScreen(self): |
---|
36 | """ Test the splash screen """ |
---|
37 | splash = SplashScreen() |
---|
38 | self.assertIsInstance(splash, QtGui.QSplashScreen) |
---|
39 | |
---|
40 | def testExit(self): |
---|
41 | """ |
---|
42 | Test that the custom exit method is called on shutdown |
---|
43 | """ |
---|
44 | # Must mask sys.exit, otherwise the whole testing process stops. |
---|
45 | sys.exit = MagicMock() |
---|
46 | QtGui.QMessageBox.question = MagicMock(return_value=QtGui.QMessageBox.Yes) |
---|
47 | |
---|
48 | # Open, then close the main window |
---|
49 | tmp_main = MainSasViewWindow(None) |
---|
50 | tmp_main.close() |
---|
51 | |
---|
52 | # See that the MessageBox method got called |
---|
53 | self.assertTrue(QtGui.QMessageBox.question.called) |
---|
54 | |
---|
55 | if __name__ == "__main__": |
---|
56 | unittest.main() |
---|
Note: See
TracBrowser
for help on using the repository browser.