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

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 62c6dc0 was 3e314e6, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 6 years ago

Minor fixes to the Kiessig calculator. SASVIEW-1161

  • Property mode set to 100644
File size: 3.1 KB
Line 
1import sys
2import unittest
3from PyQt5 import QtGui, QtWidgets
4from PyQt5.QtTest import QTest
5from PyQt5.QtCore import Qt
6
7import path_prepare
8from unittest.mock import MagicMock
9
10from sas.qtgui.Calculators.KiessigPanel import KiessigPanel
11
12if not QtWidgets.QApplication.instance():
13    app = QtWidgets.QApplication(sys.argv)
14
15
16class KiessigCalculatorTest(unittest.TestCase):
17    """Test the KiessigCalculator"""
18    def setUp(self):
19        """Create the KiessigCalculator"""
20        self.widget = KiessigPanel(None)
21
22    def tearDown(self):
23        """Destroy the KiessigCalculator"""
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.QWidget)
30        self.assertEqual(self.widget.windowTitle(), "Kiessig Thickness Calculator")
31        self.assertEqual(self.widget.sizePolicy().Policy(), QtWidgets.QSizePolicy.Fixed)
32
33    def testHelp(self):
34        """ Assure help file is shown """
35        self.widget.manager = QtWidgets.QWidget()
36        self.widget.manager.showHelp = MagicMock()
37        self.widget.onHelp()
38        self.assertTrue(self.widget.manager.showHelp.called_once())
39        args = self.widget.manager.showHelp.call_args
40        self.assertIn('kiessig_calculator_help.html', args[0][0])
41
42    def testComplexEntryNumbers(self):
43        """ User entered compound calculations and subsequent reset"""
44
45        self.widget.deltaq_in.clear()
46        self.widget.deltaq_in.insert('0.05')
47        #
48        # Push Compute with the left mouse button
49        computeButton = self.widget.computeButton
50        QTest.mouseClick(computeButton, Qt.LeftButton)
51        self.assertEqual(self.widget.lengthscale_out.text(), '125.664')
52
53    def testComplexEntryNumbers2(self):
54        """ User entered compound calculations and subsequent reset"""
55
56        self.widget.deltaq_in.clear()
57        self.widget.deltaq_in.insert('1.0')
58        #
59        # Push Compute with the left mouse button
60        computeButton = self.widget.computeButton
61        QTest.mouseClick(computeButton, Qt.LeftButton)
62        self.assertEqual(self.widget.lengthscale_out.text(), '6.283')
63
64    def testComplexEntryNumbers3(self):
65        """ User entered compound calculations and subsequent reset"""
66
67        self.widget.deltaq_in.clear()
68        self.widget.deltaq_in.insert('2.0')
69        #
70        # Push Compute with the left mouse button
71        computeButton = self.widget.computeButton
72        QTest.mouseClick(computeButton, Qt.LeftButton)
73        self.assertEqual(self.widget.lengthscale_out.text(), '3.142')
74
75    def testComplexEntryLetters(self):
76        """ User entered compound calculations and subsequent reset"""
77        self.widget.deltaq_in.clear()
78        self.widget.deltaq_in.insert("xyz")
79
80        # Push Compute with the left mouse button
81        computeButton = self.widget.computeButton
82        QTest.mouseClick(computeButton, Qt.LeftButton)
83        self.assertEqual(self.widget.deltaq_in.text(), '')
84        self.assertEqual(self.widget.lengthscale_out.text(), '')
85
86if __name__ == "__main__":
87    unittest.main()
Note: See TracBrowser for help on using the repository browser.