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

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 c416a17 was 83eb5208, checked in by Piotr Rozyczko <rozyczko@…>, 8 years ago

Putting files in more ordered fashion

  • Property mode set to 100644
File size: 3.6 KB
Line 
1import sys
2import unittest
3from mock import MagicMock
4
5from PyQt4 import QtGui
6
7# set up import paths
8import path_prepare
9
10# Local
11from sas.qtgui.Plotting.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
20        self.widget = PlotProperties(None,
21                         color=1,
22                         marker=3,
23                         marker_size=10,
24                         legend="LL")
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")
35
36        # Check the combo boxes
37        self.assertEqual(self.widget.cbColor.currentText(), "Green")
38        self.assertEqual(self.widget.cbColor.count(), 7)
39        self.assertEqual(self.widget.cbShape.currentText(), "Triangle Down")
40        self.assertEqual(self.widget.txtLegend.text(), "LL")
41        self.assertEqual(self.widget.sbSize.value(), 10)
42
43    def testDefaultsWithCustomColor(self):
44        '''Test the GUI when called with custom color'''
45        widget = PlotProperties(None,
46                         color="#FF00FF",
47                         marker=7,
48                         marker_size=10,
49                         legend="LL")
50
51        self.assertEqual(widget.cbColor.currentText(), "Custom")
52        self.assertEqual(widget.cbColor.count(), 8)
53       
54    def testOnColorChange(self):
55        '''Test the response to color change event'''
56        # Accept the new color
57        QtGui.QColorDialog.getColor = MagicMock(return_value=QtGui.QColor(255, 0, 255))
58
59        self.widget.onColorChange()
60
61        self.assertEqual(self.widget.color(), "#ff00ff")
62        self.assertTrue(self.widget.custom_color)
63        self.assertEqual(self.widget.cbColor.currentIndex(), 7)
64        self.assertEqual(self.widget.cbColor.currentText(), "Custom")
65
66        # Reset the color - this will remove "Custom" from the combobox
67        # and set its index to "Green"
68        self.widget.cbColor.setCurrentIndex(1)
69        self.assertEqual(self.widget.cbColor.currentText(), "Green")
70
71        # Cancel the dialog now
72        bad_color = QtGui.QColor() # constructs an invalid color
73        QtGui.QColorDialog.getColor = MagicMock(return_value=bad_color)
74        self.widget.onColorChange()
75
76        self.assertEqual(self.widget.color(), 1)
77        self.assertFalse(self.widget.custom_color)
78        self.assertEqual(self.widget.cbColor.currentIndex(), 1)
79        self.assertEqual(self.widget.cbColor.currentText(), "Green")
80
81
82    def testOnColorIndexChange(self):
83        '''Test the response to color index change event'''
84        # Intitial population of the color combo box
85        self.widget.onColorIndexChange()
86        self.assertEqual(self.widget.cbColor.count(), 7)
87        # Block the callback so we can update the cb
88        self.widget.cbColor.blockSignals(True)
89        # Add the Custom entry
90        self.widget.cbColor.addItems(["Custom"])
91        # Unblock the callback
92        self.widget.cbColor.blockSignals(False)
93        # Assert the new CB
94        self.assertEqual(self.widget.cbColor.count(), 8)
95        # Call the method
96        self.widget.onColorIndexChange()
97        # see that the Custom entry disappeared
98        self.assertEqual(self.widget.cbColor.count(), 7)
99        self.assertEqual(self.widget.cbColor.findText("Custom"), -1)
100
101if __name__ == "__main__":
102    unittest.main()
Note: See TracBrowser for help on using the repository browser.