<commit_before>import sys
import unittest

from PyQt5.QtWidgets import QApplication
from PyQt5.QtTest import QTest
from PyQt5 import QtCore

# set up import paths
import sas.qtgui.path_prepare

from sas.qtgui.MainWindow.DroppableDataLoadWidget import DroppableDataLoadWidget
from sas.qtgui.Utilities.GuiUtils import *
from sas.qtgui.UnitTesting.TestUtils import QtSignalSpy

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

class DroppableDataLoadWidgetTest(unittest.TestCase):
    '''Test the DroppableDataLoadWidget GUI'''
    def setUp(self):
        '''Create the GUI'''
        class dummy_manager(object):
            def communicator(self):
                return Communicate()
            def perspective(self):
                return MyPerspective()

        self.form = DroppableDataLoadWidget(None, guimanager=dummy_manager())

        # create dummy mime object
        self.mime_data = QtCore.QMimeData()
        self.testfile = 'testfile.txt'
        self.mime_data.setUrls([QtCore.QUrl(self.testfile)])

    def testDragIsOK(self):
        """
        Test the item being dragged over the load widget
        """
        good_drag_event = QtGui.QDragMoveEvent(QtCore.QPoint(0,0),
                                               QtCore.Qt.CopyAction,
                                               self.mime_data,
                                               QtCore.Qt.LeftButton,
                                               QtCore.Qt.NoModifier)
        mime_data = QtCore.QMimeData()
        bad_drag_event = QtGui.QDragMoveEvent(QtCore.QPoint(0,0),
                                               QtCore.Qt.CopyAction,
                                               mime_data,
                                               QtCore.Qt.LeftButton,
                                               QtCore.Qt.NoModifier)

        # Call the drag handler with good event
        assert self.form.dragIsOK(good_drag_event)

        # Call the drag handler with bad event
        assert not self.form.dragIsOK(bad_drag_event)

    def testDropEvent(self):
        """
        Test what happens if an object is dropped onto the load widget
        """
        spy_file_read = QtSignalSpy(self.form, self.form.communicator.fileReadSignal)

        drop_event = QtGui.QDropEvent(QtCore.QPoint(0,0),
                                    QtCore.Qt.CopyAction,
                                    self.mime_data,
                                    QtCore.Qt.LeftButton,
                                    QtCore.Qt.NoModifier)

        self.form.dropEvent(drop_event)
        QApplication.processEvents()
        assert spy_file_read.count() == 1
        #self.assertIn(self.testfile, str(spy_file_read.signal(index=0)))


if __name__ == "__main__":
    unittest.main()<commit_msg>Change to pytest fixtures DroppableDataLoadWidgetTest.py<commit_after>import pytest

from PyQt5.QtWidgets import QApplication
from PyQt5.QtTest import QTest
from PyQt5 import QtCore

from sas.qtgui.MainWindow.DroppableDataLoadWidget import DroppableDataLoadWidget
from sas.qtgui.Utilities.GuiUtils import *
from sas.qtgui.UnitTesting.TestUtils import QtSignalSpy


class DroppableDataLoadWidgetTest:
    '''Test the DroppableDataLoadWidget GUI'''

    @pytest.fixture(autouse=True)
    def form(self, qapp):
        '''Create/Destroy the DroppableDataLoadWidget'''
        class dummy_manager(object):
            def communicator(self):
                return Communicate()
            def perspective(self):
                return MyPerspective()

        f = DroppableDataLoadWidget(None, guimanager=dummy_manager())

        # create dummy mime object
        self.mime_data = QtCore.QMimeData()
        self.testfile = 'testfile.txt'
        self.mime_data.setUrls([QtCore.QUrl(self.testfile)])

        yield f

    def testDragIsOK(self, form):
        """
        Test the item being dragged over the load widget
        """
        good_drag_event = QtGui.QDragMoveEvent(QtCore.QPoint(0,0),
                                               QtCore.Qt.CopyAction,
                                               self.mime_data,
                                               QtCore.Qt.LeftButton,
                                               QtCore.Qt.NoModifier)
        mime_data = QtCore.QMimeData()
        bad_drag_event = QtGui.QDragMoveEvent(QtCore.QPoint(0,0),
                                               QtCore.Qt.CopyAction,
                                               mime_data,
                                               QtCore.Qt.LeftButton,
                                               QtCore.Qt.NoModifier)

        # Call the drag handler with good event
        assert form.dragIsOK(good_drag_event)

        # Call the drag handler with bad event
        assert not form.dragIsOK(bad_drag_event)

    def testDropEvent(self, form):
        """
        Test what happens if an object is dropped onto the load widget
        """
        spy_file_read = QtSignalSpy(form, form.communicator.fileReadSignal)

        drop_event = QtGui.QDropEvent(QtCore.QPoint(0,0),
                                    QtCore.Qt.CopyAction,
                                    self.mime_data,
                                    QtCore.Qt.LeftButton,
                                    QtCore.Qt.NoModifier)

        form.dropEvent(drop_event)
        QApplication.processEvents()
        assert spy_file_read.count() == 1
        #self.assertIn(self.testfile, str(spy_file_read.signal(index=0)))
{'fraction_non_alphanumeric': 0.07469180565627266, 'fraction_numerical': 0.003988397389412618, 'mean_word_length': 1.62339514978602, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6744257', 'n_tokens_mistral': 1477, 'n_tokens_neox': 1430, 'n_words': 290}