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