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

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 d6b8a1d was 7fb471d, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Update for unit tests and minor functionality quirks

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[f721030]1import sys
2import unittest
3
[9e426c1]4from PyQt4 import QtGui
5from PyQt4 import QtTest
6from PyQt4 import QtCore
[7fb471d]7from unittest.mock import MagicMock
[f721030]8
[31c5b58]9# set up import paths
10import path_prepare
11
[f721030]12# Local
[83eb5208]13from sas.qtgui.MainWindow.MainWindow import MainSasViewWindow
14from sas.qtgui.MainWindow.MainWindow import SplashScreen
[f721030]15
[464cd07]16if not QtGui.QApplication.instance():
17    app = QtGui.QApplication(sys.argv)
[f721030]18
19class MainWindowTest(unittest.TestCase):
[9e426c1]20    """Test the Main Window GUI"""
[f721030]21    def setUp(self):
[9e426c1]22        """Create the GUI"""
[f721030]23
24        self.widget = MainSasViewWindow(None)
25
26    def tearDown(self):
[9e426c1]27        """Destroy the GUI"""
[f721030]28        self.widget = None
29
30    def testDefaults(self):
[9e426c1]31        """Test the GUI in its default state"""
32        self.assertIsInstance(self.widget, QtGui.QMainWindow)
33        self.assertIsInstance(self.widget.centralWidget(), QtGui.QWorkspace)
[f721030]34       
35    def testSplashScreen(self):
[9e426c1]36        """ Test the splash screen """
37        splash = SplashScreen()
38        self.assertIsInstance(splash, QtGui.QSplashScreen)
39
40    def testExit(self):
[f721030]41        """
[9e426c1]42        Test that the custom exit method is called on shutdown
[f721030]43        """
[9e426c1]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)
[f721030]54       
55if __name__ == "__main__":
56    unittest.main()
Note: See TracBrowser for help on using the repository browser.