source: sasview/src/sas/qtgui/MainWindow/UnitTesting/MainWindowTest.py @ 8137a02

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 8137a02 was 63467b6, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 6 years ago

Improved handling of 2d plot children. Refactored model tree search.

  • Property mode set to 100644
File size: 2.5 KB
RevLine 
[f721030]1import sys
2import unittest
[53c771e]3import logging
[f721030]4
[53c771e]5from PyQt5 import QtGui, QtWidgets
6from PyQt5 import QtTest
7from PyQt5 import QtCore
[7fb471d]8from unittest.mock import MagicMock
[f721030]9
[31c5b58]10# set up import paths
11import path_prepare
12
[f721030]13# Local
[83eb5208]14from sas.qtgui.MainWindow.MainWindow import MainSasViewWindow
15from sas.qtgui.MainWindow.MainWindow import SplashScreen
[53c771e]16from sas.qtgui.MainWindow.GuiManager import GuiManager
[8353d90]17from sas.qtgui.Perspectives.Fitting import FittingPerspective
[f721030]18
[53c771e]19if not QtWidgets.QApplication.instance():
20    app = QtWidgets.QApplication(sys.argv)
[f721030]21
22class MainWindowTest(unittest.TestCase):
[9e426c1]23    """Test the Main Window GUI"""
[f721030]24    def setUp(self):
[9e426c1]25        """Create the GUI"""
[f721030]26
27        self.widget = MainSasViewWindow(None)
28
29    def tearDown(self):
[9e426c1]30        """Destroy the GUI"""
[f721030]31        self.widget = None
32
33    def testDefaults(self):
[9e426c1]34        """Test the GUI in its default state"""
[53c771e]35        self.assertIsInstance(self.widget, QtWidgets.QMainWindow)
36        self.assertIsInstance(self.widget.centralWidget(), QtWidgets.QMdiArea)
[f721030]37       
38    def testSplashScreen(self):
[9e426c1]39        """ Test the splash screen """
40        splash = SplashScreen()
[53c771e]41        self.assertIsInstance(splash, QtWidgets.QSplashScreen)
[9e426c1]42
[8353d90]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
[fa762f4]49        self.assertEqual(len(tmp_main.workspace.subWindowList()), 2)
[8353d90]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()), 2)
57
58        tmp_main.close()
59
[9e426c1]60    def testExit(self):
[f721030]61        """
[9e426c1]62        Test that the custom exit method is called on shutdown
[f721030]63        """
[9e426c1]64        # Must mask sys.exit, otherwise the whole testing process stops.
65        sys.exit = MagicMock()
[53c771e]66        QtWidgets.QMessageBox.question = MagicMock(return_value=QtWidgets.QMessageBox.Yes)
[9e426c1]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
[53c771e]73        self.assertTrue(QtWidgets.QMessageBox.question.called)
[f721030]74       
75if __name__ == "__main__":
76    unittest.main()
Note: See TracBrowser for help on using the repository browser.