1 | import unittest |
---|
2 | import sys |
---|
3 | from PyQt5 import QtGui |
---|
4 | from PyQt5 import QtWidgets |
---|
5 | |
---|
6 | """ |
---|
7 | Unit tests for the QT GUI |
---|
8 | ========================= |
---|
9 | |
---|
10 | In order to run the tests, first install SasView and sasmodels to site-packages |
---|
11 | by running ``python setup.py install`` in both repositories. |
---|
12 | |
---|
13 | The tests can be run with ``python GUITests.py``, or |
---|
14 | ``python GUITests.py suiteName1 suiteName2 ...`` for a subset of tests. |
---|
15 | |
---|
16 | To get more verbose console output (recommended), use ``python GUITests.py -v`` |
---|
17 | """ |
---|
18 | |
---|
19 | # Llist of all suite names. Every time a new suite is added, its name should |
---|
20 | # also be added here |
---|
21 | ALL_SUITES = [ |
---|
22 | 'calculatorsSuite', |
---|
23 | 'mainSuite', |
---|
24 | 'fittingSuite', |
---|
25 | 'plottingSuite', |
---|
26 | 'utilitiesSuite', |
---|
27 | 'perspectivesSuite', |
---|
28 | ] |
---|
29 | |
---|
30 | # Prepare the general QApplication instance |
---|
31 | app = QtWidgets.QApplication(sys.argv) |
---|
32 | |
---|
33 | # Main Window |
---|
34 | from MainWindow.UnitTesting import AboutBoxTest |
---|
35 | from MainWindow.UnitTesting import DataExplorerTest |
---|
36 | from MainWindow.UnitTesting import WelcomePanelTest |
---|
37 | from MainWindow.UnitTesting import DroppableDataLoadWidgetTest |
---|
38 | from MainWindow.UnitTesting import GuiManagerTest |
---|
39 | from MainWindow.UnitTesting import MainWindowTest |
---|
40 | |
---|
41 | ## Plotting |
---|
42 | from Plotting.UnitTesting import AddTextTest |
---|
43 | from Plotting.UnitTesting import PlotHelperTest |
---|
44 | from Plotting.UnitTesting import WindowTitleTest |
---|
45 | from Plotting.UnitTesting import ScalePropertiesTest |
---|
46 | from Plotting.UnitTesting import SetGraphRangeTest |
---|
47 | from Plotting.UnitTesting import LinearFitTest |
---|
48 | from Plotting.UnitTesting import PlotPropertiesTest |
---|
49 | from Plotting.UnitTesting import PlotUtilitiesTest |
---|
50 | from Plotting.UnitTesting import ColorMapTest |
---|
51 | from Plotting.UnitTesting import BoxSumTest |
---|
52 | from Plotting.UnitTesting import SlicerModelTest |
---|
53 | from Plotting.UnitTesting import SlicerParametersTest |
---|
54 | from Plotting.UnitTesting import PlotterBaseTest |
---|
55 | from Plotting.UnitTesting import PlotterTest |
---|
56 | from Plotting.UnitTesting import Plotter2DTest |
---|
57 | |
---|
58 | # Calculators |
---|
59 | from Calculators.UnitTesting import KiessigCalculatorTest |
---|
60 | from Calculators.UnitTesting import DensityCalculatorTest |
---|
61 | from Calculators.UnitTesting import GenericScatteringCalculatorTest |
---|
62 | from Calculators.UnitTesting import SLDCalculatorTest |
---|
63 | from Calculators.UnitTesting import SlitSizeCalculatorTest |
---|
64 | from Calculators.UnitTesting import ResolutionCalculatorPanelTest |
---|
65 | from Calculators.UnitTesting import DataOperationUtilityTest |
---|
66 | |
---|
67 | # Utilities |
---|
68 | from Utilities.UnitTesting import GuiUtilsTest |
---|
69 | from Utilities.UnitTesting import SasviewLoggerTest |
---|
70 | from Utilities.UnitTesting import GridPanelTest |
---|
71 | from Utilities.UnitTesting import ModelEditorTest |
---|
72 | from Utilities.UnitTesting import PluginDefinitionTest |
---|
73 | from Utilities.UnitTesting import TabbedModelEditorTest |
---|
74 | from Utilities.UnitTesting import AddMultEditorTest |
---|
75 | from Utilities.UnitTesting import ReportDialogTest |
---|
76 | |
---|
77 | # Unit Testing |
---|
78 | from UnitTesting import TestUtilsTest |
---|
79 | |
---|
80 | # Perspectives |
---|
81 | # Fitting |
---|
82 | from Perspectives.Fitting.UnitTesting import FittingWidgetTest |
---|
83 | from Perspectives.Fitting.UnitTesting import FittingPerspectiveTest |
---|
84 | from Perspectives.Fitting.UnitTesting import FittingLogicTest |
---|
85 | from Perspectives.Fitting.UnitTesting import FittingUtilitiesTest |
---|
86 | from Perspectives.Fitting.UnitTesting import FitPageTest |
---|
87 | from Perspectives.Fitting.UnitTesting import FittingOptionsTest |
---|
88 | from Perspectives.Fitting.UnitTesting import MultiConstraintTest |
---|
89 | from Perspectives.Fitting.UnitTesting import ComplexConstraintTest |
---|
90 | from Perspectives.Fitting.UnitTesting import ConstraintWidgetTest |
---|
91 | |
---|
92 | # Invariant |
---|
93 | from Perspectives.Invariant.UnitTesting import InvariantPerspectiveTest |
---|
94 | |
---|
95 | # Inversion |
---|
96 | from Perspectives.Inversion.UnitTesting import InversionPerspectiveTest |
---|
97 | |
---|
98 | def plottingSuite(): |
---|
99 | suites = ( |
---|
100 | # Plotting |
---|
101 | unittest.makeSuite(Plotter2DTest.Plotter2DTest, 'test'), |
---|
102 | unittest.makeSuite(PlotHelperTest.PlotHelperTest, 'test'), |
---|
103 | unittest.makeSuite(AddTextTest.AddTextTest, 'test'), |
---|
104 | unittest.makeSuite(WindowTitleTest.WindowTitleTest, 'test'), |
---|
105 | unittest.makeSuite(ScalePropertiesTest.ScalePropertiesTest, 'test'), |
---|
106 | unittest.makeSuite(SetGraphRangeTest.SetGraphRangeTest, 'test'), |
---|
107 | unittest.makeSuite(LinearFitTest.LinearFitTest, 'test'), |
---|
108 | unittest.makeSuite(PlotPropertiesTest.PlotPropertiesTest, 'test'), |
---|
109 | unittest.makeSuite(PlotUtilitiesTest.PlotUtilitiesTest, 'test'), |
---|
110 | unittest.makeSuite(ColorMapTest.ColorMapTest, 'test'), |
---|
111 | unittest.makeSuite(BoxSumTest.BoxSumTest, 'test'), |
---|
112 | unittest.makeSuite(SlicerModelTest.SlicerModelTest, 'test'), |
---|
113 | unittest.makeSuite(SlicerParametersTest.SlicerParametersTest, 'test'), |
---|
114 | unittest.makeSuite(PlotterBaseTest.PlotterBaseTest, 'test'), |
---|
115 | unittest.makeSuite(PlotterTest.PlotterTest, 'test'), |
---|
116 | ) |
---|
117 | return unittest.TestSuite(suites) |
---|
118 | |
---|
119 | def mainSuite(): |
---|
120 | suites = ( |
---|
121 | # Main window |
---|
122 | unittest.makeSuite(DataExplorerTest.DataExplorerTest, 'test'), |
---|
123 | unittest.makeSuite(DroppableDataLoadWidgetTest.DroppableDataLoadWidgetTest, 'test'), |
---|
124 | unittest.makeSuite(MainWindowTest.MainWindowTest, 'test'), |
---|
125 | unittest.makeSuite(GuiManagerTest.GuiManagerTest, 'test'), |
---|
126 | unittest.makeSuite(AboutBoxTest.AboutBoxTest, 'test'), |
---|
127 | unittest.makeSuite(WelcomePanelTest.WelcomePanelTest, 'test'), |
---|
128 | ) |
---|
129 | return unittest.TestSuite(suites) |
---|
130 | |
---|
131 | def utilitiesSuite(): |
---|
132 | suites = ( |
---|
133 | ## Utilities |
---|
134 | unittest.makeSuite(TestUtilsTest.TestUtilsTest, 'test'), |
---|
135 | unittest.makeSuite(SasviewLoggerTest.SasviewLoggerTest, 'test'), |
---|
136 | unittest.makeSuite(GuiUtilsTest.GuiUtilsTest, 'test'), |
---|
137 | unittest.makeSuite(GuiUtilsTest.DoubleValidatorTest, 'test'), |
---|
138 | unittest.makeSuite(GuiUtilsTest.HashableStandardItemTest, 'test'), |
---|
139 | unittest.makeSuite(GridPanelTest.BatchOutputPanelTest, 'test'), |
---|
140 | unittest.makeSuite(ModelEditorTest.ModelEditorTest, 'test'), |
---|
141 | unittest.makeSuite(PluginDefinitionTest.PluginDefinitionTest, 'test'), |
---|
142 | unittest.makeSuite(TabbedModelEditorTest.TabbedModelEditorTest,'test'), |
---|
143 | unittest.makeSuite(AddMultEditorTest.AddMultEditorTest, 'test'), |
---|
144 | unittest.makeSuite(ReportDialogTest.ReportDialogTest, 'test'), |
---|
145 | ) |
---|
146 | return unittest.TestSuite(suites) |
---|
147 | |
---|
148 | def calculatorsSuite(): |
---|
149 | suites = ( |
---|
150 | # Calculators |
---|
151 | unittest.makeSuite(KiessigCalculatorTest.KiessigCalculatorTest, 'test'), |
---|
152 | unittest.makeSuite(DensityCalculatorTest.DensityCalculatorTest, 'test'), |
---|
153 | unittest.makeSuite(GenericScatteringCalculatorTest.GenericScatteringCalculatorTest, 'test'), |
---|
154 | unittest.makeSuite(SLDCalculatorTest.SLDCalculatorTest, 'test'), |
---|
155 | unittest.makeSuite(SlitSizeCalculatorTest.SlitSizeCalculatorTest, 'test'), |
---|
156 | unittest.makeSuite(ResolutionCalculatorPanelTest.ResolutionCalculatorPanelTest, 'test'), |
---|
157 | unittest.makeSuite(DataOperationUtilityTest.DataOperationUtilityTest, 'test'), |
---|
158 | ) |
---|
159 | return unittest.TestSuite(suites) |
---|
160 | |
---|
161 | def fittingSuite(): |
---|
162 | suites = ( |
---|
163 | # Perspectives |
---|
164 | # Fitting |
---|
165 | unittest.makeSuite(FittingPerspectiveTest.FittingPerspectiveTest, 'test'), |
---|
166 | unittest.makeSuite(FittingWidgetTest.FittingWidgetTest, 'test'), |
---|
167 | unittest.makeSuite(FittingLogicTest.FittingLogicTest, 'test'), |
---|
168 | unittest.makeSuite(FittingUtilitiesTest.FittingUtilitiesTest, 'test'), |
---|
169 | unittest.makeSuite(FitPageTest.FitPageTest, 'test'), |
---|
170 | unittest.makeSuite(FittingOptionsTest.FittingOptionsTest, 'test'), |
---|
171 | unittest.makeSuite(MultiConstraintTest.MultiConstraintTest, 'test'), |
---|
172 | unittest.makeSuite(ConstraintWidgetTest.ConstraintWidgetTest, 'test'), |
---|
173 | unittest.makeSuite(ComplexConstraintTest.ComplexConstraintTest, 'test'), |
---|
174 | ) |
---|
175 | return unittest.TestSuite(suites) |
---|
176 | |
---|
177 | def perspectivesSuite(): |
---|
178 | suites = ( |
---|
179 | # Invariant |
---|
180 | unittest.makeSuite(InvariantPerspectiveTest.InvariantPerspectiveTest, 'test'), |
---|
181 | # Inversion |
---|
182 | #unittest.makeSuite(InversionPerspectiveTest.InversionTest, 'test'), |
---|
183 | ) |
---|
184 | return unittest.TestSuite(suites) |
---|
185 | |
---|
186 | if __name__ == "__main__": |
---|
187 | |
---|
188 | user_suites = ALL_SUITES |
---|
189 | # Check if user asked for specific suites: |
---|
190 | if len(sys.argv) > 1: |
---|
191 | user_suites = sys.argv[1:] |
---|
192 | errors = {} |
---|
193 | for suite in user_suites: |
---|
194 | # create the suite object from name |
---|
195 | try: |
---|
196 | |
---|
197 | suite_instance = globals()[suite]() |
---|
198 | result=unittest.TextTestResult(sys.stdout,True,True) |
---|
199 | print("\nRunning %d test cases for %s"%(suite_instance.countTestCases(), suite)) |
---|
200 | result.buffer=True |
---|
201 | suite_instance.run(result) |
---|
202 | |
---|
203 | if not result.wasSuccessful(): |
---|
204 | if len(result.errors) or len(result.failures): |
---|
205 | errors[suite] = (result.errors, result.failures) |
---|
206 | if len(result.errors): |
---|
207 | print("\n============ Errors disovered ===================") |
---|
208 | if len(result.failures): |
---|
209 | print("\n============ Failures disovered =================") |
---|
210 | else: |
---|
211 | print("\nAll tests successful") |
---|
212 | |
---|
213 | except KeyError: |
---|
214 | print("Failure : %s "%str(ex)) |
---|
215 | print("ERROR: Incorrect suite name: %s " % suite) |
---|
216 | pass |
---|
217 | |
---|
218 | if len(errors.keys())>0: |
---|
219 | for suite, errors in errors.items(): |
---|
220 | for r in errors[0]: |
---|
221 | print("\nSuite: %s had following errors:\n %s : %s"%(suite, r[0], r[1])) |
---|
222 | for r in errors[1]: |
---|
223 | print("\nSuite: %s had following failures:\n %s : %s"%(suite, r[0], r[1])) |
---|
224 | print("=================================================") |
---|