source: sasview/src/sas/qtgui/MainWindow/UnitTesting/DroppableDataLoadWidgetTest.py @ 0d72cac

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 0d72cac 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
Line 
1import sys
2import unittest
3
4from PyQt5.QtWidgets import QApplication
5from PyQt5.QtTest import QTest
6from PyQt5 import QtCore
7
8# set up import paths
9import path_prepare
10
11from sas.qtgui.MainWindow.DroppableDataLoadWidget import DroppableDataLoadWidget
12from sas.qtgui.Utilities.GuiUtils import *
13from sas.qtgui.UnitTesting.TestUtils import QtSignalSpy
14
15if not QApplication.instance():
16    app = QApplication(sys.argv)
17
18class DroppableDataLoadWidgetTest(unittest.TestCase):
19    '''Test the DroppableDataLoadWidget GUI'''
20    def setUp(self):
21        '''Create the GUI'''
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())
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)])
34
35    def testDragIsOK(self):
36        """
37        Test the item being dragged over the load widget
38        """
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))
56
57    def testDropEvent(self):
58        """
59        Test what happens if an object is dropped onto the load widget
60        """
61        spy_file_read = QtSignalSpy(self.form, self.form.communicator.fileReadSignal)
62
63        drop_event = QtGui.QDropEvent(QtCore.QPoint(0,0),
64                                    QtCore.Qt.CopyAction,
65                                    self.mime_data,
66                                    QtCore.Qt.LeftButton,
67                                    QtCore.Qt.NoModifier)
68
69        self.form.dropEvent(drop_event)
70        QApplication.processEvents()
71        self.assertEqual(spy_file_read.count(), 1)
72        #self.assertIn(self.testfile, str(spy_file_read.signal(index=0)))
73
74
75if __name__ == "__main__":
76    unittest.main()
Note: See TracBrowser for help on using the repository browser.