[06b0138] | 1 | import unittest |
---|
[464cd07] | 2 | import sys |
---|
[4992ff2] | 3 | from PyQt5 import QtGui |
---|
| 4 | from PyQt5 import QtWidgets |
---|
[464cd07] | 5 | |
---|
[32f6cdd] | 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 |
---|
[d0528c4] | 11 | by running ``python setup.py install`` in both repositories. |
---|
[32f6cdd] | 12 | |
---|
[144fe21] | 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`` |
---|
[32f6cdd] | 17 | """ |
---|
| 18 | |
---|
[144fe21] | 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 | |
---|
[464cd07] | 30 | # Prepare the general QApplication instance |
---|
[4992ff2] | 31 | app = QtWidgets.QApplication(sys.argv) |
---|
[06b0138] | 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 | |
---|
[53c771e] | 41 | ## Plotting |
---|
[06b0138] | 42 | from Plotting.UnitTesting import AddTextTest |
---|
| 43 | from Plotting.UnitTesting import PlotHelperTest |
---|
| 44 | from Plotting.UnitTesting import WindowTitleTest |
---|
[53c771e] | 45 | from Plotting.UnitTesting import ScalePropertiesTest |
---|
[06b0138] | 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 |
---|
[53c771e] | 54 | from Plotting.UnitTesting import PlotterBaseTest |
---|
| 55 | from Plotting.UnitTesting import PlotterTest |
---|
| 56 | from Plotting.UnitTesting import Plotter2DTest |
---|
[06b0138] | 57 | |
---|
| 58 | # Calculators |
---|
| 59 | from Calculators.UnitTesting import KiessigCalculatorTest |
---|
| 60 | from Calculators.UnitTesting import DensityCalculatorTest |
---|
| 61 | from Calculators.UnitTesting import GenericScatteringCalculatorTest |
---|
[464cd07] | 62 | from Calculators.UnitTesting import SLDCalculatorTest |
---|
| 63 | from Calculators.UnitTesting import SlitSizeCalculatorTest |
---|
[01cda57] | 64 | from Calculators.UnitTesting import ResolutionCalculatorPanelTest |
---|
[d5c5d3d] | 65 | from Calculators.UnitTesting import DataOperationUtilityTest |
---|
[06b0138] | 66 | |
---|
| 67 | # Utilities |
---|
| 68 | from Utilities.UnitTesting import GuiUtilsTest |
---|
| 69 | from Utilities.UnitTesting import SasviewLoggerTest |
---|
[3b3b40b] | 70 | from Utilities.UnitTesting import GridPanelTest |
---|
| 71 | from Utilities.UnitTesting import ModelEditorTest |
---|
| 72 | from Utilities.UnitTesting import PluginDefinitionTest |
---|
| 73 | from Utilities.UnitTesting import TabbedModelEditorTest |
---|
[01ef3f7] | 74 | from Utilities.UnitTesting import AddMultEditorTest |
---|
[57be490] | 75 | from Utilities.UnitTesting import ReportDialogTest |
---|
[06b0138] | 76 | |
---|
| 77 | # Unit Testing |
---|
| 78 | from UnitTesting import TestUtilsTest |
---|
| 79 | |
---|
| 80 | # Perspectives |
---|
[7c487846] | 81 | # Fitting |
---|
[06b0138] | 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 |
---|
[72f4834] | 87 | from Perspectives.Fitting.UnitTesting import FittingOptionsTest |
---|
[0595bb7] | 88 | from Perspectives.Fitting.UnitTesting import MultiConstraintTest |
---|
[da9a0722] | 89 | from Perspectives.Fitting.UnitTesting import ComplexConstraintTest |
---|
[676f137] | 90 | from Perspectives.Fitting.UnitTesting import ConstraintWidgetTest |
---|
[0595bb7] | 91 | |
---|
[7c487846] | 92 | # Invariant |
---|
| 93 | from Perspectives.Invariant.UnitTesting import InvariantPerspectiveTest |
---|
[06b0138] | 94 | |
---|
[676f137] | 95 | # Inversion |
---|
| 96 | from Perspectives.Inversion.UnitTesting import InversionPerspectiveTest |
---|
| 97 | |
---|
[144fe21] | 98 | def plottingSuite(): |
---|
[06b0138] | 99 | suites = ( |
---|
| 100 | # Plotting |
---|
| 101 | unittest.makeSuite(Plotter2DTest.Plotter2DTest, 'test'), |
---|
[53c771e] | 102 | unittest.makeSuite(PlotHelperTest.PlotHelperTest, 'test'), |
---|
[06b0138] | 103 | unittest.makeSuite(AddTextTest.AddTextTest, 'test'), |
---|
[53c771e] | 104 | unittest.makeSuite(WindowTitleTest.WindowTitleTest, 'test'), |
---|
[06b0138] | 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'), |
---|
[53c771e] | 114 | unittest.makeSuite(PlotterBaseTest.PlotterBaseTest, 'test'), |
---|
| 115 | unittest.makeSuite(PlotterTest.PlotterTest, 'test'), |
---|
[144fe21] | 116 | ) |
---|
| 117 | return unittest.TestSuite(suites) |
---|
[06b0138] | 118 | |
---|
[144fe21] | 119 | def mainSuite(): |
---|
| 120 | suites = ( |
---|
[06b0138] | 121 | # Main window |
---|
| 122 | unittest.makeSuite(DataExplorerTest.DataExplorerTest, 'test'), |
---|
[f4a1433] | 123 | unittest.makeSuite(DroppableDataLoadWidgetTest.DroppableDataLoadWidgetTest, 'test'), |
---|
[06b0138] | 124 | unittest.makeSuite(MainWindowTest.MainWindowTest, 'test'), |
---|
[53c771e] | 125 | unittest.makeSuite(GuiManagerTest.GuiManagerTest, 'test'), |
---|
| 126 | unittest.makeSuite(AboutBoxTest.AboutBoxTest, 'test'), |
---|
| 127 | unittest.makeSuite(WelcomePanelTest.WelcomePanelTest, 'test'), |
---|
[144fe21] | 128 | ) |
---|
| 129 | return unittest.TestSuite(suites) |
---|
[06b0138] | 130 | |
---|
[144fe21] | 131 | def utilitiesSuite(): |
---|
| 132 | suites = ( |
---|
| 133 | ## Utilities |
---|
[0261bc1] | 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'), |
---|
[3b3b40b] | 139 | unittest.makeSuite(GridPanelTest.BatchOutputPanelTest, 'test'), |
---|
| 140 | unittest.makeSuite(ModelEditorTest.ModelEditorTest, 'test'), |
---|
| 141 | unittest.makeSuite(PluginDefinitionTest.PluginDefinitionTest, 'test'), |
---|
| 142 | unittest.makeSuite(TabbedModelEditorTest.TabbedModelEditorTest,'test'), |
---|
[01ef3f7] | 143 | unittest.makeSuite(AddMultEditorTest.AddMultEditorTest, 'test'), |
---|
[57be490] | 144 | unittest.makeSuite(ReportDialogTest.ReportDialogTest, 'test'), |
---|
[144fe21] | 145 | ) |
---|
| 146 | return unittest.TestSuite(suites) |
---|
[06b0138] | 147 | |
---|
[144fe21] | 148 | def calculatorsSuite(): |
---|
| 149 | suites = ( |
---|
[06b0138] | 150 | # Calculators |
---|
| 151 | unittest.makeSuite(KiessigCalculatorTest.KiessigCalculatorTest, 'test'), |
---|
| 152 | unittest.makeSuite(DensityCalculatorTest.DensityCalculatorTest, 'test'), |
---|
| 153 | unittest.makeSuite(GenericScatteringCalculatorTest.GenericScatteringCalculatorTest, 'test'), |
---|
[464cd07] | 154 | unittest.makeSuite(SLDCalculatorTest.SLDCalculatorTest, 'test'), |
---|
| 155 | unittest.makeSuite(SlitSizeCalculatorTest.SlitSizeCalculatorTest, 'test'), |
---|
[01cda57] | 156 | unittest.makeSuite(ResolutionCalculatorPanelTest.ResolutionCalculatorPanelTest, 'test'), |
---|
[d5c5d3d] | 157 | unittest.makeSuite(DataOperationUtilityTest.DataOperationUtilityTest, 'test'), |
---|
[144fe21] | 158 | ) |
---|
| 159 | return unittest.TestSuite(suites) |
---|
[06b0138] | 160 | |
---|
[144fe21] | 161 | def fittingSuite(): |
---|
| 162 | suites = ( |
---|
[06b0138] | 163 | # Perspectives |
---|
[7c487846] | 164 | # Fitting |
---|
[06b0138] | 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'), |
---|
[72f4834] | 170 | unittest.makeSuite(FittingOptionsTest.FittingOptionsTest, 'test'), |
---|
[0595bb7] | 171 | unittest.makeSuite(MultiConstraintTest.MultiConstraintTest, 'test'), |
---|
[676f137] | 172 | unittest.makeSuite(ConstraintWidgetTest.ConstraintWidgetTest, 'test'), |
---|
[da9a0722] | 173 | unittest.makeSuite(ComplexConstraintTest.ComplexConstraintTest, 'test'), |
---|
[144fe21] | 174 | ) |
---|
| 175 | return unittest.TestSuite(suites) |
---|
[676f137] | 176 | |
---|
[144fe21] | 177 | def perspectivesSuite(): |
---|
| 178 | suites = ( |
---|
[7c487846] | 179 | # Invariant |
---|
| 180 | unittest.makeSuite(InvariantPerspectiveTest.InvariantPerspectiveTest, 'test'), |
---|
[50bfab0] | 181 | # Inversion |
---|
[144fe21] | 182 | #unittest.makeSuite(InversionPerspectiveTest.InversionTest, 'test'), |
---|
[676f137] | 183 | ) |
---|
[06b0138] | 184 | return unittest.TestSuite(suites) |
---|
| 185 | |
---|
| 186 | if __name__ == "__main__": |
---|
| 187 | |
---|
[144fe21] | 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:] |
---|
[7dd309a] | 192 | errors = {} |
---|
[144fe21] | 193 | for suite in user_suites: |
---|
| 194 | # create the suite object from name |
---|
| 195 | try: |
---|
[7dd309a] | 196 | |
---|
[144fe21] | 197 | suite_instance = globals()[suite]() |
---|
[7dd309a] | 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 | |
---|
[144fe21] | 213 | except KeyError: |
---|
[7dd309a] | 214 | print("Failure : %s "%str(ex)) |
---|
[144fe21] | 215 | print("ERROR: Incorrect suite name: %s " % suite) |
---|
| 216 | pass |
---|
[7dd309a] | 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("=================================================") |
---|