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

Last change on this file since 6b43c58 was 464cd07, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Use singleton QApplication in unit tests to avoid issues on Ubuntu. SASVIEW-485

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