source: sasview/src/sas/qtgui/MainWindow/UnitTesting/DroppableDataLoadWidgetTest.py @ 87dfca4

ESS_GUIESS_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 87dfca4 was 80468f6, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Fixed a few unit test files

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[f82ab8c]1import sys
2import unittest
3
[53c771e]4from PyQt5.QtWidgets import QApplication
5from PyQt5.QtTest import QTest
6from PyQt5 import QtCore
[31c5b58]7
8# set up import paths
9import path_prepare
10
[83eb5208]11from sas.qtgui.MainWindow.DroppableDataLoadWidget import DroppableDataLoadWidget
12from sas.qtgui.Utilities.GuiUtils import *
13from sas.qtgui.UnitTesting.TestUtils import QtSignalSpy
[f82ab8c]14
[464cd07]15if not QApplication.instance():
16    app = QApplication(sys.argv)
[f82ab8c]17
18class DroppableDataLoadWidgetTest(unittest.TestCase):
19    '''Test the DroppableDataLoadWidget GUI'''
20    def setUp(self):
21        '''Create the GUI'''
[481ff26]22        class dummy_manager(object):
23            def communicator(self):
24                return Communicate()
25            def perspective(self):
26                return MyPerspective()
27
28        self.form = DroppableDataLoadWidget(None, guimanager=dummy_manager())
[e540cd2]29
30        # create dummy mime object
31        self.mime_data = QtCore.QMimeData()
32        self.testfile = 'testfile.txt'
33        self.mime_data.setUrls([QtCore.QUrl(self.testfile)])
[481ff26]34
35    def testDragIsOK(self):
36        """
37        Test the item being dragged over the load widget
38        """
[e540cd2]39        good_drag_event = QtGui.QDragMoveEvent(QtCore.QPoint(0,0),
40                                               QtCore.Qt.CopyAction,
41                                               self.mime_data,
42                                               QtCore.Qt.LeftButton,
43                                               QtCore.Qt.NoModifier)
44        mime_data = QtCore.QMimeData()
45        bad_drag_event = QtGui.QDragMoveEvent(QtCore.QPoint(0,0),
46                                               QtCore.Qt.CopyAction,
47                                               mime_data,
48                                               QtCore.Qt.LeftButton,
49                                               QtCore.Qt.NoModifier)
50
51        # Call the drag handler with good event
52        self.assertTrue(self.form.dragIsOK(good_drag_event))
53
54        # Call the drag handler with bad event
55        self.assertFalse(self.form.dragIsOK(bad_drag_event))
[481ff26]56
57    def testDropEvent(self):
58        """
59        Test what happens if an object is dropped onto the load widget
60        """
[e540cd2]61        spy_file_read = QtSignalSpy(self.form, self.form.communicator.fileReadSignal)
62
63        drop_event = QtGui.QDropEvent(QtCore.QPoint(0,0),
[53c771e]64                                    QtCore.Qt.CopyAction,
65                                    self.mime_data,
66                                    QtCore.Qt.LeftButton,
67                                    QtCore.Qt.NoModifier)
[e540cd2]68
69        self.form.dropEvent(drop_event)
[53c771e]70        QApplication.processEvents()
[e540cd2]71        self.assertEqual(spy_file_read.count(), 1)
[80468f6]72        #self.assertIn(self.testfile, str(spy_file_read.signal(index=0)))
[e540cd2]73
[f82ab8c]74
75if __name__ == "__main__":
76    unittest.main()
Note: See TracBrowser for help on using the repository browser.