source: sasview/src/sas/qtgui/Plotting/UnitTesting/SlicerParametersTest.py @ 7969b9c

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 7969b9c was 4992ff2, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Initial, in-progress version. Not really working atm. SASVIEW-787

  • Property mode set to 100644
File size: 3.8 KB
Line 
1import sys
2import unittest
3from unittest.mock import MagicMock
4
5from PyQt4 import QtGui
6from PyQt4 import QtCore
7from PyQt4 import QtTest
8from PyQt4 import QtWebKit
9
10# set up import paths
11import sas.qtgui.path_prepare
12
13from sas.qtgui.UnitTesting.TestUtils import QtSignalSpy
14
15# Local
16from sas.qtgui.Plotting.SlicerParameters import SlicerParameters
17
18if not QtGui.QApplication.instance():
19    app = QtGui.QApplication(sys.argv)
20
21class SlicerParametersTest(unittest.TestCase):
22    '''Test the SlicerParameters dialog'''
23    def setUp(self):
24        '''Create the SlicerParameters dialog'''
25
26        item1 = QtGui.QStandardItem("dromekage")
27        item2 = QtGui.QStandardItem("999.0")
28        self.model = QtGui.QStandardItemModel()
29        self.model.appendRow([item1, item2])
30        self.widget = SlicerParameters(model=self.model)
31
32    def tearDown(self):
33        '''Destroy the model'''
34        self.widget = None
35
36    def testDefaults(self):
37        '''Test the GUI in its default state'''
38        #self.widget.mapper
39        self.assertIsInstance(self.widget.proxy, QtCore.QIdentityProxyModel)
40        self.assertIsInstance(self.widget.lstParams.itemDelegate(), QtGui.QStyledItemDelegate)
41        self.assertTrue(self.widget.lstParams.model().columnReadOnly(0))
42        self.assertFalse(self.widget.lstParams.model().columnReadOnly(1))
43
44        # Test the proxy model
45        self.assertEqual(self.widget.lstParams.model(), self.widget.proxy)
46        self.assertEqual(self.widget.proxy.columnCount(), 2)
47        self.assertEqual(self.widget.proxy.rowCount(), 1)
48        self.assertEqual(self.widget.model.item(0,0).text(), 'dromekage')
49        self.assertEqual(self.widget.model.item(0,1).text(), '999.0')
50
51        # Check the flags in the proxy model
52        flags = self.widget.proxy.flags(self.widget.proxy.index(0,0))
53        self.assertFalse(flags & QtCore.Qt.ItemIsEditable)
54        self.assertTrue(flags & QtCore.Qt.ItemIsSelectable)
55        self.assertTrue(flags & QtCore.Qt.ItemIsEnabled)
56
57    def testClose(self):
58        ''' Assure that clicking on Close triggers right behaviour'''
59        self.widget.show()
60
61        # Set up the spy
62        spy_close = QtSignalSpy(self.widget, self.widget.close_signal)
63        # Click on the "Close" button
64        QtTest.QTest.mouseClick(self.widget.buttonBox.button(QtGui.QDialogButtonBox.Close), QtCore.Qt.LeftButton)
65        # Check the signal
66        self.assertEqual(spy_close.count(), 1)
67        # Assure the window got closed
68        self.assertFalse(self.widget.isVisible())
69
70    def testOnHelp(self):
71        ''' Assure clicking on help returns QtWeb view on requested page'''
72        self.widget.show()
73
74        #Mock the QWebView method
75        QtWebKit.QWebView.show = MagicMock()
76        QtWebKit.QWebView.load = MagicMock()
77
78        # Invoke the action
79        self.widget.onHelp()
80
81        # Check if show() got called
82        self.assertTrue(QtWebKit.QWebView.show.called)
83
84        # Assure the filename is correct
85        self.assertIn("graph_help.html", QtWebKit.QWebView.load.call_args[0][0].toString())
86       
87    def testSetModel(self):
88        ''' Test if resetting the model works'''
89       
90        item1 = QtGui.QStandardItem("s1")
91        item2 = QtGui.QStandardItem("5.0")
92        new_model = QtGui.QStandardItemModel()
93        new_model.appendRow([item1, item2])
94        item1 = QtGui.QStandardItem("s2")
95        item2 = QtGui.QStandardItem("20.0")
96        new_model.appendRow([item1, item2])
97        # Force the new model onto the widget
98        self.widget.setModel(model=new_model)
99
100        # Test if the widget got it
101        self.assertEqual(self.widget.model.columnCount(), 2)
102        self.assertEqual(self.widget.model.rowCount(), 2)
103        self.assertEqual(self.widget.model.item(0,0).text(), 's1')
104        self.assertEqual(self.widget.model.item(1,0).text(), 's2')
105
106
107       
108if __name__ == "__main__":
109    unittest.main()
Note: See TracBrowser for help on using the repository browser.