source: sasview/src/sas/qtgui/Utilities/UnitTesting/PluginDefinitionTest.py @ 58478a5

ESS_GUIESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_openclESS_GUI_sync_sascalc
Last change on this file since 58478a5 was 80468f6, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Fixed a few unit test files

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