source:
sasview/src/sas/qtgui/MainWindow/UnitTesting/MainWindowTest.py
@
1ba88515
Last change on this file since 1ba88515 was 53c771e, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago | |
---|---|
|
|
File size: 1.7 KB |
Rev | Line | |
---|---|---|
[f721030] | 1 | import sys |
2 | import unittest | |
[53c771e] | 3 | import logging |
[f721030] | 4 | |
[53c771e] | 5 | from PyQt5 import QtGui, QtWidgets |
6 | from PyQt5 import QtTest | |
7 | from PyQt5 import QtCore | |
[7fb471d] | 8 | from unittest.mock import MagicMock |
[f721030] | 9 | |
[31c5b58] | 10 | # set up import paths |
11 | import path_prepare | |
12 | ||
[f721030] | 13 | # Local |
[83eb5208] | 14 | from sas.qtgui.MainWindow.MainWindow import MainSasViewWindow |
15 | from sas.qtgui.MainWindow.MainWindow import SplashScreen | |
[53c771e] | 16 | from sas.qtgui.MainWindow.GuiManager import GuiManager |
[f721030] | 17 | |
[53c771e] | 18 | if not QtWidgets.QApplication.instance(): |
19 | app = QtWidgets.QApplication(sys.argv) | |
[f721030] | 20 | |
21 | class MainWindowTest(unittest.TestCase): | |
[9e426c1] | 22 | """Test the Main Window GUI""" |
[f721030] | 23 | def setUp(self): |
[9e426c1] | 24 | """Create the GUI""" |
[f721030] | 25 | |
26 | self.widget = MainSasViewWindow(None) | |
27 | ||
28 | def tearDown(self): | |
[9e426c1] | 29 | """Destroy the GUI""" |
[f721030] | 30 | self.widget = None |
31 | ||
32 | def testDefaults(self): | |
[9e426c1] | 33 | """Test the GUI in its default state""" |
[53c771e] | 34 | self.assertIsInstance(self.widget, QtWidgets.QMainWindow) |
35 | self.assertIsInstance(self.widget.centralWidget(), QtWidgets.QMdiArea) | |
[f721030] | 36 | |
37 | def testSplashScreen(self): | |
[9e426c1] | 38 | """ Test the splash screen """ |
39 | splash = SplashScreen() | |
[53c771e] | 40 | self.assertIsInstance(splash, QtWidgets.QSplashScreen) |
[9e426c1] | 41 | |
42 | def testExit(self): | |
[f721030] | 43 | """ |
[9e426c1] | 44 | Test that the custom exit method is called on shutdown |
[f721030] | 45 | """ |
[9e426c1] | 46 | # Must mask sys.exit, otherwise the whole testing process stops. |
47 | sys.exit = MagicMock() | |
[53c771e] | 48 | QtWidgets.QMessageBox.question = MagicMock(return_value=QtWidgets.QMessageBox.Yes) |
[9e426c1] | 49 | |
50 | # Open, then close the main window | |
51 | tmp_main = MainSasViewWindow(None) | |
52 | tmp_main.close() | |
53 | ||
54 | # See that the MessageBox method got called | |
[53c771e] | 55 | self.assertTrue(QtWidgets.QMessageBox.question.called) |
[f721030] | 56 | |
57 | if __name__ == "__main__": | |
58 | unittest.main() |
Note: See TracBrowser
for help on using the repository browser.