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

Last change on this file since a7067ef2 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
RevLine 
[363fbfa]1import sys
2import unittest
3from PyQt4 import QtGui
4from PyQt4.QtTest import QTest
5from PyQt4.QtCore import Qt
6
7# TEMP
[83eb5208]8import sas.qtgui.path_prepare
[363fbfa]9
10
[83eb5208]11from sas.qtgui.Calculators.KiessigPanel import KiessigPanel
[363fbfa]12
[464cd07]13if not QtGui.QApplication.instance():
14    app = QtGui.QApplication(sys.argv)
[363fbfa]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
[040529d]38        self.widget.onHelp()
[363fbfa]39
40    def testComplexEntryNumbers(self):
41        """ User entered compound calculations and subsequent reset"""
42
[040529d]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"""
[363fbfa]64
[040529d]65        self.widget.deltaq_in.clear()
66        self.widget.deltaq_in.insert('2.0')
67        #
[363fbfa]68        # Push Compute with the left mouse button
69        computeButton = self.widget.computeButton
70        QTest.mouseClick(computeButton, Qt.LeftButton)
[040529d]71        self.assertEqual(self.widget.lengthscale_out.text(), '3.142')
[363fbfa]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.