[d3ca363] | 1 | import sys |
---|
| 2 | import unittest |
---|
| 3 | |
---|
[53c771e] | 4 | from PyQt5 import QtGui, QtWidgets |
---|
[d3ca363] | 5 | |
---|
| 6 | # set up import paths |
---|
[83eb5208] | 7 | import sas.qtgui.path_prepare |
---|
[d3ca363] | 8 | |
---|
| 9 | # Local |
---|
[83eb5208] | 10 | from sas.qtgui.Plotting.SetGraphRange import SetGraphRange |
---|
[d3ca363] | 11 | |
---|
[53c771e] | 12 | if not QtWidgets.QApplication.instance(): |
---|
| 13 | app = QtWidgets.QApplication(sys.argv) |
---|
[d3ca363] | 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''' |
---|
[53c771e] | 29 | self.assertIsInstance(self.widget, QtWidgets.QDialog) |
---|
[d3ca363] | 30 | self.assertEqual(self.widget.windowTitle(), "Set Graph Range") |
---|
[53c771e] | 31 | self.assertIsInstance(self.widget.txtXmin, QtWidgets.QLineEdit) |
---|
[d3ca363] | 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() |
---|