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