source: sasview/src/sas/qtgui/MainWindow/UnitTesting/AboutBoxTest.py @ 96e8e39

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 96e8e39 was 53c771e, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Converted unit tests

  • Property mode set to 100644
File size: 3.4 KB
Line 
1import sys
2import unittest
3import webbrowser
4
5from PyQt5 import QtGui, QtWidgets
6from PyQt5.QtTest import QTest
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.AboutBox import AboutBox
15import sas.qtgui.Utilities.LocalConfig as LocalConfig
16
17if not QtWidgets.QApplication.instance():
18    app = QtWidgets.QApplication(sys.argv)
19
20class AboutBoxTest(unittest.TestCase):
21    '''Test the AboutBox'''
22    def setUp(self):
23        '''Create the AboutBox'''
24        self.widget = AboutBox(None)
25
26    def tearDown(self):
27        '''Destroy the AboutBox'''
28        self.widget.close()
29        self.widget = None
30
31    def testDefaults(self):
32        '''Test the GUI in its default state'''
33        self.assertIsInstance(self.widget, QtWidgets.QWidget)
34        self.assertEqual(self.widget.windowTitle(), "About")
35        self.assertEqual(self.widget.cmdOK.text(), "OK")
36
37        self.assertIn("SasView", self.widget.label_2.text())
38        # Link buttons pixmaps don't contain image filenames, so can't check this.
39        # self.assertEqual(self.widget.cmdLinkUT.icon().name(), "utlogo.gif")
40
41
42    def testVersion(self):
43        """
44        Assure the version number is as expected
45        """
46        version = self.widget.lblVersion
47        self.assertIsInstance(version, QtWidgets.QLabel)
48        self.assertEqual(str(version.text()), str(LocalConfig.__version__))
49
50    def testAbout(self):
51        """
52        Assure the about label is filled properly
53        """
54        about = self.widget.lblAbout
55        self.assertIsInstance(about, QtWidgets.QLabel)
56        # build version
57        self.assertIn(str(LocalConfig.__build__), about.text())
58        # License
59        self.assertIn(str(LocalConfig._copyright), about.text())
60        # URLs
61        self.assertIn(str(LocalConfig._homepage), about.text())
62        self.assertIn(str(LocalConfig.__download_page__), about.text())
63        self.assertIn(str(LocalConfig._license), about.text())
64
65        # Are links enabled?
66        self.assertTrue(about.openExternalLinks())
67
68    def testAddActions(self):
69        """
70        Assure link buttons are set up correctly
71        """
72        webbrowser.open = MagicMock()
73        all_hosts = [
74                LocalConfig._nist_url,
75                LocalConfig._umd_url,
76                LocalConfig._sns_url,
77                LocalConfig._nsf_url,
78                LocalConfig._isis_url,
79                LocalConfig._ess_url,
80                LocalConfig._ill_url,
81                LocalConfig._ansto_url,
82                LocalConfig._inst_url]
83
84        # Press the buttons
85        buttonList = self.widget.findChildren(QtWidgets.QPushButton)
86        for button in buttonList:
87            QTest.mouseClick(button, QtCore.Qt.LeftButton)
88            #open_link = webbrowser.open.call_args
89            args, _ = webbrowser.open.call_args
90            # args[0] contains the actual argument sent to open()
91            self.assertIn(args[0], all_hosts)
92
93        # The above test also greedily catches the OK button,
94        # so let's test it separately.
95        # Show the widget
96        self.widget.show()
97        self.assertTrue(self.widget.isVisible())
98        # Click on the OK button
99        QTest.mouseClick(self.widget.cmdOK, QtCore.Qt.LeftButton)
100        # assure the widget is no longer seen
101        self.assertFalse(self.widget.isVisible())
102
103if __name__ == "__main__":
104    unittest.main()
Note: See TracBrowser for help on using the repository browser.