Changeset db5cd8d in sasview


Ignore:
Timestamp:
Jan 12, 2017 2:09:23 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:
2e3e959
Parents:
87cc73a
Message:

Added tests for PlotProperties?

Location:
src/sas/qtgui
Files:
5 edited

Legend:

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

    r87cc73a rdb5cd8d  
    2727 
    2828        # Fill out the color combobox 
    29         self.cbColor.addItems(COLORS.keys()) 
     29        self.cbColor.addItems(COLORS.keys()[:-1]) 
    3030        # data1d.custom_color can now be a simple integer, 
    3131        # specifying COLORS dict index or a string containing 
  • src/sas/qtgui/UnitTesting/PlotPropertiesTest.py

    r87cc73a rdb5cd8d  
    11import sys 
    22import unittest 
     3from mock import MagicMock 
    34 
    45from PyQt4 import QtGui 
     
    67# set up import paths 
    78import path_prepare 
    8  
    9 from UnitTesting.TestUtils import WarningNotImplemented 
    109 
    1110# Local 
     
    1918        '''Create the PlotProperties''' 
    2019 
    21         self.widget = PlotProperties(None) 
     20        self.widget = PlotProperties(None,  
     21                         color=1, 
     22                         marker=3, 
     23                         marker_size=10, 
     24                         legend="LL") 
    2225 
    2326    def tearDown(self): 
     
    3033        self.assertIsInstance(self.widget, QtGui.QDialog) 
    3134        self.assertEqual(self.widget.windowTitle(), "Modify Plot Properties") 
     35 
     36        # Check the combo boxes 
     37        self.assertEqual(self.widget.cbColor.currentText(), "Green") 
     38        self.assertEqual(self.widget.cbShape.currentText(), "Triangle Down") 
     39        self.assertEqual(self.widget.txtLegend.text(), "LL") 
     40        self.assertEqual(self.widget.sbSize.value(), 10) 
    3241         
    3342    def testOnColorChange(self): 
    3443        '''Test the response to color change event''' 
    35         WarningNotImplemented(sys._getframe().f_code.co_name) 
     44        # Accept the new color 
     45        QtGui.QColorDialog.getColor = MagicMock(return_value=QtGui.QColor(255, 0, 255)) 
     46 
     47        self.widget.onColorChange(None) 
     48 
     49        self.assertEqual(self.widget.color(), "#ff00ff") 
     50        self.assertTrue(self.widget.custom_color) 
     51        self.assertEqual(self.widget.cbColor.currentIndex(), 7) 
     52        self.assertEqual(self.widget.cbColor.currentText(), "Custom") 
     53 
     54        # Reset the color - this will remove "Custom" from the combobox 
     55        # and set its index to "Green" 
     56        self.widget.cbColor.setCurrentIndex(1) 
     57        self.assertEqual(self.widget.cbColor.currentText(), "Green") 
     58 
     59        # Cancel the dialog now 
     60        bad_color = QtGui.QColor() # constructs an invalid color 
     61        QtGui.QColorDialog.getColor = MagicMock(return_value=bad_color) 
     62        self.widget.onColorChange(None) 
     63 
     64        self.assertEqual(self.widget.color(), 1) 
     65        self.assertFalse(self.widget.custom_color) 
     66        self.assertEqual(self.widget.cbColor.currentIndex(), 1) 
     67        self.assertEqual(self.widget.cbColor.currentText(), "Green") 
     68 
    3669 
    3770    def testOnColorIndexChange(self): 
    3871        '''Test the response to color index change event''' 
    39         WarningNotImplemented(sys._getframe().f_code.co_name) 
    40      
     72        # Intitial population of the color combo box 
     73        self.widget.onColorIndexChange(0) 
     74        self.assertEqual(self.widget.cbColor.count(), 7) 
     75        # Block the callback so we can update the cb 
     76        self.widget.cbColor.blockSignals(True) 
     77        # Add the Custom entry 
     78        self.widget.cbColor.addItems(["Custom"]) 
     79        # Unblock the callback 
     80        self.widget.cbColor.blockSignals(False) 
     81        # Assert the new CB 
     82        self.assertEqual(self.widget.cbColor.count(), 8) 
     83        # Call the method 
     84        self.widget.onColorIndexChange(0) 
     85        # see that the Custom entry disappeared 
     86        self.assertEqual(self.widget.cbColor.count(), 7) 
     87        self.assertEqual(self.widget.cbColor.findText("Custom"), -1) 
    4188 
    4289if __name__ == "__main__": 
  • src/sas/qtgui/UnitTesting/PlotUtilitiesTest.py

    r87cc73a rdb5cd8d  
    33from collections import OrderedDict 
    44 
    5 from UnitTesting.TestUtils import WarningNotImplemented 
     5from UnitTesting.TestUtils import WarningTestNotImplemented 
    66 
    77# Tested module 
     
    2525    def testBuildMatrix(self): 
    2626        """ build matrix for 2d plot from a vector """ 
    27         WarningNotImplemented(sys._getframe().f_code.co_name) 
     27        WarningTestNotImplemented() 
    2828 
    2929    def testGetBins(self): 
    3030        """ test 1d arrays of the index with square binning """ 
    31         WarningNotImplemented(sys._getframe().f_code.co_name) 
     31        WarningTestNotImplemented() 
    3232 
    3333    def testFillupPixels(self): 
    3434        """ test filling z values of the empty cells of 2d image matrix """ 
    35         WarningNotImplemented(sys._getframe().f_code.co_name) 
     35        WarningTestNotImplemented() 
    3636 
    3737    def testRescale(sef): 
    3838        """ test the helper function for step based zooming """ 
    39         WarningNotImplemented(sys._getframe().f_code.co_name) 
     39        WarningTestNotImplemented() 
    4040 
    4141    def testGgetValidColor(self): 
    4242        """ test that the method returns a color understood by MPL """ 
    43         WarningNotImplemented(sys._getframe().f_code.co_name) 
     43        WarningTestNotImplemented() 
    4444 
    4545if __name__ == "__main__": 
  • src/sas/qtgui/UnitTesting/PlotterTest.py

    r87cc73a rdb5cd8d  
    1313from sas.sasgui.guiframe.dataFitting import Data1D 
    1414from sas.sasgui.guiframe.dataFitting import Data2D 
    15 from UnitTesting.TestUtils import WarningNotImplemented 
     15from UnitTesting.TestUtils import WarningTestNotImplemented 
    1616 
    1717# Tested module 
     
    224224    def testOnLinearFit(self): 
    225225        """ Checks the response to LinearFit call """ 
    226         WarningNotImplemented(sys._getframe().f_code.co_name) 
     226        WarningTestNotImplemented() 
    227227 
    228228    def testOnRemovePlot(self): 
    229229        """ Assure plots get removed when requested """ 
    230         WarningNotImplemented(sys._getframe().f_code.co_name) 
     230        WarningTestNotImplemented() 
    231231 
    232232    def testRemovePlot(self): 
    233233        """ Test plot removal """ 
    234         WarningNotImplemented(sys._getframe().f_code.co_name) 
     234        WarningTestNotImplemented() 
    235235 
    236236    def testOnToggleHideError(self): 
    237237        """ Test the error bar toggle on plots """ 
    238         WarningNotImplemented(sys._getframe().f_code.co_name) 
     238        WarningTestNotImplemented() 
    239239 
    240240    def testOnFitDisplay(self): 
    241241        """ Test the fit line display on the chart """ 
    242         WarningNotImplemented(sys._getframe().f_code.co_name) 
     242        WarningTestNotImplemented() 
    243243 
    244244    def testReplacePlot(self): 
    245245        """ Test the plot refresh functionality """ 
    246         WarningNotImplemented(sys._getframe().f_code.co_name) 
     246        WarningTestNotImplemented() 
    247247 
    248248    def testReplacePlot(self): 
    249249        """ Test the plot refresh functionality """ 
    250         WarningNotImplemented(sys._getframe().f_code.co_name) 
     250        WarningTestNotImplemented(sys._getframe().f_code.co_name) 
    251251 
    252252    def testOnModifyPlot(self): 
    253253        """ Test the functionality for changing plot properties """ 
    254         WarningNotImplemented(sys._getframe().f_code.co_name) 
     254        WarningTestNotImplemented() 
    255255 
    256256if __name__ == "__main__": 
  • src/sas/qtgui/UnitTesting/TestUtils.py

    r87cc73a rdb5cd8d  
    22from PyQt4.QtGui import * 
    33from PyQt4.QtTest import * 
     4import inspect 
    45 
    5 def WarningNotImplemented(method_name): 
    6     """ Prints warning about a non-implemented test """ 
    7     print("\nWARNING: %s needs implementing!"%method_name) 
     6def WarningTestNotImplemented(method_name=None): 
     7    """ 
     8    Prints warning about a non-implemented test. 
     9    Test name retrieved from stack trace. 
     10    """ 
     11    if method_name is not None: 
     12        print("\nWARNING: %s needs implementing!"%method_name) 
     13    else: 
     14        (frame, filename, line_number, 
     15            function_name, lines, index) = inspect.getouterframes(inspect.currentframe())[1] 
     16        print("\nWARNING: %s needs implementing!"%function_name) 
    817 
    918class QtSignalSpy(QObject): 
Note: See TracChangeset for help on using the changeset viewer.