source: sasview/src/sas/qtgui/UnitTesting/PlotPropertiesTest.py @ db5cd8d

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since db5cd8d was db5cd8d, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Added tests for PlotProperties?

  • Property mode set to 100755
File size: 3.1 KB
RevLine 
[87cc73a]1import sys
2import unittest
[db5cd8d]3from mock import MagicMock
[87cc73a]4
5from PyQt4 import QtGui
6
7# set up import paths
8import path_prepare
9
10# Local
11from PlotProperties import PlotProperties
12
13app = QtGui.QApplication(sys.argv)
14
15class PlotPropertiesTest(unittest.TestCase):
16    '''Test the PlotProperties'''
17    def setUp(self):
18        '''Create the PlotProperties'''
19
[db5cd8d]20        self.widget = PlotProperties(None, 
21                         color=1,
22                         marker=3,
23                         marker_size=10,
24                         legend="LL")
[87cc73a]25
26    def tearDown(self):
27        '''Destroy the GUI'''
28        self.widget.close()
29        self.widget = None
30
31    def testDefaults(self):
32        '''Test the GUI in its default state'''
33        self.assertIsInstance(self.widget, QtGui.QDialog)
34        self.assertEqual(self.widget.windowTitle(), "Modify Plot Properties")
[db5cd8d]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)
[87cc73a]41       
42    def testOnColorChange(self):
43        '''Test the response to color change event'''
[db5cd8d]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
[87cc73a]69
70    def testOnColorIndexChange(self):
71        '''Test the response to color index change event'''
[db5cd8d]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)
[87cc73a]88
89if __name__ == "__main__":
90    unittest.main()
Note: See TracBrowser for help on using the repository browser.