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 | # TEMP |
---|
8 | #import sas.qtgui.path_prepare |
---|
9 | import path_prepare |
---|
10 | |
---|
11 | |
---|
12 | from sas.qtgui.Calculators.KiessigPanel import KiessigPanel |
---|
13 | |
---|
14 | if not QtWidgets.QApplication.instance(): |
---|
15 | app = QtWidgets.QApplication(sys.argv) |
---|
16 | |
---|
17 | |
---|
18 | class KiessigCalculatorTest(unittest.TestCase): |
---|
19 | """Test the KiessigCalculator""" |
---|
20 | def setUp(self): |
---|
21 | """Create the KiessigCalculator""" |
---|
22 | self.widget = KiessigPanel(None) |
---|
23 | |
---|
24 | def tearDown(self): |
---|
25 | """Destroy the KiessigCalculator""" |
---|
26 | self.widget.close() |
---|
27 | self.widget = None |
---|
28 | |
---|
29 | def testDefaults(self): |
---|
30 | """Test the GUI in its default state""" |
---|
31 | self.assertIsInstance(self.widget, QtWidgets.QWidget) |
---|
32 | self.assertEqual(self.widget.windowTitle(), "Kiessig Thickness Calculator") |
---|
33 | self.assertEqual(self.widget.sizePolicy().Policy(), QtWidgets.QSizePolicy.Fixed) |
---|
34 | |
---|
35 | def testHelp(self): |
---|
36 | """ Assure help file is shown """ |
---|
37 | |
---|
38 | # this should not rise |
---|
39 | self.widget.onHelp() |
---|
40 | |
---|
41 | def testComplexEntryNumbers(self): |
---|
42 | """ User entered compound calculations and subsequent reset""" |
---|
43 | |
---|
44 | self.widget.deltaq_in.clear() |
---|
45 | self.widget.deltaq_in.insert('0.05') |
---|
46 | # |
---|
47 | # Push Compute with the left mouse button |
---|
48 | computeButton = self.widget.computeButton |
---|
49 | QTest.mouseClick(computeButton, Qt.LeftButton) |
---|
50 | self.assertEqual(self.widget.lengthscale_out.text(), '125.664') |
---|
51 | |
---|
52 | def testComplexEntryNumbers2(self): |
---|
53 | """ User entered compound calculations and subsequent reset""" |
---|
54 | |
---|
55 | self.widget.deltaq_in.clear() |
---|
56 | self.widget.deltaq_in.insert('1.0') |
---|
57 | # |
---|
58 | # Push Compute with the left mouse button |
---|
59 | computeButton = self.widget.computeButton |
---|
60 | QTest.mouseClick(computeButton, Qt.LeftButton) |
---|
61 | self.assertEqual(self.widget.lengthscale_out.text(), '6.283') |
---|
62 | |
---|
63 | def testComplexEntryNumbers3(self): |
---|
64 | """ User entered compound calculations and subsequent reset""" |
---|
65 | |
---|
66 | self.widget.deltaq_in.clear() |
---|
67 | self.widget.deltaq_in.insert('2.0') |
---|
68 | # |
---|
69 | # Push Compute with the left mouse button |
---|
70 | computeButton = self.widget.computeButton |
---|
71 | QTest.mouseClick(computeButton, Qt.LeftButton) |
---|
72 | self.assertEqual(self.widget.lengthscale_out.text(), '3.142') |
---|
73 | |
---|
74 | def testComplexEntryLetters(self): |
---|
75 | """ User entered compound calculations and subsequent reset""" |
---|
76 | |
---|
77 | self.widget.deltaq_in.insert("xyz") |
---|
78 | |
---|
79 | # Push Compute with the left mouse button |
---|
80 | computeButton = self.widget.computeButton |
---|
81 | QTest.mouseClick(computeButton, Qt.LeftButton) |
---|
82 | self.assertEqual(self.widget.lengthscale_out.text(), '') |
---|
83 | |
---|
84 | if __name__ == "__main__": |
---|
85 | unittest.main() |
---|