Changeset 3a3f192 in sasview


Ignore:
Timestamp:
Mar 29, 2019 1:23:59 PM (5 years ago)
Author:
ibressler
Branches:
ESS_GUI_bumps_abstraction
Parents:
df3c5d6
Message:

FittingOptions?: adjusted tests to new implementation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingOptionsTest.py

    rbfb5d9e r3a3f192  
    22import unittest 
    33import webbrowser 
    4 from bumps import options 
    54 
    65from PyQt5 import QtGui, QtWidgets 
     
    1413 
    1514# Local 
    16 from sas.qtgui.Perspectives.Fitting.FittingOptions import FittingOptions 
     15from sas.qtgui.Perspectives.Fitting.FittingOptions import \ 
     16        FittingOptions, FittingMethod, FittingMethodParameter 
    1717 
    1818if not QtWidgets.QApplication.instance(): 
     
    2323    def setUp(self): 
    2424        '''Create FittingOptions dialog''' 
    25         self.widget = FittingOptions(None, config=options.FIT_CONFIG) 
     25        self.widget = FittingOptions() 
    2626 
    2727    def tearDown(self): 
     
    3838        # The combo box 
    3939        self.assertIsInstance(self.widget.cbAlgorithm, QtWidgets.QComboBox) 
    40         self.assertEqual(self.widget.cbAlgorithm.count(), 6) 
     40        self.assertTrue(self.widget.cbAlgorithm.count() >= 5) # at least the default bumps algos 
    4141        self.assertEqual(self.widget.cbAlgorithm.itemText(0), 'Nelder-Mead Simplex') 
    4242        self.assertEqual(self.widget.cbAlgorithm.itemText(4), 'Levenberg-Marquardt') 
     
    5050         
    5151        # DREAM 
     52        self.widget.cbAlgorithm.setCurrentText("DREAM") 
    5253        self.assertIsInstance(self.widget.samples_dream.validator(), QtGui.QIntValidator) 
    5354        self.assertIsInstance(self.widget.burn_dream.validator(), QtGui.QIntValidator) 
     
    5657        self.assertIsInstance(self.widget.steps_dream.validator(), QtGui.QIntValidator) 
    5758        # DE 
     59        self.widget.cbAlgorithm.setCurrentText("Differential Evolution") 
    5860        self.assertIsInstance(self.widget.steps_de.validator(), QtGui.QIntValidator) 
    5961        self.assertIsInstance(self.widget.CR_de.validator(), QtGui.QDoubleValidator) 
     
    7779        self.assertTrue(self.widget.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).isEnabled()) 
    7880 
    79     def testOnAlgorithmChange(self): 
    80         '''Test the combo box change callback''' 
    81         # Current ID 
    82         self.assertEqual(self.widget.current_fitter_id, 'lm') 
    83         # index = 0 
    84         self.widget.onAlgorithmChange(0) 
    85         # Check Nelder-Mead 
    86         self.assertEqual(self.widget.stackedWidget.currentIndex(), 1) 
    87         self.assertEqual(self.widget.current_fitter_id, 'lm') 
    88  
    89         # index = 4 
    90         self.widget.onAlgorithmChange(4) 
    91         # Check Levenberg-Marquad 
    92         self.assertEqual(self.widget.stackedWidget.currentIndex(), 1) 
    93         self.assertEqual(self.widget.current_fitter_id, 'lm') 
    94  
    9581    def testOnApply(self): 
    9682        '''Test bumps update''' 
     
    11096 
    11197        # 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') 
    114100 
    115101    # test disabled until pyQt5 works well 
     
    141127        self.assertIn("fit-lm", webbrowser.open.call_args[0][0]) 
    142128 
    143     def testWidgetFromOptions(self): 
     129    def testParamWidget(self): 
    144130        '''Test the helper function''' 
    145131        # test empty call 
    146         self.assertIsNone(self.widget.widgetFromOption(None)) 
     132        self.assertIsNone(self.widget.paramWidget(None, None)) 
    147133        # 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)) 
    150136 
    151137        # Switch to DREAM 
    152         self.widget.cbAlgorithm.setCurrentIndex(2) 
     138        self.widget.cbAlgorithm.setCurrentText('DREAM') 
     139        fm = self.widget.fittingMethods['DREAM'] 
    153140        # 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) 
    156143 
    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): 
    158163        '''Test the widget update''' 
     164        self.widget.cbAlgorithm.setCurrentText("Quasi-Newton BFGS") 
    159165        # 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 
    163175 
    164176        # Invoke the method for the changed  
    165         self.widget.updateWidgetFromBumps('newton') 
     177        self.widget.updateWidgetFromConfig() 
    166178 
    167179        # See that the widget picked up the right values 
Note: See TracChangeset for help on using the changeset viewer.