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

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 304d082 was 464cd07, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Use singleton QApplication in unit tests to avoid issues on Ubuntu. SASVIEW-485

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