Changeset 351b53e in sasview
- Timestamp:
- Mar 22, 2017 4:23:49 AM (8 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:
- 0979dfb
- Parents:
- 7248d75d
- Location:
- src/sas/qtgui/Perspectives/Fitting
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
r4d457df r351b53e 31 31 CATEGORY_DEFAULT = "Choose category..." 32 32 CATEGORY_STRUCTURE = "Structure Factor" 33 STRUCTURE_DEFAULT = "None" 33 34 QMIN_DEFAULT = 0.0005 34 35 QMAX_DEFAULT = 0.5 … … 231 232 """ 232 233 structure_factor_list = self.master_category_dict.pop(CATEGORY_STRUCTURE) 233 structure_factors = ["None"] 234 factors = [factor[0] for factor in structure_factor_list] 235 factors.insert(0, STRUCTURE_DEFAULT) 234 236 self.cbStructureFactor.clear() 235 structure_factors = [factor[0] for factor in structure_factor_list] 236 self.cbStructureFactor.addItems(sorted(structure_factors)) 237 self.cbStructureFactor.addItems(sorted(factors)) 237 238 238 239 def onSelectCategory(self): … … 246 247 # Otherwise, just return 247 248 if self._previous_category_index != 0: 249 # We need to block signals, or else state changes on perceived unchanged conditions 250 self.cbCategory.blockSignals(True) 248 251 self.cbCategory.setCurrentIndex(self._previous_category_index) 252 self.cbCategory.blockSignals(False) 249 253 return 250 254 … … 288 292 model = str(self.cbModel.currentText()) 289 293 294 # Reset structure factor 295 self.cbStructureFactor.setCurrentIndex(0) 296 290 297 # SasModel -> QModel 291 298 self.SASModelToQModel(model) … … 357 364 Setting model parameters into table based on selected category 358 365 """ 366 # TODO - modify for structure factor-only choice 367 359 368 # Crete/overwrite model items 360 369 self._model_model.clear() … … 415 424 parameter_name = parameter_name[16:] 416 425 property_name = str(self._poly_model.headerData(model_column, 1).toPyObject()) # Value, min, max, etc. 417 print "%s(%s) => %d" % (parameter_name, property_name, value)426 # print "%s(%s) => %d" % (parameter_name, property_name, value) 418 427 419 428 # Update the sasmodel … … 454 463 property_name = str(self._model_model.headerData(1, model_column).toPyObject()) # Value, min, max, etc. 455 464 456 print "%s(%s) => %d" % (parameter_name, property_name, value)465 # print "%s(%s) => %d" % (parameter_name, property_name, value) 457 466 self.kernel_module.params[parameter_name] = value 458 467 … … 691 700 self._last_model_row = self._model_model.rowCount() 692 701 693 694 702 def modifyShellsInList(self, index): 695 703 """ -
src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingLogicTest.py
r7248d75d r351b53e 125 125 q_0 = numpy.sqrt(qx_0 * qx_0 + qy_0 * qy_0) 126 126 127 data = Data2D(image=x_0, err_image=dx_0, qx_data=qx_0, 128 qy_data=qy_0, q_data=q_0, mask=mask_0, 127 data = Data2D(image=x_0, err_image=dx_0, qx_data=qx_0, 128 qy_data=qy_0, q_data=q_0, mask=mask_0, 129 129 dqx_data=dqx_0, dqy_data=dqy_0) 130 130 -
src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py
r7248d75d r351b53e 6 6 from PyQt4 import QtCore 7 7 from mock import MagicMock 8 from twisted.internet import threads 8 9 9 10 # set up import paths … … 13 14 from sas.qtgui.GuiUtils import * 14 15 from sas.qtgui.Perspectives.Fitting.FittingWidget import * 15 #from sas.qtgui.Perspectives.Fitting.FittingWidget import FittingWidget 16 from sas.qtgui.UnitTesting.TestUtils import QtSignalSpy 17 16 18 from sas.sasgui.guiframe.dataFitting import Data1D 17 19 … … 149 151 def testSignals(self): 150 152 """ 151 Test the widget e xmitted signals153 Test the widget emitted signals 152 154 """ 153 155 pass … … 157 159 Assure proper behaviour on changing category 158 160 """ 159 pass 161 self.widget.show() 162 self.assertEqual(self.widget._previous_category_index, 0) 163 # confirm the model combo contains no models 164 self.assertEqual(self.widget.cbModel.count(), 0) 165 166 # invoke the method by changing the index 167 self.widget.cbCategory.setCurrentIndex(1) 168 169 # test the model combo content 170 self.assertEqual(self.widget.cbModel.count(), 29) 171 172 # Try to change back to default 173 self.widget.cbCategory.setCurrentIndex(0) 174 175 # Observe no such luck 176 self.assertEqual(self.widget.cbCategory.currentIndex(), 1) 177 self.assertEqual(self.widget.cbModel.count(), 29) 178 179 # Set the structure factor 180 structure_index=self.widget.cbCategory.findText(CATEGORY_STRUCTURE) 181 self.widget.cbCategory.setCurrentIndex(structure_index) 182 # check the enablement of controls 183 self.assertFalse(self.widget.cbModel.isEnabled()) 184 self.assertTrue(self.widget.cbStructureFactor.isEnabled()) 160 185 161 186 def testSelectModel(self): … … 163 188 Assure proper behaviour on changing model 164 189 """ 165 pass 190 self.widget.show() 191 # Change the category index so we have some models 192 self.widget.cbCategory.setCurrentIndex(1) 193 194 # check the enablement of controls 195 self.assertTrue(self.widget.cbModel.isEnabled()) 196 self.assertFalse(self.widget.cbStructureFactor.isEnabled()) 197 198 # set up the model update spy 199 # spy = QtSignalSpy(self.widget._model_model, self.widget._model_model.itemChanged) 200 201 # mock the tested methods 202 self.widget.SASModelToQModel = MagicMock() 203 self.widget.createDefaultDataset = MagicMock() 204 self.widget.calculateDataForModel = MagicMock() 205 # 206 # Now change the model 207 self.widget.cbModel.setCurrentIndex(3) 208 self.assertEqual(self.widget.cbModel.currentText(),'correlation_length') 209 210 # No data sent -> no index set, only createDefaultDataset called 211 self.assertTrue(self.widget.createDefaultDataset.called) 212 self.assertTrue(self.widget.SASModelToQModel.called) 213 self.assertFalse(self.widget.calculateDataForModel.called) 214 215 # Let's set a dummy index on widget 216 self.widget._index = QtGui.QStandardItem() 217 # Reset the sasmodel index 218 self.widget.cbModel.setCurrentIndex(1) 219 self.assertEqual(self.widget.cbModel.currentText(),'be_polyelectrolyte') 220 221 # Observe calculateDataForModel called 222 self.assertTrue(self.widget.calculateDataForModel.called) 166 223 167 224 def testSelectFactor(self): … … 169 226 Assure proper behaviour on changing structure factor 170 227 """ 171 pass 228 self.widget.show() 229 # Change the category index so we have some models 230 self.widget.cbCategory.setCurrentIndex(1) 231 # Change the model to one that supports structure factors 232 model_index = self.widget.cbModel.findText('fractal_core_shell') 233 self.widget.cbModel.setCurrentIndex(model_index) 234 235 # Check that the factor combo is active and the default is chosen 236 self.assertTrue(self.widget.cbStructureFactor.isEnabled()) 237 self.assertEqual(self.widget.cbStructureFactor.currentText(), STRUCTURE_DEFAULT) 238 239 # We have this many rows in the model 240 rowcount = self.widget._model_model.rowCount() 241 #self.assertEqual(self.widget._model_model.rowCount(), 8) 242 243 # Change structure factor to something more exciting 244 structure_index = self.widget.cbStructureFactor.findText('squarewell') 245 self.widget.cbStructureFactor.setCurrentIndex(structure_index) 246 247 # We have 4 more rows now 248 self.assertEqual(self.widget._model_model.rowCount(), rowcount+4) 249 250 # Switch models 251 self.widget.cbModel.setCurrentIndex(0) 252 253 # Observe factor reset to None 254 self.assertEqual(self.widget.cbStructureFactor.currentText(), STRUCTURE_DEFAULT) 255 256 257 # TODO once functionality fixed 258 ## Switch category to structure factor 259 #structure_index=self.widget.cbCategory.findText(CATEGORY_STRUCTURE) 260 #self.widget.cbCategory.setCurrentIndex(structure_index) 261 ## Choose the last factor 262 #last_index = self.widget.cbStructureFactor.count() 263 #self.widget.cbStructureFactor.setCurrentIndex(last_index-1) 172 264 173 265 def testReadCategoryInfo(self): … … 175 267 Check the category file reader 176 268 """ 269 # Tested in default checks 177 270 pass 178 271 … … 181 274 Checks the sasmodel parameter update from QModel items 182 275 """ 183 pass 184 185 def testComputeDataRange(self): 186 """ 187 Tests the data range calculator on Data1D/Data2D 188 """ 189 pass 190 191 def testCreateDefault1dData(self): 192 """ 193 Tests the default 1D set 194 """ 195 pass 196 197 def testCreateDefault2dData(self): 198 """ 199 Tests the default 2D set 200 """ 201 pass 202 203 def testCreateTheoryIndex(self): 276 # Tested in default checks 277 pass 278 279 def notestCreateTheoryIndex(self): 204 280 """ 205 281 Test the data->QIndex conversion 206 282 """ 207 pass 208 209 def testCalculate1DForModel(self): 283 # set up the model update spy 284 spy = QtSignalSpy(self.widget._model_model, self.widget.communicate.updateTheoryFromPerspectiveSignal) 285 286 self.widget.show() 287 # Change the category index so we have some models 288 self.widget.cbCategory.setCurrentIndex(1) 289 290 # Create the index 291 self.widget.createTheoryIndex() 292 293 # Check the signal sent 294 print spy 295 296 # Check the index 297 298 def testCalculateDataForModel(self): 210 299 """ 211 300 Check that the fitting 1D data object is ready 212 301 """ 213 pass214 215 def testCalculate2DForModel(self):216 """217 Check that the fitting 2D data object is ready218 """219 pass302 # Mock the thread creation 303 threads.deferToThread = MagicMock() 304 # Call the tested method 305 self.widget.calculateDataForModel() 306 # Test the mock 307 self.assertTrue(threads.deferToThread.called) 308 self.assertEqual(threads.deferToThread.call_args_list[0][0][0].__name__, "compute") 220 309 221 310 def testComplete1D(self): … … 223 312 Check that a new 1D plot is generated 224 313 """ 314 # TODO when chisqr method coded 225 315 pass 226 316 … … 229 319 Check that a new 2D plot is generated 230 320 """ 321 # TODO when chisqr method coded 231 322 pass 232 323 … … 235 326 Test the polydispersity model setup 236 327 """ 237 pass 328 self.widget.show() 329 # Change the category index so we have a model with no poly 330 self.widget.cbCategory.setCurrentIndex(1) 331 # Check the poly model 332 self.assertEqual(self.widget._poly_model.rowCount(), 0) 333 self.assertEqual(self.widget._poly_model.columnCount(), 0) 334 335 # Change the category index so we have a model available 336 self.widget.cbCategory.setCurrentIndex(2) 337 338 # Check the poly model 339 self.assertEqual(self.widget._poly_model.rowCount(), 3) 340 self.assertEqual(self.widget._poly_model.columnCount(), 7) 341 342 # Test the header 343 self.assertEqual(self.widget.lstPoly.horizontalHeader().count(), 7) 344 self.assertFalse(self.widget.lstPoly.horizontalHeader().stretchLastSection()) 345 346 # Test presence of comboboxes in last column 347 for row in xrange(self.widget._poly_model.rowCount()): 348 func_index = self.widget._poly_model.index(row, 6) 349 self.assertTrue(isinstance(self.widget.lstPoly.indexWidget(func_index), QtGui.QComboBox)) 350 self.assertIn('Distribution of', self.widget._poly_model.item(row, 0).text()) 238 351 239 352 def testSetMagneticModel(self): … … 241 354 Test the magnetic model setup 242 355 """ 243 pass 356 self.widget.show() 357 # Change the category index so we have a model available 358 self.widget.cbCategory.setCurrentIndex(2) 359 360 # Check the magnetic model 361 self.assertEqual(self.widget._magnet_model.rowCount(), 9) 362 self.assertEqual(self.widget._magnet_model.columnCount(), 5) 363 364 # Test the header 365 self.assertEqual(self.widget.lstMagnetic.horizontalHeader().count(), 5) 366 self.assertFalse(self.widget.lstMagnetic.horizontalHeader().stretchLastSection()) 367 368 # Test rows 369 for row in xrange(self.widget._magnet_model.rowCount()): 370 func_index = self.widget._magnet_model.index(row, 0) 371 self.assertIn(':', self.widget._magnet_model.item(row, 0).text()) 372 244 373 245 374 def testAddExtraShells(self): … … 253 382 Test the additional rows added by modifying the shells combobox 254 383 """ 255 pass 384 self.widget.show() 385 # Change the model to multi shell 386 self.widget.cbCategory.setCurrentIndex(2) 387 self.widget.cbModel.setCurrentIndex(4) 388 389 # Assure we have the combobox available 390 last_row = self.widget._last_model_row 391 func_index = self.widget._model_model.index(last_row-1, 1) 392 self.assertIsInstance(self.widget.lstParams.indexWidget(func_index), QtGui.QComboBox) 393 394 # Change the combo box index 395 self.widget.lstParams.indexWidget(func_index).setCurrentIndex(3) 396 397 # Check that the number of rows increased 398 more_rows = self.widget._model_model.rowCount() - last_row 399 self.assertEqual(more_rows, 6) # 6 new rows: 2 params per index 400 401 # Back to 0 402 self.widget.lstParams.indexWidget(func_index).setCurrentIndex(0) 403 self.assertEqual(self.widget._model_model.rowCount(), last_row) 256 404 257 405
Note: See TracChangeset
for help on using the changeset viewer.