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

ESS_GUIESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_openclESS_GUI_sync_sascalc
Last change on this file since aea6bb7 was 2f55df6, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 6 years ago

Slicer Parameters should also close the corresponding subwindow on exit.
Also: fixed toFloat() conversion.
SASVIEW-1115

  • Property mode set to 100644
File size: 3.8 KB
RevLine 
[cf89cce]1import sys
2import unittest
[14ec91c5]3import webbrowser
[7fb471d]4from unittest.mock import MagicMock
[cf89cce]5
[53c771e]6from PyQt5 import QtGui, QtWidgets
7from PyQt5 import QtCore
8from PyQt5 import QtTest
[cf89cce]9
10# set up import paths
[83eb5208]11import sas.qtgui.path_prepare
[cf89cce]12
[83eb5208]13from sas.qtgui.UnitTesting.TestUtils import QtSignalSpy
[cf89cce]14
15# Local
[83eb5208]16from sas.qtgui.Plotting.SlicerParameters import SlicerParameters
[cf89cce]17
[53c771e]18if not QtWidgets.QApplication.instance():
19    app = QtWidgets.QApplication(sys.argv)
[cf89cce]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
[4992ff2]39        self.assertIsInstance(self.widget.proxy, QtCore.QIdentityProxyModel)
[53c771e]40        self.assertIsInstance(self.widget.lstParams.itemDelegate(), QtWidgets.QStyledItemDelegate)
[cf89cce]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
[2f55df6]62        spy_close = QtSignalSpy(self.widget, self.widget.closeWidgetSignal)
[cf89cce]63        # Click on the "Close" button
[53c771e]64        QtTest.QTest.mouseClick(self.widget.buttonBox.button(QtWidgets.QDialogButtonBox.Close), QtCore.Qt.LeftButton)
[cf89cce]65        # Check the signal
66        self.assertEqual(spy_close.count(), 1)
67        # Assure the window got closed
68        self.assertFalse(self.widget.isVisible())
69
[53c771e]70    def notestOnHelp(self):
[cf89cce]71        ''' Assure clicking on help returns QtWeb view on requested page'''
72        self.widget.show()
73
[14ec91c5]74        #Mock the webbrowser.open method
75        webbrowser.open = MagicMock()
[cf89cce]76
77        # Invoke the action
78        self.widget.onHelp()
79
80        # Check if show() got called
[14ec91c5]81        self.assertTrue(webbrowser.open.called)
[cf89cce]82
83        # Assure the filename is correct
[14ec91c5]84        self.assertIn("graph_help.html", webbrowser.open.call_args[0][0])
[cf89cce]85       
86    def testSetModel(self):
87        ''' Test if resetting the model works'''
88       
89        item1 = QtGui.QStandardItem("s1")
90        item2 = QtGui.QStandardItem("5.0")
91        new_model = QtGui.QStandardItemModel()
92        new_model.appendRow([item1, item2])
93        item1 = QtGui.QStandardItem("s2")
94        item2 = QtGui.QStandardItem("20.0")
95        new_model.appendRow([item1, item2])
96        # Force the new model onto the widget
97        self.widget.setModel(model=new_model)
98
99        # Test if the widget got it
100        self.assertEqual(self.widget.model.columnCount(), 2)
101        self.assertEqual(self.widget.model.rowCount(), 2)
102        self.assertEqual(self.widget.model.item(0,0).text(), 's1')
103        self.assertEqual(self.widget.model.item(1,0).text(), 's2')
104
105
106       
107if __name__ == "__main__":
108    unittest.main()
Note: See TracBrowser for help on using the repository browser.