source: sasview/src/sas/qtgui/UnitTesting/AboutBoxTest.py @ 161713c

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 161713c was 31c5b58, checked in by Piotr Rozyczko <rozyczko@…>, 8 years ago

Refactored to allow running with run.py.
Minor fixes to plotting.

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