[363fbfa] | 1 | import sys |
---|
| 2 | import unittest |
---|
[53c771e] | 3 | from PyQt5 import QtGui, QtWidgets |
---|
| 4 | from PyQt5.QtTest import QTest |
---|
| 5 | from PyQt5.QtCore import Qt |
---|
[363fbfa] | 6 | |
---|
[53c771e] | 7 | import path_prepare |
---|
[e90988c] | 8 | from unittest.mock import MagicMock |
---|
[363fbfa] | 9 | |
---|
[83eb5208] | 10 | from sas.qtgui.Calculators.KiessigPanel import KiessigPanel |
---|
[363fbfa] | 11 | |
---|
[53c771e] | 12 | if not QtWidgets.QApplication.instance(): |
---|
| 13 | app = QtWidgets.QApplication(sys.argv) |
---|
[363fbfa] | 14 | |
---|
| 15 | |
---|
| 16 | class 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 | |
---|
| 86 | if __name__ == "__main__": |
---|
| 87 | unittest.main() |
---|