Ignore:
Timestamp:
Jan 12, 2017 4: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?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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__": 
Note: See TracChangeset for help on using the changeset viewer.