source: sasview/src/sas/qtgui/Calculators/UnitTesting/KiessigCalculatorTest.py @ 4a9786d8

Last change on this file since 4a9786d8 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: 2.7 KB
Line 
1import sys
2import unittest
3from PyQt4 import QtGui
4from PyQt4.QtTest import QTest
5from PyQt4.QtCore import Qt
6
7# TEMP
8import sas.qtgui.path_prepare
9
10
11from sas.qtgui.Calculators.KiessigPanel import KiessigPanel
12
13if not QtGui.QApplication.instance():
14    app = QtGui.QApplication(sys.argv)
15
16
17class KiessigCalculatorTest(unittest.TestCase):
18    """Test the KiessigCalculator"""
19    def setUp(self):
20        """Create the KiessigCalculator"""
21        self.widget = KiessigPanel(None)
22
23    def tearDown(self):
24        """Destroy the KiessigCalculator"""
25        self.widget.close()
26        self.widget = None
27
28    def testDefaults(self):
29        """Test the GUI in its default state"""
30        self.assertIsInstance(self.widget, QtGui.QWidget)
31        self.assertEqual(self.widget.windowTitle(), "Kiessig Thickness Calculator")
32        self.assertEqual(self.widget.sizePolicy().Policy(), QtGui.QSizePolicy.Fixed)
33
34    def testHelp(self):
35        """ Assure help file is shown """
36
37        # this should not rise
38        self.widget.onHelp()
39
40    def testComplexEntryNumbers(self):
41        """ User entered compound calculations and subsequent reset"""
42
43        self.widget.deltaq_in.clear()
44        self.widget.deltaq_in.insert('0.05')
45        #
46        # Push Compute with the left mouse button
47        computeButton = self.widget.computeButton
48        QTest.mouseClick(computeButton, Qt.LeftButton)
49        self.assertEqual(self.widget.lengthscale_out.text(), '125.664')
50
51    def testComplexEntryNumbers2(self):
52        """ User entered compound calculations and subsequent reset"""
53
54        self.widget.deltaq_in.clear()
55        self.widget.deltaq_in.insert('1.0')
56        #
57        # Push Compute with the left mouse button
58        computeButton = self.widget.computeButton
59        QTest.mouseClick(computeButton, Qt.LeftButton)
60        self.assertEqual(self.widget.lengthscale_out.text(), '6.283')
61
62    def testComplexEntryNumbers3(self):
63        """ User entered compound calculations and subsequent reset"""
64
65        self.widget.deltaq_in.clear()
66        self.widget.deltaq_in.insert('2.0')
67        #
68        # Push Compute with the left mouse button
69        computeButton = self.widget.computeButton
70        QTest.mouseClick(computeButton, Qt.LeftButton)
71        self.assertEqual(self.widget.lengthscale_out.text(), '3.142')
72
73    def testComplexEntryLetters(self):
74        """ User entered compound calculations and subsequent reset"""
75
76        self.widget.deltaq_in.insert("xyz")
77
78        # Push Compute with the left mouse button
79        computeButton = self.widget.computeButton
80        QTest.mouseClick(computeButton, Qt.LeftButton)
81        self.assertEqual(self.widget.lengthscale_out.text(), '')
82
83if __name__ == "__main__":
84    unittest.main()
Note: See TracBrowser for help on using the repository browser.