source: sasview/src/sas/qtgui/MainWindow/UnitTesting/MainWindowTest.py @ 6c7ebb88

Last change on this file since 6c7ebb88 was 0989bad, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 6 years ago

Modified the main window name from MainWindow? to more suitable SasView?.
Fixed a bunch of related and unrelated unit tests.

  • Property mode set to 100644
File size: 2.5 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
17from sas.qtgui.Perspectives.Fitting import FittingPerspective
18
19if not QtWidgets.QApplication.instance():
20    app = QtWidgets.QApplication(sys.argv)
21
22class MainWindowTest(unittest.TestCase):
23    """Test the Main Window GUI"""
24    def setUp(self):
25        """Create the GUI"""
26
27        self.widget = MainSasViewWindow(None)
28
29    def tearDown(self):
30        """Destroy the GUI"""
31        self.widget = None
32
33    def testDefaults(self):
34        """Test the GUI in its default state"""
35        self.assertIsInstance(self.widget, QtWidgets.QMainWindow)
36        self.assertIsInstance(self.widget.centralWidget(), QtWidgets.QMdiArea)
37       
38    def testSplashScreen(self):
39        """ Test the splash screen """
40        splash = SplashScreen()
41        self.assertIsInstance(splash, QtWidgets.QSplashScreen)
42
43    def testWidgets(self):
44        """ Test enablement/disablement of widgets """
45        # Open the main window
46        tmp_main = MainSasViewWindow(None)
47        tmp_main.showMaximized()
48        # See that only one subwindow is up
49        self.assertEqual(len(tmp_main.workspace.subWindowList()), 3)
50        # and that the subwindow is the fitting perspective
51        self.assertIsInstance(tmp_main.workspace.subWindowList()[0].widget(),
52                              FittingPerspective.FittingWindow)
53        # Show the message widget
54        tmp_main.guiManager.showWelcomeMessage()
55        # Assure it is visible and a part of the MdiArea
56        self.assertEqual(len(tmp_main.workspace.subWindowList()), 3)
57
58        tmp_main.close()
59
60    def testExit(self):
61        """
62        Test that the custom exit method is called on shutdown
63        """
64        # Must mask sys.exit, otherwise the whole testing process stops.
65        sys.exit = MagicMock()
66        QtWidgets.QMessageBox.question = MagicMock(return_value=QtWidgets.QMessageBox.Yes)
67
68        # Open, then close the main window
69        tmp_main = MainSasViewWindow(None)
70        tmp_main.close()
71
72        # See that the MessageBox method got called
73        self.assertTrue(QtWidgets.QMessageBox.question.called)
74       
75if __name__ == "__main__":
76    unittest.main()
Note: See TracBrowser for help on using the repository browser.