source: sasview/src/sas/qtgui/Plotting/UnitTesting/AddTextTest.py @ 0849aec

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 0849aec was 99ea1b0, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Update for unit tests and minor functionality quirks

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