[9290b1a] | 1 | import sys |
---|
| 2 | import unittest |
---|
| 3 | from mock import MagicMock |
---|
| 4 | |
---|
| 5 | from PyQt4 import QtGui |
---|
| 6 | |
---|
| 7 | # set up import paths |
---|
| 8 | import path_prepare |
---|
| 9 | |
---|
| 10 | # Local |
---|
[83eb5208] | 11 | from sas.qtgui.Plotting.AddText import AddText |
---|
[9290b1a] | 12 | |
---|
[464cd07] | 13 | if not QtGui.QApplication.instance(): |
---|
| 14 | app = QtGui.QApplication(sys.argv) |
---|
[9290b1a] | 15 | |
---|
| 16 | class 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 | |
---|
| 61 | if __name__ == "__main__": |
---|
| 62 | unittest.main() |
---|