source: sasview/src/sas/qtgui/Plotting/UnitTesting/AddTextTest.py @ 441a03f

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 441a03f was 53c771e, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Converted unit tests

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[9290b1a]1import sys
2import unittest
[7fb471d]3from unittest.mock import MagicMock
[9290b1a]4
[53c771e]5from PyQt5 import QtGui, QtWidgets
[9290b1a]6
7# set up import paths
8import path_prepare
9
10# Local
[83eb5208]11from sas.qtgui.Plotting.AddText import AddText
[9290b1a]12
[53c771e]13if not QtWidgets.QApplication.instance():
14    app = QtWidgets.QApplication(sys.argv)
[9290b1a]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'''
[53c771e]29        self.assertIsInstance(self.widget, QtWidgets.QDialog)
[9290b1a]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)
[53c771e]36        QtWidgets.QFontDialog.getFont = MagicMock(return_value=(font_1, True))
[9290b1a]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)
[53c771e]44        QtWidgets.QFontDialog.getFont = MagicMock(return_value=(font_2, False))
[9290b1a]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")
[53c771e]53        QtWidgets.QColorDialog.getColor = MagicMock(return_value=new_color)
[9290b1a]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.