Changeset 3a3f192 in sasview
- Timestamp:
- Mar 29, 2019 1:23:59 PM (6 years ago)
- Branches:
- ESS_GUI_bumps_abstraction
- Parents:
- df3c5d6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingOptionsTest.py
rbfb5d9e r3a3f192 2 2 import unittest 3 3 import webbrowser 4 from bumps import options5 4 6 5 from PyQt5 import QtGui, QtWidgets … … 14 13 15 14 # Local 16 from sas.qtgui.Perspectives.Fitting.FittingOptions import FittingOptions 15 from sas.qtgui.Perspectives.Fitting.FittingOptions import \ 16 FittingOptions, FittingMethod, FittingMethodParameter 17 17 18 18 if not QtWidgets.QApplication.instance(): … … 23 23 def setUp(self): 24 24 '''Create FittingOptions dialog''' 25 self.widget = FittingOptions( None, config=options.FIT_CONFIG)25 self.widget = FittingOptions() 26 26 27 27 def tearDown(self): … … 38 38 # The combo box 39 39 self.assertIsInstance(self.widget.cbAlgorithm, QtWidgets.QComboBox) 40 self.assert Equal(self.widget.cbAlgorithm.count(), 6)40 self.assertTrue(self.widget.cbAlgorithm.count() >= 5) # at least the default bumps algos 41 41 self.assertEqual(self.widget.cbAlgorithm.itemText(0), 'Nelder-Mead Simplex') 42 42 self.assertEqual(self.widget.cbAlgorithm.itemText(4), 'Levenberg-Marquardt') … … 50 50 51 51 # DREAM 52 self.widget.cbAlgorithm.setCurrentText("DREAM") 52 53 self.assertIsInstance(self.widget.samples_dream.validator(), QtGui.QIntValidator) 53 54 self.assertIsInstance(self.widget.burn_dream.validator(), QtGui.QIntValidator) … … 56 57 self.assertIsInstance(self.widget.steps_dream.validator(), QtGui.QIntValidator) 57 58 # DE 59 self.widget.cbAlgorithm.setCurrentText("Differential Evolution") 58 60 self.assertIsInstance(self.widget.steps_de.validator(), QtGui.QIntValidator) 59 61 self.assertIsInstance(self.widget.CR_de.validator(), QtGui.QDoubleValidator) … … 77 79 self.assertTrue(self.widget.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).isEnabled()) 78 80 79 def testOnAlgorithmChange(self):80 '''Test the combo box change callback'''81 # Current ID82 self.assertEqual(self.widget.current_fitter_id, 'lm')83 # index = 084 self.widget.onAlgorithmChange(0)85 # Check Nelder-Mead86 self.assertEqual(self.widget.stackedWidget.currentIndex(), 1)87 self.assertEqual(self.widget.current_fitter_id, 'lm')88 89 # index = 490 self.widget.onAlgorithmChange(4)91 # Check Levenberg-Marquad92 self.assertEqual(self.widget.stackedWidget.currentIndex(), 1)93 self.assertEqual(self.widget.current_fitter_id, 'lm')94 95 81 def testOnApply(self): 96 82 '''Test bumps update''' … … 110 96 111 97 # Check the parameters 112 self.assertEqual( options.FIT_CONFIG.values['dream']['steps'], 50.0)113 self.assertEqual( options.FIT_CONFIG.values['dream']['init'], 'cov')98 self.assertEqual(self.widget.fittingMethods['DREAM'].params['steps'].value, 50.) 99 self.assertEqual(self.widget.fittingMethods['DREAM'].params['init'].value, 'cov') 114 100 115 101 # test disabled until pyQt5 works well … … 141 127 self.assertIn("fit-lm", webbrowser.open.call_args[0][0]) 142 128 143 def test WidgetFromOptions(self):129 def testParamWidget(self): 144 130 '''Test the helper function''' 145 131 # test empty call 146 self.assertIsNone(self.widget. widgetFromOption(None))132 self.assertIsNone(self.widget.paramWidget(None, None)) 147 133 # test silly call 148 self.assertIsNone(self.widget. widgetFromOption('poop'))149 self.assertIsNone(self.widget. widgetFromOption(QtWidgets.QMainWindow()))134 self.assertIsNone(self.widget.paramWidget('poop', 'dsfsd')) 135 self.assertIsNone(self.widget.paramWidget(QtWidgets.QMainWindow(), None)) 150 136 151 137 # Switch to DREAM 152 self.widget.cbAlgorithm.setCurrentIndex(2) 138 self.widget.cbAlgorithm.setCurrentText('DREAM') 139 fm = self.widget.fittingMethods['DREAM'] 153 140 # test smart call 154 self.assertIsInstance(self.widget. widgetFromOption('samples'), QtWidgets.QLineEdit)155 self.assertIsInstance(self.widget. widgetFromOption('init'), QtWidgets.QComboBox)141 self.assertIsInstance(self.widget.paramWidget(fm, 'samples'), QtWidgets.QLineEdit) 142 self.assertIsInstance(self.widget.paramWidget(fm, 'init'), QtWidgets.QComboBox) 156 143 157 def testUpdateWidgetFromBumps(self): 144 def testUpdateConfigFromWidget(self): 145 '''Test the config update''' 146 # test empty call 147 self.assertIsNone(self.widget.updateConfigFromWidget(None)) 148 # test silly call 149 self.assertIsNone(self.widget.updateConfigFromWidget('poop')) 150 self.assertIsNone(self.widget.updateConfigFromWidget(QtWidgets.QMainWindow())) 151 152 # Switch to DREAM 153 self.widget.cbAlgorithm.setCurrentText('DREAM') 154 fm = FittingMethod("dream", "a long dream", [ 155 FittingMethodParameter("samples", "# samples", int, 0), 156 FittingMethodParameter("init", "init func", int, 0)]) 157 # test smart call 158 self.widget.updateConfigFromWidget(fm) 159 self.assertEqual(fm.params['samples'].value, 10000) 160 self.assertEqual(fm.params['init'].value, 'eps') 161 162 def testUpdateWidgetFromConfig(self): 158 163 '''Test the widget update''' 164 self.widget.cbAlgorithm.setCurrentText("Quasi-Newton BFGS") 159 165 # modify some value 160 options.FIT_CONFIG.values['newton']['steps'] = 1234 161 options.FIT_CONFIG.values['newton']['starts'] = 666 162 options.FIT_CONFIG.values['newton']['xtol'] = 0.01 166 self.assertEqual(self.widget.steps_newton.text(), '3000') 167 self.assertEqual(self.widget.starts_newton.text(), '1') 168 self.assertEqual(self.widget.ftol_newton.text(), '1e-06') # default 169 self.assertEqual(self.widget.xtol_newton.text(), '1e-12') 170 fm = self.widget.fittingMethods["Quasi-Newton BFGS"] 171 fm.params['steps'].value = 1234 172 fm.params['starts'].value = 666 173 fm.params['ftol'].value = 1e-6 174 fm.params['xtol'].value = 0.01 163 175 164 176 # Invoke the method for the changed 165 self.widget.updateWidgetFrom Bumps('newton')177 self.widget.updateWidgetFromConfig() 166 178 167 179 # See that the widget picked up the right values
Note: See TracChangeset
for help on using the changeset viewer.