<commit_before>import sys
import subprocess
import unittest
import webbrowser
import logging

from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtTest import QTest
from PyQt5 import QtCore
from unittest.mock import MagicMock

# Local
from sas.qtgui.MainWindow.DataExplorer import DataExplorerWindow
from sas.qtgui.MainWindow.AboutBox import AboutBox
from sas.qtgui.MainWindow.WelcomePanel import WelcomePanel
from sas.qtgui.Utilities.IPythonWidget import IPythonWidget

from sas.qtgui.MainWindow.GuiManager import Acknowledgements, GuiManager
from sas.qtgui.MainWindow.MainWindow import MainSasViewWindow
from sas.qtgui.UnitTesting.TestUtils import QtSignalSpy

if not QApplication.instance():
    app = QApplication(sys.argv)

class GuiManagerTest(unittest.TestCase):
    '''Test the Main Window functionality'''
    def setUp(self):
        '''Create the tested object'''
        class MainWindow(MainSasViewWindow):
            # Main window of the application
            def __init__(self, reactor, parent=None):
                screen_resolution = QtCore.QRect(0,0,640,480)
                super(MainWindow, self).__init__(screen_resolution, parent)
        
                # define workspace for dialogs.
                self.workspace = QMdiArea(self)
                self.setCentralWidget(self.workspace)

        self.manager = GuiManager(MainWindow(None))

    def tearDown(self):
        '''Destroy the GUI'''
        self.manager = None

    def testDefaults(self):
        """
        Test the object in its default state
        """
        self.assertIsInstance(self.manager.filesWidget, DataExplorerWindow)
        self.assertIsInstance(self.manager.dockedFilesWidget, QDockWidget)
        self.assertIsInstance(self.manager.dockedFilesWidget.widget(), DataExplorerWindow)
        self.assertEqual(self.manager._workspace.dockWidgetArea(self.manager.dockedFilesWidget), QtCore.Qt.LeftDockWidgetArea)

        self.assertIsInstance(self.manager.logDockWidget, QDockWidget)
        self.assertIsInstance(self.manager.logDockWidget.widget(), QTextBrowser)
        self.assertEqual(self.manager._workspace.dockWidgetArea(self.manager.logDockWidget), QtCore.Qt.BottomDockWidgetArea)

        self.assertIsInstance(self.manager.ackWidget, Acknowledgements)
        self.assertIsInstance(self.manager.aboutWidget, AboutBox)
        #self.assertIsInstance(self.manager.welcomePanel, WelcomePanel)

    def skip_testLogging(self):
        """
        Test logging of stdout, stderr and log messages
        """
        # See if the log window is empty
        self.assertEqual(self.manager.logDockWidget.widget().toPlainText(), "")

        # Now, send some message to stdout.
        # We are in the MainWindow scope, so simple 'print' will work
        message = "from stdout"
        print(message)
        self.assertIn(message, self.manager.logDockWidget.widget().toPlainText())

        # Send some message to stderr
        message = "from stderr"
        sys.stderr.write(message)
        self.assertIn(message, self.manager.logDockWidget.widget().toPlainText())

        # And finally, send a log message
        import logging
        message = "from logging"
        message_logged = "ERROR: " + message
        logging.error(message)
        self.assertIn(message_logged, self.manager.logDockWidget.widget().toPlainText())

    def testConsole(self):
        """
        Test the docked QtConsole
        """
        # Invoke the console action
        self.manager.actionPython_Shell_Editor()

        # Test the widegt properties
        self.assertIsInstance(self.manager.ipDockWidget, QDockWidget)
        self.assertIsInstance(self.manager.ipDockWidget.widget(), IPythonWidget)
        self.assertEqual(self.manager._workspace.dockWidgetArea(self.manager.ipDockWidget), QtCore.Qt.RightDockWidgetArea)

    def testUpdatePerspective(self):
        """
        """
        pass

    def testUpdateStatusBar(self):
        """
        """
        pass

    def testSetData(self):
        """
        """
        pass

    def testQuitApplication(self):
        """
        Test that the custom exit method is called on shutdown
        """
        self.manager._workspace.show()

        # Must mask sys.exit, otherwise the whole testing process stops.
        sys.exit = MagicMock()

        # Say No to the close dialog
        QMessageBox.question = MagicMock(return_value=QMessageBox.No)

        # Open, then close the manager
        self.manager.quitApplication()

        # See that the MessageBox method got called
        #self.assertTrue(QMessageBox.question.called)

        # Say Yes to the close dialog
        QMessageBox.question = MagicMock(return_value=QMessageBox.Yes)

        # Open, then close the manager
        self.manager.quitApplication()

        # See that the MessageBox method got called
        #self.assertTrue(QMessageBox.question.called)

    def testCheckUpdate(self):
        """
        Tests the SasView website version polling
        """
        self.manager.processVersion = MagicMock()
        version = {'version'     : '5.0.2',
                   'update_url'  : 'http://www.sasview.org/sasview.latestversion', 
                   'download_url': 'https://github.com/SasView/sasview/releases/tag/v5.0.2'}
        self.manager.checkUpdate()
<commit_msg>xfail tests in GuiManagerTest.py<commit_after>import sys
import subprocess
import unittest
import webbrowser
import logging

import pytest

from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtTest import QTest
from PyQt5 import QtCore
from unittest.mock import MagicMock

