source: sasview/src/sas/qtgui/MainWindow/UnitTesting/MainWindowTest.py @ 9387fe3

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 9387fe3 was 53c771e, checked in by Piotr Rozyczko <rozyczko@…>, 6 years ago

Converted unit tests

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