source: sasview/src/sas/qtgui/UnitTesting/AddTextTest.py @ 0268aed

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 0268aed was 9290b1a, checked in by Piotr Rozyczko <rozyczko@…>, 8 years ago

Added AddText? to plot, enabled legend drag - SASVIEW-378

  • Property mode set to 100755
File size: 2.0 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 AddText import AddText
12
13app = QtGui.QApplication(sys.argv)
14
15class AddTextTest(unittest.TestCase):
16    '''Test the AddText'''
17    def setUp(self):
18        '''Create the AddText'''
19        self.widget = AddText(None)
20
21    def tearDown(self):
22        '''Destroy the GUI'''
23        self.widget.close()
24        self.widget = None
25
26    def testDefaults(self):
27        '''Test the GUI in its default state'''
28        self.assertIsInstance(self.widget, QtGui.QDialog)
29        self.assertIsInstance(self.widget._font, QtGui.QFont)
30        self.assertEqual(self.widget._color, "black")
31       
32    def testOnFontChange(self):
33        '''Test the QFontDialog output'''
34        font_1 = QtGui.QFont("Helvetica", 15)
35        QtGui.QFontDialog.getFont = MagicMock(return_value=(font_1, True))
36        # Call the method
37        self.widget.onFontChange(None)
38        # Check that the text field got the new font info
39        self.assertEqual(self.widget.textEdit.currentFont(), font_1)
40
41        # See that rejecting the dialog doesn't modify the font
42        font_2 = QtGui.QFont("Arial", 9)
43        QtGui.QFontDialog.getFont = MagicMock(return_value=(font_2, False))
44        # Call the method
45        self.widget.onFontChange(None)
46        # Check that the text field retained the previous font info
47        self.assertEqual(self.widget.textEdit.currentFont(), font_1)
48
49    def testOnColorChange(self):
50        ''' Test the QColorDialog output'''
51        new_color = QtGui.QColor("red")
52        QtGui.QColorDialog.getColor = MagicMock(return_value=new_color)
53        # Call the method
54        self.widget.onColorChange(None)
55        # Check that the text field got the new color info for text
56        self.assertEqual(self.widget.textEdit.palette().color(QtGui.QPalette.Text), new_color)
57        # ... and the hex value of this color is correct
58        self.assertEqual(self.widget.color(), "#ff0000")
59       
60if __name__ == "__main__":
61    unittest.main()
Note: See TracBrowser for help on using the repository browser.