source: sasview/src/sas/qtgui/UnitTesting/DroppableDataLoadWidgetTest.py @ e540cd2

ESS_GUIESS_GUI_DocsESS_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 e540cd2 was e540cd2, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 8 years ago

Status bar, progress bar, initial treeview context menu + minor cleanup

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