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
RevLine 
[363fbfa]1import sys
2import unittest
[53c771e]3from PyQt5 import QtGui, QtWidgets
4from PyQt5.QtTest import QTest
5from PyQt5.QtCore import Qt
[363fbfa]6
[53c771e]7import path_prepare
[e90988c]8from unittest.mock import MagicMock
[363fbfa]9
[83eb5208]10from sas.qtgui.Calculators.KiessigPanel import KiessigPanel
[363fbfa]11
[53c771e]12if not QtWidgets.QApplication.instance():
13    app = QtWidgets.QApplication(sys.argv)
[363fbfa]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"""
[53c771e]29        self.assertIsInstance(self.widget, QtWidgets.QWidget)
[363fbfa]30        self.assertEqual(self.widget.windowTitle(), "Kiessig Thickness Calculator")
[53c771e]31        self.assertEqual(self.widget.sizePolicy().Policy(), QtWidgets.QSizePolicy.Fixed)
[363fbfa]32
33    def testHelp(self):
34        """ Assure help file is shown """
[e90988c]35        self.widget.manager = QtWidgets.QWidget()
36        self.widget.manager.showHelp = MagicMock()
[040529d]37        self.widget.onHelp()
[e90988c]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])
[363fbfa]41
42    def testComplexEntryNumbers(self):
43        """ User entered compound calculations and subsequent reset"""
44
[040529d]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"""
[363fbfa]66
[040529d]67        self.widget.deltaq_in.clear()
68        self.widget.deltaq_in.insert('2.0')
69        #
[363fbfa]70        # Push Compute with the left mouse button
71        computeButton = self.widget.computeButton
72        QTest.mouseClick(computeButton, Qt.LeftButton)
[040529d]73        self.assertEqual(self.widget.lengthscale_out.text(), '3.142')
[363fbfa]74
75    def testComplexEntryLetters(self):
76        """ User entered compound calculations and subsequent reset"""
[3e314e6]77        self.widget.deltaq_in.clear()
[363fbfa]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)
[3e314e6]83        self.assertEqual(self.widget.deltaq_in.text(), '')
[363fbfa]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.