source: sasview/src/sas/qtgui/Plotting/UnitTesting/SetGraphRangeTest.py @ 5dba493

Last change on this file since 5dba493 was 53c771e, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Converted unit tests

  • Property mode set to 100644
File size: 1.9 KB
Line 
1import sys
2import unittest
3
4from PyQt5 import QtGui, QtWidgets
5
6# set up import paths
7import sas.qtgui.path_prepare
8
9# Local
10from sas.qtgui.Plotting.SetGraphRange import SetGraphRange
11
12if not QtWidgets.QApplication.instance():
13    app = QtWidgets.QApplication(sys.argv)
14
15class 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, QtWidgets.QDialog)
30        self.assertEqual(self.widget.windowTitle(), "Set Graph Range")
31        self.assertIsInstance(self.widget.txtXmin, QtWidgets.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
56if __name__ == "__main__":
57    unittest.main()
Note: See TracBrowser for help on using the repository browser.