[d3ca363] | 1 | import sys |
---|
| 2 | import unittest |
---|
| 3 | |
---|
| 4 | from PyQt4 import QtGui |
---|
| 5 | |
---|
| 6 | # set up import paths |
---|
| 7 | import path_prepare |
---|
| 8 | |
---|
| 9 | # Local |
---|
| 10 | from SetGraphRange import SetGraphRange |
---|
| 11 | |
---|
| 12 | app = QtGui.QApplication(sys.argv) |
---|
| 13 | |
---|
| 14 | class SetGraphRangeTest(unittest.TestCase): |
---|
| 15 | '''Test the SetGraphRange''' |
---|
| 16 | def setUp(self): |
---|
| 17 | '''Create the SetGraphRange''' |
---|
| 18 | |
---|
| 19 | self.widget = SetGraphRange(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.assertEqual(self.widget.windowTitle(), "Set Graph Range") |
---|
| 30 | self.assertIsInstance(self.widget.txtXmin, QtGui.QLineEdit) |
---|
| 31 | self.assertIsInstance(self.widget.txtXmin.validator(), QtGui.QDoubleValidator) |
---|
| 32 | |
---|
| 33 | def testGoodRanges(self): |
---|
| 34 | '''Test the X range values set by caller''' |
---|
| 35 | self.assertEqual(self.widget.xrange(), (0.0, 0.0)) |
---|
| 36 | self.assertEqual(self.widget.yrange(), (0.0, 0.0)) |
---|
| 37 | |
---|
| 38 | new_widget = SetGraphRange(None, ("1.0", 2.0), (8.0, "-2")) |
---|
| 39 | self.assertEqual(new_widget.xrange(), (1.0, 2.0)) |
---|
| 40 | self.assertEqual(new_widget.yrange(), (8.0, -2.0)) |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | def testBadRanges(self): |
---|
| 44 | '''Test the incorrect X range values set by caller''' |
---|
| 45 | with self.assertRaises(ValueError): |
---|
| 46 | new_widget = SetGraphRange(None, ("1.0", "aa"), (None, "@")) |
---|
| 47 | self.assertEqual(new_widget.xrange(), (1.0, 0.0)) |
---|
| 48 | self.assertEqual(new_widget.yrange(), (0.0, 0.0)) |
---|
| 49 | |
---|
| 50 | with self.assertRaises(AssertionError): |
---|
| 51 | new_widget = SetGraphRange(None, "I'm a tuple", None) |
---|
| 52 | self.assertEqual(new_widget.xrange(), (1.0, 0.0)) |
---|
| 53 | self.assertEqual(new_widget.yrange(), (0.0, 0.0)) |
---|
| 54 | |
---|
| 55 | if __name__ == "__main__": |
---|
| 56 | unittest.main() |
---|