source: sasview/src/sas/qtgui/GUITests.py @ fb560d2

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since fb560d2 was 7dd309a, checked in by Piotr Rozyczko <rozyczko@…>, 6 years ago

Improved failure/error display

  • Property mode set to 100644
File size: 9.6 KB
Line 
1import unittest
2import sys
3from PyQt5 import QtGui
4from PyQt5 import QtWidgets
5
6"""
7Unit tests for the QT GUI
8=========================
9
10In order to run the tests, first install SasView and sasmodels to site-packages
11by running ``python setup.py install`` in both repositories.
12
13The tests can be run with ``python GUITests.py``, or
14``python GUITests.py suiteName1 suiteName2 ...`` for a subset of tests.
15
16To 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
21ALL_SUITES = [
22    'calculatorsSuite',
23    'mainSuite',
24    'fittingSuite',
25    'plottingSuite',
26    'utilitiesSuite',
27    'perspectivesSuite',
28    ]
29
30# Prepare the general QApplication instance
31app = QtWidgets.QApplication(sys.argv)
32
33# Main Window
34from MainWindow.UnitTesting import AboutBoxTest
35from MainWindow.UnitTesting import DataExplorerTest
36from MainWindow.UnitTesting import WelcomePanelTest
37from MainWindow.UnitTesting import DroppableDataLoadWidgetTest
38from MainWindow.UnitTesting import GuiManagerTest
39from MainWindow.UnitTesting import MainWindowTest
40
41## Plotting
42from Plotting.UnitTesting import AddTextTest
43from Plotting.UnitTesting import PlotHelperTest
44from Plotting.UnitTesting import WindowTitleTest
45from Plotting.UnitTesting import ScalePropertiesTest
46from Plotting.UnitTesting import SetGraphRangeTest
47from Plotting.UnitTesting import LinearFitTest
48from Plotting.UnitTesting import PlotPropertiesTest
49from Plotting.UnitTesting import PlotUtilitiesTest
50from Plotting.UnitTesting import ColorMapTest
51from Plotting.UnitTesting import BoxSumTest
52from Plotting.UnitTesting import SlicerModelTest
53from Plotting.UnitTesting import SlicerParametersTest
54from Plotting.UnitTesting import PlotterBaseTest
55from Plotting.UnitTesting import PlotterTest
56from Plotting.UnitTesting import Plotter2DTest
57
58# Calculators
59from Calculators.UnitTesting import KiessigCalculatorTest
60from Calculators.UnitTesting import DensityCalculatorTest
61from Calculators.UnitTesting import GenericScatteringCalculatorTest
62from Calculators.UnitTesting import SLDCalculatorTest
63from Calculators.UnitTesting import SlitSizeCalculatorTest
64from Calculators.UnitTesting import ResolutionCalculatorPanelTest
65from Calculators.UnitTesting import DataOperationUtilityTest
66
67# Utilities
68from Utilities.UnitTesting import GuiUtilsTest
69from Utilities.UnitTesting import SasviewLoggerTest
70from Utilities.UnitTesting import GridPanelTest
71from Utilities.UnitTesting import ModelEditorTest
72from Utilities.UnitTesting import PluginDefinitionTest
73from Utilities.UnitTesting import TabbedModelEditorTest
74from Utilities.UnitTesting import AddMultEditorTest
75from Utilities.UnitTesting import ReportDialogTest
76
77# Unit Testing
78from UnitTesting import TestUtilsTest
79
80# Perspectives
81#  Fitting
82from Perspectives.Fitting.UnitTesting import FittingWidgetTest
83from Perspectives.Fitting.UnitTesting import FittingPerspectiveTest
84from Perspectives.Fitting.UnitTesting import FittingLogicTest
85from Perspectives.Fitting.UnitTesting import FittingUtilitiesTest
86from Perspectives.Fitting.UnitTesting import FitPageTest
87from Perspectives.Fitting.UnitTesting import FittingOptionsTest
88from Perspectives.Fitting.UnitTesting import MultiConstraintTest
89from Perspectives.Fitting.UnitTesting import ComplexConstraintTest
90from Perspectives.Fitting.UnitTesting import ConstraintWidgetTest
91
92#  Invariant
93from Perspectives.Invariant.UnitTesting import InvariantPerspectiveTest
94
95#  Inversion
96from Perspectives.Inversion.UnitTesting import InversionPerspectiveTest
97
98def 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
119def 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
131def 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
148def 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
161def 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
177def 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
186if __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("=================================================")
Note: See TracBrowser for help on using the repository browser.