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

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

Converted unit tests

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[d3ca363]1import sys
2import unittest
3
[53c771e]4from PyQt5 import QtGui, QtWidgets
[d3ca363]5
6# set up import paths
[83eb5208]7import sas.qtgui.path_prepare
[d3ca363]8
9# Local
[83eb5208]10from sas.qtgui.Plotting.SetGraphRange import SetGraphRange
[d3ca363]11
[53c771e]12if not QtWidgets.QApplication.instance():
13    app = QtWidgets.QApplication(sys.argv)
[d3ca363]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'''
[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
56if __name__ == "__main__":
57    unittest.main()
Note: See TracBrowser for help on using the repository browser.