[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 | |
---|
| 7 | # TEMP |
---|
[53c771e] | 8 | #import sas.qtgui.path_prepare |
---|
| 9 | import path_prepare |
---|
[363fbfa] | 10 | |
---|
| 11 | |
---|
[83eb5208] | 12 | from sas.qtgui.Calculators.KiessigPanel import KiessigPanel |
---|
[363fbfa] | 13 | |
---|
[53c771e] | 14 | if not QtWidgets.QApplication.instance(): |
---|
| 15 | app = QtWidgets.QApplication(sys.argv) |
---|
[363fbfa] | 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""" |
---|
[53c771e] | 31 | self.assertIsInstance(self.widget, QtWidgets.QWidget) |
---|
[363fbfa] | 32 | self.assertEqual(self.widget.windowTitle(), "Kiessig Thickness Calculator") |
---|
[53c771e] | 33 | self.assertEqual(self.widget.sizePolicy().Policy(), QtWidgets.QSizePolicy.Fixed) |
---|
[363fbfa] | 34 | |
---|
| 35 | def testHelp(self): |
---|
| 36 | """ Assure help file is shown """ |
---|
| 37 | |
---|
| 38 | # this should not rise |
---|
[040529d] | 39 | self.widget.onHelp() |
---|
[363fbfa] | 40 | |
---|
| 41 | def testComplexEntryNumbers(self): |
---|
| 42 | """ User entered compound calculations and subsequent reset""" |
---|
| 43 | |
---|
[040529d] | 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""" |
---|
[363fbfa] | 65 | |
---|
[040529d] | 66 | self.widget.deltaq_in.clear() |
---|
| 67 | self.widget.deltaq_in.insert('2.0') |
---|
| 68 | # |
---|
[363fbfa] | 69 | # Push Compute with the left mouse button |
---|
| 70 | computeButton = self.widget.computeButton |
---|
| 71 | QTest.mouseClick(computeButton, Qt.LeftButton) |
---|
[040529d] | 72 | self.assertEqual(self.widget.lengthscale_out.text(), '3.142') |
---|
[363fbfa] | 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() |
---|