Changeset 03c372d in sasview


Ignore:
Timestamp:
Jan 23, 2017 7:54:43 AM (7 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
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:
5d89f43
Parents:
092a3d9
Message:

Added unit tests to SASVIEW-391

Location:
src/sas/qtgui
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/ColorMap.py

    r092a3d9 r03c372d  
    8080        return (self._norm.vmin, self._norm.vmax) 
    8181 
    82     def onReset(self, event): 
     82    def onReset(self): 
    8383        """ 
    8484        Respond to the Reset button click 
     
    206206        self.redrawColorBar() 
    207207        self.canvas.draw() 
    208  
    209         pass 
  • src/sas/qtgui/Plotter2D.py

    r092a3d9 r03c372d  
    204204        """ 
    205205        color_map_dialog = ColorMap(self, cmap=self.cmap, 
    206                                     zmin=self.vmin, 
    207                                     zmax=self.vmax, 
     206                                    vmin=self.vmin, 
     207                                    vmax=self.vmax, 
    208208                                    data=self.data) 
    209209 
  • src/sas/qtgui/UnitTesting/ColorMapTest.py

    r092a3d9 r03c372d  
    55from PyQt4 import QtGui 
    66from mock import MagicMock 
     7import matplotlib as mpl 
    78 
    89# set up import paths 
     
    4748        self.assertIsInstance(self.widget, QtGui.QDialog) 
    4849 
    49         WarningTestNotImplemented() 
     50        self.assertEqual(self.widget._cmap_orig, "jet") 
     51        self.assertEqual(len(self.widget.all_maps), 144) 
     52        self.assertEqual(len(self.widget.maps), 72) 
     53        self.assertEqual(len(self.widget.rmaps), 72) 
     54 
     55        self.assertEqual(self.widget.lblWidth.text(), "0") 
     56        self.assertEqual(self.widget.lblHeight.text(), "0") 
     57        self.assertEqual(self.widget.lblQmax.text(), "15.8") 
     58        self.assertEqual(self.widget.lblStopRadius.text(), "-1") 
     59        self.assertFalse(self.widget.chkReverse.isChecked()) 
     60        self.assertEqual(self.widget.cbColorMap.count(), 72) 
     61        self.assertEqual(self.widget.cbColorMap.currentIndex(), 60) 
     62 
     63        # validators 
     64        self.assertIsInstance(self.widget.txtMinAmplitude.validator(), QtGui.QDoubleValidator) 
     65        self.assertIsInstance(self.widget.txtMaxAmplitude.validator(), QtGui.QDoubleValidator) 
    5066 
    5167    def testOnReset(self): 
    5268        '''Check the dialog reset function''' 
    53         WarningTestNotImplemented() 
     69        # Set some controls to non-default state 
     70        self.widget.cbColorMap.setCurrentIndex(20) 
     71        self.widget.chkReverse.setChecked(True) 
     72        self.widget.txtMinAmplitude.setText("20.0") 
    5473 
    55     def testInitDetectorData(self): 
    56         '''Check the detector data generator''' 
    57         # possibly to fold into testDefaults 
    58         WarningTestNotImplemented() 
     74        # Reset the widget state 
     75        self.widget.onReset() 
     76 
     77        # Assure things went back to default 
     78        self.assertEqual(self.widget.cbColorMap.currentIndex(), 20) 
     79        self.assertFalse(self.widget.chkReverse.isChecked()) 
     80        self.assertEqual(self.widget.txtMinAmplitude.text(), "") 
    5981 
    6082    def testInitMapCombobox(self): 
    6183        '''Test the combo box initializer''' 
    62         # possible to fold into testDefaults 
    63         WarningTestNotImplemented() 
     84        # Set a color map from the direct list 
     85        self.widget._cmap = "gnuplot" 
     86        self.widget.initMapCombobox() 
     87 
     88        # Check the combobox 
     89        self.assertEqual(self.widget.cbColorMap.currentIndex(), 55) 
     90        self.assertFalse(self.widget.chkReverse.isChecked()) 
     91 
     92        # Set a reversed value 
     93        self.widget._cmap = "hot_r" 
     94        self.widget.initMapCombobox() 
     95        # Check the combobox 
     96        self.assertEqual(self.widget.cbColorMap.currentIndex(), 56) 
     97        self.assertTrue(self.widget.chkReverse.isChecked()) 
     98 
    6499 
    65100    def testOnMapIndexChange(self): 
    66101        '''Test the response to the combo box index change''' 
    67         WarningTestNotImplemented() 
    68102 
    69     def testRedrawColorBar(self): 
    70         '''Test the color bar redrawing''' 
    71         WarningTestNotImplemented() 
     103        self.widget.canvas.draw = MagicMock() 
     104        mpl.colorbar.ColorbarBase = MagicMock() 
     105 
     106        # simulate index change 
     107        self.widget.cbColorMap.setCurrentIndex(1) 
     108 
     109        # Check that draw() got called 
     110        self.assertTrue(self.widget.canvas.draw.called) 
     111        self.assertTrue(mpl.colorbar.ColorbarBase.called) 
    72112 
    73113    def testOnColorMapReversed(self): 
    74114        '''Test reversing the color map functionality''' 
    75         WarningTestNotImplemented() 
     115        # Check the defaults 
     116        self.assertEqual(self.widget._cmap, "jet") 
     117        self.widget.cbColorMap.addItems = MagicMock() 
     118 
     119        # Reverse the choice 
     120        self.widget.onColorMapReversed(True) 
     121 
     122        # check the behaviour 
     123        self.assertEqual(self.widget._cmap, "jet_r") 
     124        self.assertTrue(self.widget.cbColorMap.addItems.called) 
    76125 
    77126    def testOnAmplitudeChange(self): 
    78127        '''Check the callback method for responding to changes in textboxes''' 
    79         WarningTestNotImplemented() 
     128        self.widget.canvas.draw = MagicMock() 
     129        mpl.colors.Normalize = MagicMock() 
     130        mpl.colorbar.ColorbarBase = MagicMock() 
     131 
     132        self.widget.vmin = 0.0 
     133        self.widget.vmax = 100.0 
     134 
     135        # good values in fields 
     136        self.widget.txtMinAmplitude.setText("1.0") 
     137        self.widget.txtMaxAmplitude.setText("10.0") 
     138 
     139        self.widget.onAmplitudeChange() 
     140 
     141        # Check the arguments to Normalize 
     142        mpl.colors.Normalize.assert_called_with(vmin=1.0, vmax=10.0) 
     143        self.assertTrue(self.widget.canvas.draw.called) 
     144 
     145        # Bad values in fields 
     146        self.widget.txtMinAmplitude.setText("cake") 
     147        self.widget.txtMaxAmplitude.setText("more cake") 
     148 
     149        self.widget.onAmplitudeChange() 
     150 
     151        # Check the arguments to Normalize - should be defaults 
     152        mpl.colors.Normalize.assert_called_with(vmin=0.0, vmax=100.0) 
     153        self.assertTrue(self.widget.canvas.draw.called) 
    80154 
    81155 
  • src/sas/qtgui/UnitTesting/Plotter2DTest.py

    r092a3d9 r03c372d  
    6464    def testCalculateDepth(self): 
    6565        ''' Test the depth calculator ''' 
    66         WarningTestNotImplemented() 
     66        self.plotter.data = self.data 
     67 
     68        # Default, log scale 
     69        depth = self.plotter.calculateDepth() 
     70        self.assertEqual(depth, (0.1, 1.e20)) 
     71 
     72        # Change the scale to linear 
     73        self.plotter.scale = 'linear' 
     74        depth = self.plotter.calculateDepth() 
     75        self.assertEqual(depth[0], -32.) 
     76        self.assertAlmostEqual(depth[1], 1.30103, 5) 
    6777 
    6878    def testOnColorMap(self): 
    6979        ''' Respond to the color map event ''' 
    70         WarningTestNotImplemented() 
     80        self.plotter.data = self.data 
     81        self.plotter.plot() 
     82        self.plotter.show() 
     83 
     84        QtGui.QDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Accepted) 
     85 
     86        # Just this one plot 
     87        self.plotter.onColorMap() 
     88 
     89        # Check that exec_ got called 
     90        self.assertTrue(QtGui.QDialog.exec_.called) 
     91 
     92        self.assertEqual(self.plotter.cmap, "jet") 
     93        self.assertEqual(self.plotter.vmin, -0.1) 
     94        self.assertEqual(self.plotter.vmax, 0.1) 
    7195 
    7296    def testOnToggleScale(self): 
Note: See TracChangeset for help on using the changeset viewer.