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

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 161713c was 31c5b58, checked in by Piotr Rozyczko <rozyczko@…>, 8 years ago

Refactored to allow running with run.py.
Minor fixes to plotting.

  • Property mode set to 100644
File size: 2.7 KB
Line 
1import sys
2import unittest
3
4from PyQt4.QtGui import QApplication
5from PyQt4.QtTest import QTest
6from PyQt4 import QtCore
7
8# set up import paths
9import path_prepare
10
11from DroppableDataLoadWidget import DroppableDataLoadWidget
12from GuiUtils import *
13from UnitTesting.TestUtils import QtSignalSpy
14
15app = QApplication(sys.argv)
16
17class 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
74if __name__ == "__main__":
75    unittest.main()
Note: See TracBrowser for help on using the repository browser.