1 | import sys |
---|
2 | import unittest |
---|
3 | from PyQt4 import QtGui |
---|
4 | from PyQt4.QtTest import QTest |
---|
5 | from PyQt4.QtCore import Qt |
---|
6 | |
---|
7 | # TEMP |
---|
8 | import path_prepare |
---|
9 | |
---|
10 | |
---|
11 | from KiessigPanel import KiessigPanel |
---|
12 | |
---|
13 | app = QtGui.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, QtGui.QWidget) |
---|
30 | self.assertEqual(self.widget.windowTitle(), "Kiessig Thickness Calculator") |
---|
31 | self.assertEqual(self.widget.sizePolicy().Policy(), QtGui.QSizePolicy.Fixed) |
---|
32 | |
---|
33 | def testHelp(self): |
---|
34 | """ Assure help file is shown """ |
---|
35 | |
---|
36 | # this should not rise |
---|
37 | self.widget.onHelp() |
---|
38 | |
---|
39 | def testComplexEntryNumbers(self): |
---|
40 | """ User entered compound calculations and subsequent reset""" |
---|
41 | |
---|
42 | self.widget.deltaq_in.clear() |
---|
43 | self.widget.deltaq_in.insert('0.05') |
---|
44 | # |
---|
45 | # Push Compute with the left mouse button |
---|
46 | computeButton = self.widget.computeButton |
---|
47 | QTest.mouseClick(computeButton, Qt.LeftButton) |
---|
48 | self.assertEqual(self.widget.lengthscale_out.text(), '125.664') |
---|
49 | |
---|
50 | def testComplexEntryNumbers2(self): |
---|
51 | """ User entered compound calculations and subsequent reset""" |
---|
52 | |
---|
53 | self.widget.deltaq_in.clear() |
---|
54 | self.widget.deltaq_in.insert('1.0') |
---|
55 | # |
---|
56 | # Push Compute with the left mouse button |
---|
57 | computeButton = self.widget.computeButton |
---|
58 | QTest.mouseClick(computeButton, Qt.LeftButton) |
---|
59 | self.assertEqual(self.widget.lengthscale_out.text(), '6.283') |
---|
60 | |
---|
61 | def testComplexEntryNumbers3(self): |
---|
62 | """ User entered compound calculations and subsequent reset""" |
---|
63 | |
---|
64 | self.widget.deltaq_in.clear() |
---|
65 | self.widget.deltaq_in.insert('2.0') |
---|
66 | # |
---|
67 | # Push Compute with the left mouse button |
---|
68 | computeButton = self.widget.computeButton |
---|
69 | QTest.mouseClick(computeButton, Qt.LeftButton) |
---|
70 | self.assertEqual(self.widget.lengthscale_out.text(), '3.142') |
---|
71 | |
---|
72 | def testComplexEntryLetters(self): |
---|
73 | """ User entered compound calculations and subsequent reset""" |
---|
74 | |
---|
75 | self.widget.deltaq_in.insert("xyz") |
---|
76 | |
---|
77 | # Push Compute with the left mouse button |
---|
78 | computeButton = self.widget.computeButton |
---|
79 | QTest.mouseClick(computeButton, Qt.LeftButton) |
---|
80 | self.assertEqual(self.widget.lengthscale_out.text(), '') |
---|
81 | |
---|
82 | if __name__ == "__main__": |
---|
83 | unittest.main() |
---|