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