source: sasview/src/sas/qtgui/Plotting/UnitTesting/AddTextTest.py @ 0101c9f

Last change on this file since 0101c9f was 53c771e, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Converted unit tests

  • Property mode set to 100644
File size: 2.1 KB
Line 
1import sys
2import unittest
3from unittest.mock import MagicMock
4
5from PyQt5 import QtGui, QtWidgets
6
7# set up import paths
8import path_prepare
9
10# Local
11from sas.qtgui.Plotting.AddText import AddText
12
13if not QtWidgets.QApplication.instance():
14    app = QtWidgets.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, QtWidgets.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        QtWidgets.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        QtWidgets.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        QtWidgets.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.