# Local
from sas.qtgui.MainWindow.DataExplorer import DataExplorerWindow
from sas.qtgui.MainWindow.AboutBox import AboutBox
from sas.qtgui.MainWindow.WelcomePanel import WelcomePanel
from sas.qtgui.Utilities.IPythonWidget import IPythonWidget

from sas.qtgui.MainWindow.GuiManager import Acknowledgements, GuiManager
from sas.qtgui.MainWindow.MainWindow import MainSasViewWindow
from sas.qtgui.UnitTesting.TestUtils import QtSignalSpy

if not QApplication.instance():
    app = QApplication(sys.argv)

class GuiManagerTest(unittest.TestCase):
    '''Test the Main Window functionality'''
    def setUp(self):
        '''Create the tested object'''
        class MainWindow(MainSasViewWindow):
            # Main window of the application
            def __init__(self, reactor, parent=None):
                screen_resolution = QtCore.QRect(0,0,640,480)
                super(MainWindow, self).__init__(screen_resolution, parent)
        
                # define workspace for dialogs.
                self.workspace = QMdiArea(self)
                self.setCentralWidget(self.workspace)

        self.manager = GuiManager(MainWindow(None))

    def tearDown(self):
        '''Destroy the GUI'''
        self.manager = None

    def testDefaults(self):
        """
        Test the object in its default state
        """
        self.assertIsInstance(self.manager.filesWidget, DataExplorerWindow)
        self.assertIsInstance(self.manager.dockedFilesWidget, QDockWidget)
        self.assertIsInstance(self.manager.dockedFilesWidget.widget(), DataExplorerWindow)
        self.assertEqual(self.manager._workspace.dockWidgetArea(self.manager.dockedFilesWidget), QtCore.Qt.LeftDockWidgetArea)

        self.assertIsInstance(self.manager.logDockWidget, QDockWidget)
        self.assertIsInstance(self.manager.logDockWidget.widget(), QTextBrowser)
        self.assertEqual(self.manager._workspace.dockWidgetArea(self.manager.logDockWidget), QtCore.Qt.BottomDockWidgetArea)

        self.assertIsInstance(self.manager.ackWidget, Acknowledgements)
        self.assertIsInstance(self.manager.aboutWidget, AboutBox)
        #self.assertIsInstance(self.manager.welcomePanel, WelcomePanel)

    def skip_testLogging(self):
        """
        Test logging of stdout, stderr and log messages
        """
        # See if the log window is empty
        self.assertEqual(self.manager.logDockWidget.widget().toPlainText(), "")

        # Now, send some message to stdout.
        # We are in the MainWindow scope, so simple 'print' will work
        message = "from stdout"
        print(message)
        self.assertIn(message, self.manager.logDockWidget.widget().toPlainText())

        # Send some message to stderr
        message = "from stderr"
        sys.stderr.write(message)
        self.assertIn(message, self.manager.logDockWidget.widget().toPlainText())

        # And finally, send a log message
        import logging
        message = "from logging"
        message_logged = "ERROR: " + message
        logging.error(message)
        self.assertIn(message_logged, self.manager.logDockWidget.widget().toPlainText())

    def testConsole(self):
        """
        Test the docked QtConsole
        """
        # Invoke the console action
        self.manager.actionPython_Shell_Editor()

        # Test the widegt properties
        self.assertIsInstance(self.manager.ipDockWidget, QDockWidget)
        self.assertIsInstance(self.manager.ipDockWidget.widget(), IPythonWidget)
        self.assertEqual(self.manager._workspace.dockWidgetArea(self.manager.ipDockWidget), QtCore.Qt.RightDockWidgetArea)

    def testUpdatePerspective(self):
        """
        """
        pass

    def testUpdateStatusBar(self):
        """
        """
        pass

    def testSetData(self):
        """
        """
        pass

    def testQuitApplication(self):
        """
        Test that the custom exit method is called on shutdown
        """
        self.manager._workspace.show()

        # Must mask sys.exit, otherwise the whole testing process stops.
        sys.exit = MagicMock()

        # Say No to the close dialog
        QMessageBox.question = MagicMock(return_value=QMessageBox.No)

        # Open, then close the manager
        self.manager.quitApplication()

        # See that the MessageBox method got called
        #self.assertTrue(QMessageBox.question.called)

        # Say Yes to the close dialog
        QMessageBox.question = MagicMock(return_value=QMessageBox.Yes)

        # Open, then close the manager
        self.manager.quitApplication()

        # See that the MessageBox method got called
        #self.assertTrue(QMessageBox.question.called)

    @pytest.mark.xfail(reason="2022-09 already broken")
    def testCheckUpdate(self):
        """
        Tests the SasView website version polling
        """
        self.manager.processVersion = MagicMock()
        version = {'version'     : '5.0.2',
                   'update_url'  : 'http://www.sasview.org/sasview.latestversion', 
                   'download_url': 'https://github.com/SasView/sasview/releases/tag/v5.0.2'}
        self.manager.checkUpdate()

{'fraction_non_alphanumeric': 0.09084153817573844, 'fraction_numerical': 0.0039011703511053317, 'mean_word_length': 2.7938689217758985, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2491831', 'n_tokens_mistral': 3080, 'n_tokens_neox': 2964, 'n_words': 652}