[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`` |
---|
| 17 | or modify tge VERBOSITY module variable. |
---|
[32f6cdd] | 18 | """ |
---|
| 19 | |
---|
[144fe21] | 20 | # Llist of all suite names. Every time a new suite is added, its name should |
---|
| 21 | # also be added here |
---|
| 22 | ALL_SUITES = [ |
---|
| 23 | 'calculatorsSuite', |
---|
| 24 | 'mainSuite', |
---|
| 25 | 'fittingSuite', |
---|
| 26 | 'plottingSuite', |
---|
| 27 | 'utilitiesSuite', |
---|
| 28 | 'perspectivesSuite', |
---|
| 29 | ] |
---|
| 30 | |
---|
| 31 | # Define output verbosity |
---|
| 32 | #VERBOSITY = 0 # quiet - just the total number of tests run and global result |
---|
| 33 | VERBOSITY = 1 # default - quiet + a dot for every successful test or a F for failure |
---|
| 34 | #VERBOSITY = 2 # verbose - default + help string of every test and the result |
---|
| 35 | |
---|
[464cd07] | 36 | # Prepare the general QApplication instance |
---|
[4992ff2] | 37 | app = QtWidgets.QApplication(sys.argv) |
---|
[06b0138] | 38 | |
---|
| 39 | # Main Window |
---|
| 40 | from MainWindow.UnitTesting import AboutBoxTest |
---|
| 41 | from MainWindow.UnitTesting import DataExplorerTest |
---|
| 42 | from MainWindow.UnitTesting import WelcomePanelTest |
---|
| 43 | from MainWindow.UnitTesting import DroppableDataLoadWidgetTest |
---|
| 44 | from MainWindow.UnitTesting import GuiManagerTest |
---|
| 45 | from MainWindow.UnitTesting import MainWindowTest |
---|
| 46 | |
---|
[53c771e] | 47 | ## Plotting |
---|
[06b0138] | 48 | from Plotting.UnitTesting import AddTextTest |
---|
| 49 | from Plotting.UnitTesting import PlotHelperTest |
---|
| 50 | from Plotting.UnitTesting import WindowTitleTest |
---|
[53c771e] | 51 | from Plotting.UnitTesting import ScalePropertiesTest |
---|
[06b0138] | 52 | from Plotting.UnitTesting import SetGraphRangeTest |
---|
| 53 | from Plotting.UnitTesting import LinearFitTest |
---|
| 54 | from Plotting.UnitTesting import PlotPropertiesTest |
---|
| 55 | from Plotting.UnitTesting import PlotUtilitiesTest |
---|
| 56 | from Plotting.UnitTesting import ColorMapTest |
---|
| 57 | from Plotting.UnitTesting import BoxSumTest |
---|
| 58 | from Plotting.UnitTesting import SlicerModelTest |
---|
| 59 | from Plotting.UnitTesting import SlicerParametersTest |
---|
[53c771e] | 60 | from Plotting.UnitTesting import PlotterBaseTest |
---|
| 61 | from Plotting.UnitTesting import PlotterTest |
---|
| 62 | from Plotting.UnitTesting import Plotter2DTest |
---|
[06b0138] | 63 | |
---|
| 64 | # Calculators |
---|
| 65 | from Calculators.UnitTesting import KiessigCalculatorTest |
---|
| 66 | from Calculators.UnitTesting import DensityCalculatorTest |
---|
| 67 | from Calculators.UnitTesting import GenericScatteringCalculatorTest |
---|
[464cd07] | 68 | from Calculators.UnitTesting import SLDCalculatorTest |
---|
| 69 | from Calculators.UnitTesting import SlitSizeCalculatorTest |
---|
[01cda57] | 70 | from Calculators.UnitTesting import ResolutionCalculatorPanelTest |
---|
[d5c5d3d] | 71 | from Calculators.UnitTesting import DataOperationUtilityTest |
---|
[06b0138] | 72 | |
---|
| 73 | # Utilities |
---|
| 74 | from Utilities.UnitTesting import GuiUtilsTest |
---|
| 75 | from Utilities.UnitTesting import SasviewLoggerTest |
---|
[3b3b40b] | 76 | from Utilities.UnitTesting import GridPanelTest |
---|
| 77 | from Utilities.UnitTesting import ModelEditorTest |
---|
| 78 | from Utilities.UnitTesting import PluginDefinitionTest |
---|
| 79 | from Utilities.UnitTesting import TabbedModelEditorTest |
---|
[01ef3f7] | 80 | from Utilities.UnitTesting import AddMultEditorTest |
---|
[57be490] | 81 | from Utilities.UnitTesting import ReportDialogTest |
---|
[06b0138] | 82 | |
---|
| 83 | # Unit Testing |
---|
| 84 | from UnitTesting import TestUtilsTest |
---|
| 85 | |
---|
| 86 | # Perspectives |
---|
[7c487846] | 87 | # Fitting |
---|
[06b0138] | 88 | from Perspectives.Fitting.UnitTesting import FittingWidgetTest |
---|
| 89 | from Perspectives.Fitting.UnitTesting import FittingPerspectiveTest |
---|
| 90 | from Perspectives.Fitting.UnitTesting import FittingLogicTest |
---|
| 91 | from Perspectives.Fitting.UnitTesting import FittingUtilitiesTest |
---|
| 92 | from Perspectives.Fitting.UnitTesting import FitPageTest |
---|
[72f4834] | 93 | from Perspectives.Fitting.UnitTesting import FittingOptionsTest |
---|
[0595bb7] | 94 | from Perspectives.Fitting.UnitTesting import MultiConstraintTest |
---|
[da9a0722] | 95 | from Perspectives.Fitting.UnitTesting import ComplexConstraintTest |
---|
[676f137] | 96 | from Perspectives.Fitting.UnitTesting import ConstraintWidgetTest |
---|
[0595bb7] | 97 | |
---|
[7c487846] | 98 | # Invariant |
---|
| 99 | from Perspectives.Invariant.UnitTesting import InvariantPerspectiveTest |
---|
[06b0138] | 100 | |
---|
[676f137] | 101 | # Inversion |
---|
| 102 | from Perspectives.Inversion.UnitTesting import InversionPerspectiveTest |
---|
| 103 | |
---|
[144fe21] | 104 | def plottingSuite(): |
---|
[06b0138] | 105 | suites = ( |
---|
| 106 | # Plotting |
---|
| 107 | unittest.makeSuite(Plotter2DTest.Plotter2DTest, 'test'), |
---|
[53c771e] | 108 | unittest.makeSuite(PlotHelperTest.PlotHelperTest, 'test'), |
---|
[06b0138] | 109 | unittest.makeSuite(AddTextTest.AddTextTest, 'test'), |
---|
[53c771e] | 110 | unittest.makeSuite(WindowTitleTest.WindowTitleTest, 'test'), |
---|
[06b0138] | 111 | unittest.makeSuite(ScalePropertiesTest.ScalePropertiesTest, 'test'), |
---|
| 112 | unittest.makeSuite(SetGraphRangeTest.SetGraphRangeTest, 'test'), |
---|
| 113 | unittest.makeSuite(LinearFitTest.LinearFitTest, 'test'), |
---|
| 114 | unittest.makeSuite(PlotPropertiesTest.PlotPropertiesTest, 'test'), |
---|
| 115 | unittest.makeSuite(PlotUtilitiesTest.PlotUtilitiesTest, 'test'), |
---|
| 116 | unittest.makeSuite(ColorMapTest.ColorMapTest, 'test'), |
---|
| 117 | unittest.makeSuite(BoxSumTest.BoxSumTest, 'test'), |
---|
| 118 | unittest.makeSuite(SlicerModelTest.SlicerModelTest, 'test'), |
---|
| 119 | unittest.makeSuite(SlicerParametersTest.SlicerParametersTest, 'test'), |
---|
[53c771e] | 120 | unittest.makeSuite(PlotterBaseTest.PlotterBaseTest, 'test'), |
---|
| 121 | unittest.makeSuite(PlotterTest.PlotterTest, 'test'), |
---|
[144fe21] | 122 | ) |
---|
| 123 | return unittest.TestSuite(suites) |
---|
[06b0138] | 124 | |
---|
[144fe21] | 125 | def mainSuite(): |
---|
| 126 | suites = ( |
---|
[06b0138] | 127 | # Main window |
---|
| 128 | unittest.makeSuite(DataExplorerTest.DataExplorerTest, 'test'), |
---|
[f4a1433] | 129 | unittest.makeSuite(DroppableDataLoadWidgetTest.DroppableDataLoadWidgetTest, 'test'), |
---|
[06b0138] | 130 | unittest.makeSuite(MainWindowTest.MainWindowTest, 'test'), |
---|
[53c771e] | 131 | unittest.makeSuite(GuiManagerTest.GuiManagerTest, 'test'), |
---|
| 132 | unittest.makeSuite(AboutBoxTest.AboutBoxTest, 'test'), |
---|
| 133 | unittest.makeSuite(WelcomePanelTest.WelcomePanelTest, 'test'), |
---|
[144fe21] | 134 | ) |
---|
| 135 | return unittest.TestSuite(suites) |
---|
[06b0138] | 136 | |
---|
[144fe21] | 137 | def utilitiesSuite(): |
---|
| 138 | suites = ( |
---|
| 139 | ## Utilities |
---|
[0261bc1] | 140 | unittest.makeSuite(TestUtilsTest.TestUtilsTest, 'test'), |
---|
| 141 | unittest.makeSuite(SasviewLoggerTest.SasviewLoggerTest, 'test'), |
---|
| 142 | unittest.makeSuite(GuiUtilsTest.GuiUtilsTest, 'test'), |
---|
| 143 | unittest.makeSuite(GuiUtilsTest.DoubleValidatorTest, 'test'), |
---|
| 144 | unittest.makeSuite(GuiUtilsTest.HashableStandardItemTest, 'test'), |
---|
[3b3b40b] | 145 | unittest.makeSuite(GridPanelTest.BatchOutputPanelTest, 'test'), |
---|
| 146 | unittest.makeSuite(ModelEditorTest.ModelEditorTest, 'test'), |
---|
| 147 | unittest.makeSuite(PluginDefinitionTest.PluginDefinitionTest, 'test'), |
---|
| 148 | unittest.makeSuite(TabbedModelEditorTest.TabbedModelEditorTest,'test'), |
---|
[01ef3f7] | 149 | unittest.makeSuite(AddMultEditorTest.AddMultEditorTest, 'test'), |
---|
[57be490] | 150 | unittest.makeSuite(ReportDialogTest.ReportDialogTest, 'test'), |
---|
[144fe21] | 151 | ) |
---|
| 152 | return unittest.TestSuite(suites) |
---|
[06b0138] | 153 | |
---|
[144fe21] | 154 | def calculatorsSuite(): |
---|
| 155 | suites = ( |
---|
[06b0138] | 156 | # Calculators |
---|
| 157 | unittest.makeSuite(KiessigCalculatorTest.KiessigCalculatorTest, 'test'), |
---|
| 158 | unittest.makeSuite(DensityCalculatorTest.DensityCalculatorTest, 'test'), |
---|
| 159 | unittest.makeSuite(GenericScatteringCalculatorTest.GenericScatteringCalculatorTest, 'test'), |
---|
[464cd07] | 160 | unittest.makeSuite(SLDCalculatorTest.SLDCalculatorTest, 'test'), |
---|
| 161 | unittest.makeSuite(SlitSizeCalculatorTest.SlitSizeCalculatorTest, 'test'), |
---|
[01cda57] | 162 | unittest.makeSuite(ResolutionCalculatorPanelTest.ResolutionCalculatorPanelTest, 'test'), |
---|
[d5c5d3d] | 163 | unittest.makeSuite(DataOperationUtilityTest.DataOperationUtilityTest, 'test'), |
---|
[144fe21] | 164 | ) |
---|
| 165 | return unittest.TestSuite(suites) |
---|
[06b0138] | 166 | |
---|
[144fe21] | 167 | def fittingSuite(): |
---|
| 168 | suites = ( |
---|
[06b0138] | 169 | # Perspectives |
---|
[7c487846] | 170 | # Fitting |
---|
[06b0138] | 171 | unittest.makeSuite(FittingPerspectiveTest.FittingPerspectiveTest, 'test'), |
---|
| 172 | unittest.makeSuite(FittingWidgetTest.FittingWidgetTest, 'test'), |
---|
| 173 | unittest.makeSuite(FittingLogicTest.FittingLogicTest, 'test'), |
---|
| 174 | unittest.makeSuite(FittingUtilitiesTest.FittingUtilitiesTest, 'test'), |
---|
| 175 | unittest.makeSuite(FitPageTest.FitPageTest, 'test'), |
---|
[72f4834] | 176 | unittest.makeSuite(FittingOptionsTest.FittingOptionsTest, 'test'), |
---|
[0595bb7] | 177 | unittest.makeSuite(MultiConstraintTest.MultiConstraintTest, 'test'), |
---|
[676f137] | 178 | unittest.makeSuite(ConstraintWidgetTest.ConstraintWidgetTest, 'test'), |
---|
[da9a0722] | 179 | unittest.makeSuite(ComplexConstraintTest.ComplexConstraintTest, 'test'), |
---|
[144fe21] | 180 | ) |
---|
| 181 | return unittest.TestSuite(suites) |
---|
[676f137] | 182 | |
---|
[144fe21] | 183 | def perspectivesSuite(): |
---|
| 184 | suites = ( |
---|
[7c487846] | 185 | # Invariant |
---|
| 186 | unittest.makeSuite(InvariantPerspectiveTest.InvariantPerspectiveTest, 'test'), |
---|
[50bfab0] | 187 | # Inversion |
---|
[144fe21] | 188 | #unittest.makeSuite(InversionPerspectiveTest.InversionTest, 'test'), |
---|
[676f137] | 189 | ) |
---|
[06b0138] | 190 | return unittest.TestSuite(suites) |
---|
| 191 | |
---|
| 192 | if __name__ == "__main__": |
---|
| 193 | |
---|
[144fe21] | 194 | user_suites = ALL_SUITES |
---|
| 195 | # Check if user asked for specific suites: |
---|
| 196 | if len(sys.argv) > 1: |
---|
| 197 | user_suites = sys.argv[1:] |
---|
| 198 | |
---|
| 199 | runner = unittest.TextTestRunner(verbosity=VERBOSITY) |
---|
| 200 | for suite in user_suites: |
---|
| 201 | # create the suite object from name |
---|
| 202 | try: |
---|
| 203 | suite_instance = globals()[suite]() |
---|
| 204 | results = runner.run(suite_instance) |
---|
| 205 | except KeyError: |
---|
| 206 | print("ERROR: Incorrect suite name: %s " % suite) |
---|
| 207 | pass |
---|