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

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 ba0dc71 was e540cd2, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 8 years ago

Status bar, progress bar, initial treeview context menu + minor cleanup

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