[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 |
---|
| 11 | from AddText import AddText |
---|
| 12 | |
---|
| 13 | app = QtGui.QApplication(sys.argv) |
---|
| 14 | |
---|
| 15 | class 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 | |
---|
| 60 | if __name__ == "__main__": |
---|
| 61 | unittest.main() |
---|