Changeset 06b0138 in sasview for src/sas/qtgui/Perspectives/Fitting/UnitTesting
- Timestamp:
- Jun 8, 2017 3:12:46 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:
- 70080a0
- Parents:
- aca8418
- Location:
- src/sas/qtgui/Perspectives/Fitting/UnitTesting
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingUtilitiesTest.py
rdc5ef15 r06b0138 10 10 from sasmodels import generate 11 11 from sasmodels import modelinfo 12 from sasmodels.sasview_model import load_standard_models 12 13 13 14 # Tested module … … 94 95 # Use a single-shell parameter 95 96 model_name = "barbell" 96 kernel_module = generate.load_kernel_module(model_name) 97 models = load_standard_models() 98 99 kernel_module = generate.load_kernel_module(model_name) 100 kernel_module_o = None 101 for model in models: 102 if model.name == model_name: 103 kernel_module_o = model() 104 self.assertIsNotNone(kernel_module_o) 97 105 barbell_parameters = modelinfo.make_parameter_table(getattr(kernel_module, 'parameters', [])) 98 106 99 params = FittingUtilities.addParametersToModel(barbell_parameters, True)107 params = FittingUtilities.addParametersToModel(barbell_parameters, kernel_module_o, True) 100 108 101 109 # Test the resulting model … … 109 117 model_name = "core_multi_shell" 110 118 kernel_module = generate.load_kernel_module(model_name) 119 kernel_module_o = None 120 for model in models: 121 if model.name == model_name: 122 kernel_module_o = model() 123 self.assertIsNotNone(kernel_module_o) 111 124 multi_parameters = modelinfo.make_parameter_table(getattr(kernel_module, 'parameters', [])) 112 125 113 params = FittingUtilities.addParametersToModel(multi_parameters, False)126 params = FittingUtilities.addParametersToModel(multi_parameters, kernel_module_o, False) 114 127 115 128 # Test the resulting model … … 127 140 model_name = "core_multi_shell" 128 141 kernel_module = generate.load_kernel_module(model_name) 142 models = load_standard_models() 143 kernel_module_o = None 144 for model in models: 145 if model.name == model_name: 146 kernel_module_o = model() 147 self.assertIsNotNone(kernel_module_o) 129 148 multi_parameters = modelinfo.make_parameter_table(getattr(kernel_module, 'parameters', [])) 130 149 131 params = FittingUtilities.addParametersToModel(multi_parameters, True)150 params = FittingUtilities.addParametersToModel(multi_parameters, kernel_module_o, True) 132 151 133 152 # Test the resulting model -
src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py
rfd1ae6d1 r06b0138 35 35 """Destroy the GUI""" 36 36 self.widget.close() 37 self.widget = None37 del self.widget 38 38 39 39 def testDefaults(self): … … 84 84 """ 85 85 Test if models have been loaded properly 86 :return:87 86 """ 88 87 fittingWindow = self.widget 89 88 89 self.assertIsInstance(fittingWindow.lstPoly.itemDelegate(), QtGui.QStyledItemDelegate) 90 90 #Test loading from json categories 91 91 fittingWindow.SASModelToQModel("cylinder") … … 95 95 self.assertEqual(str(pd_index.data().toString()), "Distribution of length") 96 96 97 # test the delegate a bit 98 delegate = fittingWindow.lstPoly.itemDelegate() 99 self.assertEqual(len(delegate.POLYDISPERSE_FUNCTIONS), 5) 100 self.assertEqual(delegate.POLY_EDITABLE_PARAMS, [2, 3, 4, 5]) 101 self.assertEqual(delegate.POLY_FUNCTION, 6) 102 self.assertIsInstance(delegate.combo_updated, QtCore.pyqtBoundSignal) 103 97 104 def testSelectStructureFactor(self): 98 105 """ 99 106 Test if structure factors have been loaded properly 100 :return:101 107 """ 102 108 fittingWindow = self.widget … … 340 346 #self.assertTrue(isinstance(self.widget.lstPoly.indexWidget(func_index), QtGui.QComboBox)) 341 347 self.assertIn('Distribution of', self.widget._poly_model.item(row, 0).text()) 348 #self.widget.close() 349 350 def testPolyModelChange(self): 351 """ 352 Polydispersity model changed - test all possible scenarios 353 """ 354 self.widget.show() 355 # Change the category index so we have a model with polydisp 356 category_index = self.widget.cbCategory.findText("Cylinder") 357 self.widget.cbCategory.setCurrentIndex(category_index) 358 359 # click on a poly parameter checkbox 360 index = self.widget._poly_model.index(0,0) 361 # Set the checbox 362 self.widget._poly_model.item(0,0).setCheckState(2) 363 # Assure the parameter is added 364 self.assertEqual(self.widget.parameters_to_fit, ['radius_bell.width']) 365 366 # Add another parameter 367 self.widget._poly_model.item(2,0).setCheckState(2) 368 # Assure the parameters are added 369 self.assertEqual(self.widget.parameters_to_fit, ['radius_bell.width', 'length.width']) 370 371 # Change the min/max values 372 self.assertEqual(self.widget.kernel_module.details['radius_bell'][1], 0.0) 373 self.widget._poly_model.item(0,2).setText("1.0") 374 self.assertEqual(self.widget.kernel_module.details['radius_bell'][1], 1.0) 375 376 # Change the number of points 377 self.assertEqual(self.widget.kernel_module.getParam('radius_bell.npts'), 35) 378 self.widget._poly_model.item(0,4).setText("22") 379 self.assertEqual(self.widget.kernel_module.getParam('radius_bell.npts'), 22) 380 # try something stupid 381 self.widget._poly_model.item(0,4).setText("butt") 382 # see that this didn't annoy the control at all 383 self.assertEqual(self.widget.kernel_module.getParam('radius_bell.npts'), 22) 384 385 # Change the number of sigmas 386 self.assertEqual(self.widget.kernel_module.getParam('radius_bell.nsigmas'), 3) 387 self.widget._poly_model.item(0,5).setText("222") 388 self.assertEqual(self.widget.kernel_module.getParam('radius_bell.nsigmas'), 222) 389 # try something stupid again 390 self.widget._poly_model.item(0,4).setText("beer") 391 # no efect 392 self.assertEqual(self.widget.kernel_module.getParam('radius_bell.nsigmas'), 222) 393 394 def testOnPolyComboIndexChange(self): 395 """ 396 Test the slot method for polydisp. combo box index change 397 """ 398 self.widget.show() 399 # Change the category index so we have a model with polydisp 400 category_index = self.widget.cbCategory.findText("Cylinder") 401 self.widget.cbCategory.setCurrentIndex(category_index) 402 403 # call method with default settings 404 self.widget.onPolyComboIndexChange('gaussian', 0) 405 # check values 406 self.assertEqual(self.widget.kernel_module.getParam('radius_bell.npts'), 35) 407 self.assertEqual(self.widget.kernel_module.getParam('radius_bell.nsigmas'), 3) 408 # Change the index 409 self.widget.onPolyComboIndexChange('rectangle', 0) 410 # check values 411 self.assertEqual(self.widget.kernel_module.getParam('radius_bell.npts'), 35) 412 self.assertEqual(self.widget.kernel_module.getParam('radius_bell.nsigmas'), 1.70325) 413 # Change the index 414 self.widget.onPolyComboIndexChange('lognormal', 0) 415 # check values 416 self.assertEqual(self.widget.kernel_module.getParam('radius_bell.npts'), 80) 417 self.assertEqual(self.widget.kernel_module.getParam('radius_bell.nsigmas'), 8) 418 # Change the index 419 self.widget.onPolyComboIndexChange('schulz', 0) 420 # check values 421 self.assertEqual(self.widget.kernel_module.getParam('radius_bell.npts'), 80) 422 self.assertEqual(self.widget.kernel_module.getParam('radius_bell.nsigmas'), 8) 423 424 # mock up file load 425 self.widget.loadPolydispArray = MagicMock() 426 # Change to 'array' 427 self.widget.onPolyComboIndexChange('array', 0) 428 # See the mock fire 429 self.assertTrue(self.widget.loadPolydispArray.called) 430 431 def testLoadPolydispArray(self): 432 """ 433 Test opening of the load file dialog for 'array' polydisp. function 434 """ 435 filename = os.path.join("UnitTesting", "testdata_noexist.txt") 436 QtGui.QFileDialog.getOpenFileName = MagicMock(return_value=filename) 437 self.widget.show() 438 # Change the category index so we have a model with polydisp 439 category_index = self.widget.cbCategory.findText("Cylinder") 440 self.widget.cbCategory.setCurrentIndex(category_index) 441 442 self.widget.onPolyComboIndexChange('array', 0) 443 # check values - unchanged since the file doesn't exist 444 self.assertTrue(self.widget._poly_model.item(0, 1).isEnabled()) 445 with self.assertRaises(AttributeError): 446 self.widget.disp_model() 447 448 # good file 449 filename = os.path.join("UnitTesting", "testdata.txt") 450 QtGui.QFileDialog.getOpenFileName = MagicMock(return_value=filename) 451 452 self.widget.onPolyComboIndexChange('array', 0) 453 # check values - disabled control, present weights 454 self.assertFalse(self.widget._poly_model.item(0, 1).isEnabled()) 455 self.assertEqual(self.widget.disp_model.weights[0], 2.83954) 456 self.assertEqual(len(self.widget.disp_model.weights), 19) 457 self.assertEqual(len(self.widget.disp_model.values), 19) 458 self.assertEqual(self.widget.disp_model.values[0], 0.0) 459 self.assertEqual(self.widget.disp_model.values[18], 3.67347) 342 460 343 461 def testSetMagneticModel(self):
Note: See TracChangeset
for help on using the changeset viewer.