Changeset d79bb7e in sasview for src/sas/qtgui/Perspectives/Inversion/UnitTesting
- Timestamp:
- Apr 26, 2018 2:43:31 PM (7 years ago)
- Branches:
- ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- 6bd0d81
- Parents:
- 0662f53
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Inversion/UnitTesting/InversionPerspectiveTest.py
r0662f53 rd79bb7e 1 import sys1 import time 2 2 import unittest 3 import logging4 3 from unittest.mock import MagicMock 5 4 6 5 from PyQt5 import QtGui, QtWidgets 7 from PyQt5.QtTest import QTest 8 from PyQt5 import QtCore 9 10 import sas.qtgui.path_prepare 6 7 from sas.qtgui.Utilities.GuiUtils import * 11 8 from sas.qtgui.Perspectives.Inversion.InversionPerspective import InversionWindow 12 9 from sas.qtgui.Perspectives.Inversion.InversionUtils import WIDGETS 13 from sas.sascalc.dataloader.loader import Loader14 10 from sas.qtgui.Plotting.PlotterData import Data1D 15 11 16 from sas.qtgui.MainWindow.DataManager import DataManager17 import sas.qtgui.Utilities.LocalConfig18 12 import sas.qtgui.Utilities.GuiUtils as GuiUtils 19 13 … … 22 16 23 17 18 class dummy_manager(object): 19 HELP_DIRECTORY_LOCATION = "html" 20 communicate = Communicate() 21 22 def communicator(self): 23 return self.communicate 24 25 24 26 class InversionTest(unittest.TestCase): 25 27 """ Test the Inversion Perspective GUI """ … … 27 29 def setUp(self): 28 30 """ Create the InversionWindow """ 29 self.widget = InversionWindow( None)30 self.widget. performEstimate = MagicMock()31 self.widget = InversionWindow(dummy_manager()) 32 self.widget.show() 31 33 self.fakeData1 = GuiUtils.HashableStandardItem("A") 32 34 self.fakeData2 = GuiUtils.HashableStandardItem("B") 33 35 reference_data1 = Data1D(x=[0.1, 0.2], y=[0.0, 0.0], dy=[0.0, 0.0]) 36 reference_data1.filename = "Test A" 34 37 reference_data2 = Data1D(x=[0.1, 0.2], y=[0.0, 0.0], dy=[0.0, 0.0]) 35 GuiUtils.updateModelItem(self.fakeData1, [reference_data1]) 36 GuiUtils.updateModelItem(self.fakeData2, [reference_data2]) 38 reference_data2.filename = "Test B" 39 GuiUtils.updateModelItem(self.fakeData1, reference_data1) 40 GuiUtils.updateModelItem(self.fakeData2, reference_data2) 37 41 38 42 def tearDown(self): 39 43 """ Destroy the InversionWindow """ 40 self.widget.setClosable( True)44 self.widget.setClosable(False) 41 45 self.widget.close() 42 46 self.widget = None … … 44 48 def removeAllData(self): 45 49 """ Cleanup method to restore widget to its base state """ 46 while len(self.widget.dataList) > 0: 47 self.widget.removeData() 50 if len(self.widget.dataList) > 0: 51 remove_me = list(self.widget._dataList.keys()) 52 self.widget.removeData(remove_me) 48 53 49 54 def baseGUIState(self): … … 105 110 self.assertEqual(self.widget.backgroundInput.text(), "0.0") 106 111 self.assertEqual(self.widget.minQInput.text(), "") 107 self.assertEqual(self.widget.maxQInput.text(), self.widget.minQInput.text())112 self.assertEqual(self.widget.maxQInput.text(), "") 108 113 self.assertEqual(self.widget.regularizationConstantInput.text(), "0.0001") 109 114 self.assertEqual(self.widget.noOfTermsInput.text(), "10") … … 116 121 self.assertEqual(self.widget.dataList.count(), 1) 117 122 # See that the buttons are now enabled properly 123 self.widget.enableButtons() 118 124 self.assertFalse(self.widget.calculateAllButton.isEnabled()) 119 125 self.assertTrue(self.widget.calculateThisButton.isEnabled()) … … 127 133 self.assertEqual(self.widget.dataList.count(), 2) 128 134 # See that the buttons are now enabled properly 135 self.widget.enableButtons() 136 self.assertTrue(self.widget.calculateThisButton.isEnabled()) 129 137 self.assertTrue(self.widget.calculateAllButton.isEnabled()) 130 self.assertTrue(self.widget.calculateThisButton.isEnabled())131 138 self.assertTrue(self.widget.removeButton.isEnabled()) 132 139 self.assertTrue(self.widget.explorerButton.isEnabled()) … … 137 144 self.zeroDataSetState() 138 145 self.baseBatchState() 146 self.removeAllData() 139 147 140 148 def testAllowBatch(self): 141 149 """ Batch P(r) Tests """ 150 self.baseBatchState() 151 self.widget.setData([self.fakeData1]) 152 self.oneDataSetState() 153 self.widget.setData([self.fakeData2]) 154 self.twoDataSetState() 155 self.widget.calculateAllButton.click() 156 self.assertTrue(self.widget.batchResultsWindow is not None) 157 self.assertEqual(self.widget.batchResultsWindow.tblParams.columnCount(), 9) 158 self.assertEqual(self.widget.batchResultsWindow.tblParams.rowCount(), 2) 159 if self.widget.isBatch: 160 self.widget.isBatch = False 161 self.widget.batchResultsWindow.close() 162 self.assertTrue(self.widget.batchResultsWindow is None) 163 # Last test 164 self.widget.removeData() 165 self.removeAllData() 142 166 self.baseBatchState() 143 167 … … 153 177 self.removeAllData() 154 178 self.zeroDataSetState() 179 self.removeAllData() 155 180 156 181 def testRemoveData(self): … … 161 186 self.widget.removeData() 162 187 self.oneDataSetState() 188 self.removeAllData() 163 189 164 190 def testClose(self): … … 166 192 self.assertFalse(self.widget.isClosable()) 167 193 self.widget.close() 168 self.assertTrue(self.widget.isVisible()) 194 self.assertTrue(self.widget.isMinimized()) 195 self.assertTrue(self.widget.dmaxWindow is None) 196 self.assertTrue(self.widget.batchResultsWindow is None) 169 197 self.widget.setClosable(False) 170 198 self.assertFalse(self.widget.isClosable()) 171 199 self.widget.close() 172 self.assertTrue(self.widget.is Visible())200 self.assertTrue(self.widget.isMinimized()) 173 201 self.widget.setClosable(True) 174 202 self.assertTrue(self.widget.isClosable()) 175 203 self.widget.setClosable() 176 204 self.assertTrue(self.widget.isClosable()) 177 self.widget.close() 178 self.assertFalse(self.widget.isVisible()) 205 self.removeAllData() 179 206 180 207 def testGetNFunc(self): … … 198 225 self.assertEqual(cm.output, ['ERROR:root:Incorrect number of terms specified: Nordvest Pizza']) 199 226 self.assertEqual(self.widget.getNFunc(), 10) 227 self.removeAllData() 200 228 201 229 def testSetCurrentData(self): … … 214 242 self.widget.setCurrentData(self.fakeData1) 215 243 self.assertEqual(self.widget._data, self.fakeData1) 216 217 def notestModelChanged(self): 218 """ test the model update """ 219 self.assertTrue(self.widget._calculator.get_dmax(), 140.0) 220 self.widget.maxDistanceInput.setText("750.0") 221 self.assertTrue(self.widget._calculator.get_dmax(), 750.0) 222 self.assertTrue(self.widget._calculator.get_qmax(), 0.0) 223 self.widget.maxQInput.setText("100.0") 224 self.assertTrue(self.widget._calculator.get_dmax(), 100.0) 244 self.removeAllData() 245 246 def testModelChanged(self): 247 """ Test setting the input and the model and vice-versa """ 248 # Initial values 249 self.assertEqual(self.widget._calculator.get_dmax(), 140.0) 250 self.assertEqual(self.widget._calculator.get_qmax(), -1.0) 251 self.assertEqual(self.widget._calculator.get_qmin(), -1.0) 252 self.assertEqual(self.widget._calculator.slit_height, 0.0) 253 self.assertEqual(self.widget._calculator.slit_width, 0.0) 254 self.assertEqual(self.widget._calculator.alpha, 0.0001) 255 # Set new values 256 self.widget.maxDistanceInput.setText("1.0") 257 self.widget.maxQInput.setText("3.0") 258 self.widget.minQInput.setText("5.0") 259 self.widget.slitHeightInput.setText("7.0") 260 self.widget.slitWidthInput.setText("9.0") 261 self.widget.regularizationConstantInput.setText("11.0") 262 # Check new values 263 self.assertEqual(self.widget._calculator.get_dmax(), 1.0) 264 self.assertEqual(self.widget._calculator.get_qmax(), 3.0) 265 self.assertEqual(self.widget._calculator.get_qmin(), 5.0) 266 self.assertEqual(self.widget._calculator.slit_height, 7.0) 267 self.assertEqual(self.widget._calculator.slit_width, 9.0) 268 self.assertEqual(self.widget._calculator.alpha, 11.0) 269 # Change model directly 270 self.widget.model.setItem(WIDGETS.W_MAX_DIST, QtGui.QStandardItem("2.0")) 271 self.widget.model.setItem(WIDGETS.W_QMIN, QtGui.QStandardItem("4.0")) 272 self.widget.model.setItem(WIDGETS.W_QMAX, QtGui.QStandardItem("6.0")) 273 self.widget.model.setItem(WIDGETS.W_SLIT_HEIGHT, QtGui.QStandardItem("8.0")) 274 self.widget.model.setItem(WIDGETS.W_SLIT_WIDTH, QtGui.QStandardItem("10.0")) 275 self.widget.model.setItem(WIDGETS.W_REGULARIZATION, QtGui.QStandardItem("12.0")) 276 # Check values 277 self.assertEqual(self.widget._calculator.get_dmax(), 2.0) 278 self.assertEqual(self.widget._calculator.get_qmin(), 4.0) 279 self.assertEqual(self.widget._calculator.get_qmax(), 6.0) 280 self.assertEqual(self.widget._calculator.slit_height, 8.0) 281 self.assertEqual(self.widget._calculator.slit_width, 10.0) 282 self.assertEqual(self.widget._calculator.alpha, 12.0) 283 self.removeAllData() 225 284 226 285 def notestHelp(self):
Note: See TracChangeset
for help on using the changeset viewer.