import sys
import webbrowser

import pytest

from PyQt5 import QtGui, QtWidgets
from PyQt5.QtTest import QTest
from PyQt5 import QtCore

import sas.sasview
import sas.system.version
from sas import config
from sas.system import web, legal

# Local
from sas.qtgui.MainWindow.AboutBox import AboutBox

class AboutBoxTest:
    '''Test the AboutBox'''

    @pytest.fixture(autouse=True)
    def widget(self, qapp):
        '''Create/Destroy the AboutBox'''
        w = AboutBox(None)
        yield w
        w.close()

    def testDefaults(self, widget):
        '''Test the GUI in its default state'''
        assert isinstance(widget, QtWidgets.QWidget)
        assert widget.windowTitle() == "About"
        assert widget.cmdOK.text() == "OK"

        assert "SasView" in widget.label_2.text()
        # Link buttons pixmaps don't contain image filenames, so can't check this.
        # self.assertEqual(widget.cmdLinkUT.icon().name(), "utlogo.gif")


    def testVersion(self, widget):
        """
        Assure the version number is as expected
        """
        version = widget.lblVersion
        assert isinstance(version, QtWidgets.QLabel)
        assert str(version.text()) == str(sas.system.version.__version__)

    def testAbout(self, widget):
        """
        Assure the about label is filled properly
        """
        about = widget.lblAbout
        assert isinstance(about, QtWidgets.QLabel)
        # License
        assert str(legal.copyright) in about.text()
        # URLs
        assert str(web.homepage_url) in about.text()
        assert str(config.download_url) in about.text()
        assert str(config.help_email) in about.text()

        # Are links enabled?
        assert about.openExternalLinks()

    def testAddActions(self, widget, mocker):
        """
        Assure link buttons are set up correctly
        """
        mocker.patch.object(webbrowser, 'open')
        all_hosts = [
                config.nist_url,
                config.umd_url,
                config.sns_url,
                config.nsf_url,
                config.isis_url,
                config.ess_url,
                config.ill_url,
                config.ansto_url,
                config.inst_url,
                config.delft_url,
                config.bam_url,
                config.diamond_url]

        # Press the buttons
        buttonList = widget.findChildren(QtWidgets.QPushButton)
        for button in buttonList:
            QTest.mouseClick(button, QtCore.Qt.LeftButton)
            #open_link = webbrowser.open.call_args
            args, _ = webbrowser.open.call_args
            # args[0] contains the actual argument sent to open()
            assert args[0] in all_hosts

        # The above test also greedily catches the OK button,
        # so let's test it separately.
        # Show the widget
        widget.show()
        assert widget.isVisible()
        # Click on the OK button
        QTest.mouseClick(widget.cmdOK, QtCore.Qt.LeftButton)
        # assure the widget is no longer seen
        assert not widget.isVisible()

@@ -1563,22 +1563,19 @@
 ert str(
-config
+web
 .downloa
@@ -1616,22 +1616,19 @@
 ert str(
-config
+web
 .help_em
@@ -1925,22 +1925,19 @@
         
-config
+web
 .nist_ur
@@ -1955,22 +1955,19 @@
         
-config
+web
 .umd_url
@@ -1984,22 +1984,19 @@
         
-config
+web
 .sns_url
@@ -2013,22 +2013,19 @@
         
-config
+web
 .nsf_url
@@ -2042,22 +2042,19 @@
         
-config
+web
 .isis_ur
@@ -2072,22 +2072,19 @@
         
-config
+web
 .ess_url
@@ -2101,22 +2101,19 @@
         
-config
+web
 .ill_url
@@ -2130,22 +2130,19 @@
         
-config
+web
 .ansto_u
@@ -2161,22 +2161,19 @@
         
-config
+web
 .inst_ur
@@ -2191,22 +2191,19 @@
         
-config
+web
 .delft_u
@@ -2222,22 +2222,19 @@
         
-config
+web
 .bam_url
@@ -2251,22 +2251,19 @@
         
-config
+web
 .diamond

Fix AboutBoxTest.py for new config/web objects