[3b3b40b] | 1 | import sys |
---|
| 2 | import unittest |
---|
| 3 | import logging |
---|
| 4 | |
---|
| 5 | from PyQt5.QtGui import * |
---|
| 6 | from PyQt5.QtCore import * |
---|
| 7 | from PyQt5.QtWidgets import * |
---|
| 8 | |
---|
| 9 | # set up import paths |
---|
| 10 | import sas.qtgui.path_prepare |
---|
| 11 | |
---|
| 12 | from UnitTesting.TestUtils import QtSignalSpy |
---|
| 13 | |
---|
| 14 | # Local |
---|
| 15 | from sas.qtgui.Utilities.PluginDefinition import PluginDefinition |
---|
| 16 | from sas.qtgui.Utilities.PythonSyntax import PythonHighlighter |
---|
| 17 | |
---|
| 18 | #if not QApplication.instance(): |
---|
| 19 | # app = QApplication(sys.argv) |
---|
| 20 | app = QApplication(sys.argv) |
---|
| 21 | |
---|
| 22 | class PluginDefinitionTest(unittest.TestCase): |
---|
| 23 | def setUp(self): |
---|
| 24 | """ |
---|
| 25 | Prepare the editor |
---|
| 26 | """ |
---|
| 27 | self.widget = PluginDefinition(None) |
---|
| 28 | |
---|
| 29 | def tearDown(self): |
---|
| 30 | """Destroy the DataOperationUtility""" |
---|
| 31 | self.widget.close() |
---|
| 32 | self.widget = None |
---|
| 33 | |
---|
| 34 | def testDefaults(self): |
---|
| 35 | """Test the GUI in its default state""" |
---|
| 36 | self.assertIsInstance(self.widget.highlight, PythonHighlighter) |
---|
| 37 | self.assertIsInstance(self.widget.parameter_dict, dict) |
---|
| 38 | self.assertIsInstance(self.widget.pd_parameter_dict, dict) |
---|
| 39 | |
---|
| 40 | self.assertEqual(len(self.widget.model), 6) |
---|
| 41 | self.assertIn("filename", self.widget.model.keys()) |
---|
| 42 | self.assertIn("overwrite", self.widget.model.keys()) |
---|
| 43 | self.assertIn("description", self.widget.model.keys()) |
---|
| 44 | self.assertIn("parameters", self.widget.model.keys()) |
---|
| 45 | self.assertIn("pd_parameters", self.widget.model.keys()) |
---|
| 46 | self.assertIn("text", self.widget.model.keys()) |
---|
| 47 | |
---|
| 48 | def testOnOverwrite(self): |
---|
| 49 | """See what happens when the overwrite checkbox is selected""" |
---|
| 50 | spy_signal = QtSignalSpy(self.widget, self.widget.modelModified) |
---|
| 51 | |
---|
| 52 | # check the default |
---|
| 53 | self.assertFalse(self.widget.chkOverwrite.isChecked()) |
---|
| 54 | |
---|
| 55 | # Change the state |
---|
| 56 | self.widget.chkOverwrite.setChecked(True) |
---|
| 57 | |
---|
| 58 | # Check the signal |
---|
| 59 | self.assertEqual(spy_signal.count(), 1) |
---|
| 60 | |
---|
| 61 | # model dict updated |
---|
| 62 | self.assertTrue(self.widget.model['overwrite']) |
---|
| 63 | |
---|
| 64 | def testOnPluginNameChanged(self): |
---|
| 65 | """See what happens when the name of the plugin changes""" |
---|
| 66 | spy_signal = QtSignalSpy(self.widget, self.widget.modelModified) |
---|
| 67 | |
---|
| 68 | # Change the name |
---|
| 69 | new_text = "Duck season" |
---|
| 70 | self.widget.txtName.setText(new_text) |
---|
| 71 | self.widget.txtName.editingFinished.emit() |
---|
| 72 | |
---|
| 73 | # Check the signal |
---|
| 74 | self.assertEqual(spy_signal.count(), 1) |
---|
| 75 | |
---|
| 76 | # model dict updated |
---|
| 77 | self.assertTrue(self.widget.model['filename'] == new_text) |
---|
| 78 | |
---|
| 79 | def testOnDescriptionChanged(self): |
---|
| 80 | """See what happens when the description of the plugin changes""" |
---|
| 81 | spy_signal = QtSignalSpy(self.widget, self.widget.modelModified) |
---|
| 82 | |
---|
| 83 | # Change the name |
---|
| 84 | new_text = "Rabbit season" |
---|
| 85 | self.widget.txtDescription.setText(new_text) |
---|
| 86 | self.widget.txtDescription.editingFinished.emit() |
---|
| 87 | |
---|
| 88 | # Check the signal |
---|
| 89 | self.assertEqual(spy_signal.count(), 1) |
---|
| 90 | |
---|
| 91 | # model dict updated |
---|
| 92 | self.assertTrue(self.widget.model['description'] == new_text) |
---|
| 93 | |
---|
| 94 | def testOnParamsChanged(self): |
---|
| 95 | """See what happens when parameters change""" |
---|
| 96 | spy_signal = QtSignalSpy(self.widget, self.widget.modelModified) |
---|
| 97 | |
---|
| 98 | # number of rows. default=1 |
---|
| 99 | self.assertEqual(self.widget.tblParams.rowCount(), 1) |
---|
| 100 | |
---|
| 101 | # number of columns. default=2 |
---|
| 102 | self.assertEqual(self.widget.tblParams.columnCount(), 2) |
---|
| 103 | |
---|
| 104 | # Change the param |
---|
| 105 | new_param = "shoot" |
---|
| 106 | self.widget.tblParams.setItem(0,0,QTableWidgetItem(new_param)) |
---|
| 107 | #self.widget.tblParams.editingFinished.emit() |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | # Check the signal |
---|
| 111 | self.assertEqual(spy_signal.count(), 1) |
---|
| 112 | |
---|
| 113 | # model dict updated |
---|
| 114 | self.assertEqual(self.widget.model['parameters'], {0: (new_param, None)}) |
---|
| 115 | |
---|
| 116 | # Change the value |
---|
| 117 | new_value = "BOOM" |
---|
| 118 | self.widget.tblParams.setItem(0,1,QTableWidgetItem(new_value)) |
---|
| 119 | |
---|
| 120 | # Check the signal |
---|
| 121 | self.assertEqual(spy_signal.count(), 2) |
---|
| 122 | |
---|
| 123 | # model dict updated |
---|
| 124 | self.assertEqual(self.widget.model['parameters'], {0: (new_param, new_value)}) |
---|
| 125 | |
---|
| 126 | # See that the number of rows increased |
---|
| 127 | self.assertEqual(self.widget.tblParams.rowCount(), 2) |
---|
| 128 | |
---|
| 129 | def testOnPDParamsChanged(self): |
---|
| 130 | """See what happens when pd parameters change""" |
---|
| 131 | spy_signal = QtSignalSpy(self.widget, self.widget.modelModified) |
---|
| 132 | |
---|
| 133 | # number of rows. default=1 |
---|
| 134 | self.assertEqual(self.widget.tblParamsPD.rowCount(), 1) |
---|
| 135 | |
---|
| 136 | # number of columns. default=2 |
---|
| 137 | self.assertEqual(self.widget.tblParamsPD.columnCount(), 2) |
---|
| 138 | |
---|
| 139 | # Change the param |
---|
| 140 | new_param = "shoot" |
---|
| 141 | self.widget.tblParamsPD.setItem(0,0,QTableWidgetItem(new_param)) |
---|
| 142 | |
---|
| 143 | # Check the signal |
---|
| 144 | self.assertEqual(spy_signal.count(), 1) |
---|
| 145 | |
---|
| 146 | # model dict updated |
---|
| 147 | self.assertEqual(self.widget.model['pd_parameters'], {0: (new_param, None)}) |
---|
| 148 | |
---|
| 149 | # Change the value |
---|
| 150 | new_value = "BOOM" |
---|
| 151 | self.widget.tblParamsPD.setItem(0,1,QTableWidgetItem(new_value)) |
---|
| 152 | |
---|
| 153 | # Check the signal |
---|
| 154 | self.assertEqual(spy_signal.count(), 2) |
---|
| 155 | |
---|
| 156 | # model dict updated |
---|
| 157 | self.assertTrue(self.widget.model['pd_parameters'] == {0: (new_param, new_value)}) |
---|
| 158 | |
---|
| 159 | # See that the number of rows increased |
---|
| 160 | self.assertEqual(self.widget.tblParamsPD.rowCount(), 2) |
---|
| 161 | |
---|
| 162 | def testOnFunctionChanged(self): |
---|
| 163 | """See what happens when the model text changes""" |
---|
| 164 | spy_signal = QtSignalSpy(self.widget, self.widget.modelModified) |
---|
| 165 | |
---|
| 166 | # Change the text |
---|
| 167 | new_model = "1\n2\n" |
---|
| 168 | self.widget.txtFunction.setPlainText(new_model) |
---|
| 169 | |
---|
| 170 | # Check the signal |
---|
| 171 | self.assertEqual(spy_signal.count(), 1) |
---|
| 172 | |
---|
| 173 | # model dict updated |
---|
| 174 | self.assertEqual(self.widget.model['text'], new_model.rstrip()) |
---|
| 175 | |
---|