Changeset 0662f53 in sasview
- Timestamp:
- Apr 19, 2018 2:37:02 PM (7 years ago)
- Branches:
- ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- d79bb7e
- Parents:
- 044454d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Inversion/UnitTesting/InversionPerspectiveTest.py
r50bfab0 r0662f53 10 10 import sas.qtgui.path_prepare 11 11 from sas.qtgui.Perspectives.Inversion.InversionPerspective import InversionWindow 12 from sas.qtgui.Perspectives.Inversion.InversionUtils import WIDGETS 12 13 from sas.sascalc.dataloader.loader import Loader 13 14 from sas.qtgui.Plotting.PlotterData import Data1D … … 20 21 app = QtWidgets.QApplication(sys.argv) 21 22 23 22 24 class InversionTest(unittest.TestCase): 23 '''Test the Inversion Interface''' 25 """ Test the Inversion Perspective GUI """ 26 24 27 def setUp(self): 25 '''Create the InversionWindow'''28 """ Create the InversionWindow """ 26 29 self.widget = InversionWindow(None) 30 self.widget.performEstimate = MagicMock() 31 self.fakeData1 = GuiUtils.HashableStandardItem("A") 32 self.fakeData2 = GuiUtils.HashableStandardItem("B") 33 reference_data1 = Data1D(x=[0.1, 0.2], y=[0.0, 0.0], dy=[0.0, 0.0]) 34 reference_data2 = Data1D(x=[0.1, 0.2], y=[0.0, 0.0], dy=[0.0, 0.0]) 35 GuiUtils.updateModelItem(self.fakeData1, [reference_data1]) 36 GuiUtils.updateModelItem(self.fakeData2, [reference_data2]) 27 37 28 38 def tearDown(self): 29 '''Destroy the InversionWindow''' 39 """ Destroy the InversionWindow """ 40 self.widget.setClosable(True) 30 41 self.widget.close() 31 42 self.widget = None 32 43 33 def testDefaults(self): 34 '''Test the GUI in its default state''' 44 def removeAllData(self): 45 """ Cleanup method to restore widget to its base state """ 46 while len(self.widget.dataList) > 0: 47 self.widget.removeData() 48 49 def baseGUIState(self): 50 """ Testing base state of Inversion """ 51 # base class information 35 52 self.assertIsInstance(self.widget, QtWidgets.QWidget) 36 53 self.assertEqual(self.widget.windowTitle(), "P(r) Inversion Perspective") 37 self.assertEqual(self.widget.model.columnCount(), 1) 38 self.assertEqual(self.widget.model.rowCount(), 22) 39 self.assertFalse(self.widget.calculateAllButton.isEnabled()) 40 self.assertFalse(self.widget.calculateThisButton.isEnabled()) 54 self.assertFalse(self.widget.isClosable()) 55 # mapper 41 56 self.assertIsInstance(self.widget.mapper, QtWidgets.QDataWidgetMapper) 42 # make sure the model is assigned and at least the data is mapped43 self.assertEqual(self.widget.mapper.model(), self.widget.model)44 57 self.assertNotEqual(self.widget.mapper.mappedSection(self.widget.dataList), -1) 45 46 58 # validators 47 59 self.assertIsInstance(self.widget.noOfTermsInput.validator(), QtGui.QIntValidator) … … 52 64 self.assertIsInstance(self.widget.slitHeightInput.validator(), QtGui.QDoubleValidator) 53 65 self.assertIsInstance(self.widget.slitWidthInput.validator(), QtGui.QDoubleValidator) 54 55 66 # model 56 67 self.assertEqual(self.widget.model.rowCount(), 22) 57 58 def testSetData(self): 59 ''' Check if sending data works as expected''' 60 # Create dummy data 61 item1 = GuiUtils.HashableStandardItem("A") 62 item2 = GuiUtils.HashableStandardItem("B") 63 reference_data = Data1D(x=[0.1, 0.2], y=[0.0, 0.0], dy=[0.0, 0.0]) 64 GuiUtils.updateModelItem(item1, [reference_data]) 65 GuiUtils.updateModelItem(item2, [reference_data]) 66 self.widget.performEstimate = MagicMock() 67 self.widget.setData([item1, item2]) 68 69 # Test the globals 70 self.assertEqual(len(self.widget._data_list), 2) 71 self.assertEqual(len(self.widget.data_plot_list), 2) 72 self.assertEqual(len(self.widget.pr_plot_list), 2) 68 self.assertEqual(self.widget.model.columnCount(), 1) 69 self.assertEqual(self.widget.mapper.model(), self.widget.model) 70 # buttons 71 self.assertFalse(self.widget.calculateThisButton.isEnabled()) 72 self.assertFalse(self.widget.removeButton.isEnabled()) 73 self.assertFalse(self.widget.regConstantSuggestionButton.isEnabled()) 74 self.assertFalse(self.widget.noOfTermsSuggestionButton.isEnabled()) 75 self.assertFalse(self.widget.explorerButton.isEnabled()) 76 self.assertTrue(self.widget.helpButton.isEnabled()) 77 # extra windows and charts 78 self.assertIsNone(self.widget.dmaxWindow) 79 self.assertIsNone(self.widget.prPlot) 80 self.assertIsNone(self.widget.dataPlot) 81 # threads 82 self.assertIsNone(self.widget.calcThread) 83 self.assertIsNone(self.widget.estimationThread) 84 self.assertIsNone(self.widget.estimationThreadNT) 85 86 def baseBatchState(self): 87 """ Testing the base batch fitting state """ 88 self.assertTrue(self.widget.allowBatch()) 89 self.assertFalse(self.widget.isBatch) 90 self.assertIsNone(self.widget.batchResultsWindow) 91 self.assertFalse(self.widget.calculateAllButton.isEnabled()) 92 self.assertEqual(len(self.widget.batchResults), 0) 93 self.assertEqual(len(self.widget.batchComplete), 0) 94 self.widget.closeBatchResults() 95 self.assertIsNone(self.widget.batchResultsWindow) 96 97 def zeroDataSetState(self): 98 """ Testing the base data state of the GUI """ 99 # data variables 100 self.assertIsNone(self.widget._data) 101 self.assertEqual(len(self.widget._dataList), 0) 102 self.assertEqual(self.widget.nTermsSuggested, 10) 103 # inputs 104 self.assertEqual(len(self.widget.dataList), 0) 105 self.assertEqual(self.widget.backgroundInput.text(), "0.0") 106 self.assertEqual(self.widget.minQInput.text(), "") 107 self.assertEqual(self.widget.maxQInput.text(), self.widget.minQInput.text()) 108 self.assertEqual(self.widget.regularizationConstantInput.text(), "0.0001") 109 self.assertEqual(self.widget.noOfTermsInput.text(), "10") 110 self.assertEqual(self.widget.maxDistanceInput.text(), "140.0") 111 112 def oneDataSetState(self): 113 """ Testing the base data state of the GUI """ 114 # Test the globals after first sent 115 self.assertEqual(len(self.widget._dataList), 1) 116 self.assertEqual(self.widget.dataList.count(), 1) 117 # See that the buttons are now enabled properly 118 self.assertFalse(self.widget.calculateAllButton.isEnabled()) 119 self.assertTrue(self.widget.calculateThisButton.isEnabled()) 120 self.assertTrue(self.widget.removeButton.isEnabled()) 121 self.assertTrue(self.widget.explorerButton.isEnabled()) 122 123 def twoDataSetState(self): 124 """ Testing the base data state of the GUI """ 125 # Test the globals after first sent 126 self.assertEqual(len(self.widget._dataList), 2) 73 127 self.assertEqual(self.widget.dataList.count(), 2) 74 75 # See that the buttons are now enabled 128 # See that the buttons are now enabled properly 76 129 self.assertTrue(self.widget.calculateAllButton.isEnabled()) 77 130 self.assertTrue(self.widget.calculateThisButton.isEnabled()) … … 79 132 self.assertTrue(self.widget.explorerButton.isEnabled()) 80 133 81 def notestRemoveData(self): 82 ''' Test data removal from widget ''' 83 # Create dummy data 84 item1 = GuiUtils.HashableStandardItem("A") 85 item2 = GuiUtils.HashableStandardItem("B") 86 reference_data1 = Data1D(x=[0.1, 0.2], y=[0.0, 0.0], dy=[0.0, 0.0]) 87 reference_data2 = Data1D(x=[0.1, 0.2], y=[0.0, 0.0], dy=[0.0, 0.0]) 88 GuiUtils.updateModelItem(item1, [reference_data1]) 89 GuiUtils.updateModelItem(item2, [reference_data2]) 90 self.widget.performEstimate = MagicMock() 91 self.widget.setData([item1, item2]) 92 134 def testDefaults(self): 135 """ Test the GUI in its default state """ 136 self.baseGUIState() 137 self.zeroDataSetState() 138 self.baseBatchState() 139 140 def testAllowBatch(self): 141 """ Batch P(r) Tests """ 142 self.baseBatchState() 143 144 def testSetData(self): 145 """ Check if sending data works as expected """ 146 self.zeroDataSetState() 147 self.widget.setData([self.fakeData1]) 148 self.oneDataSetState() 149 self.widget.setData([self.fakeData1]) 150 self.oneDataSetState() 151 self.widget.setData([self.fakeData2]) 152 self.twoDataSetState() 153 self.removeAllData() 154 self.zeroDataSetState() 155 156 def testRemoveData(self): 157 """ Test data removal from widget """ 158 self.widget.setData([self.fakeData1, self.fakeData2]) 159 self.twoDataSetState() 93 160 # Remove data 0 94 161 self.widget.removeData() 95 96 # Test the globals 97 self.assertEqual(len(self.widget._data_list), 1) 98 self.assertEqual(len(self.widget.data_plot_list), 1) 99 self.assertEqual(len(self.widget.pr_plot_list), 1) 100 self.assertEqual(self.widget.dataList.count(), 1) 101 102 103 def testAllowBatch(self): 104 ''' Batch is allowed for this perspective''' 105 self.assertTrue(self.widget.allowBatch()) 106 107 def notestModelChanged(self): 108 ''' test the model update ''' 109 # unfinished functionality 110 pass 111 112 def notestHelp(self): 113 ''' test help widget show ''' 114 # unfinished functionality 115 pass 116 117 def testOpenExplorerWindow(self): 118 ''' open Dx window ''' 119 self.widget.openExplorerWindow() 120 self.assertTrue(self.widget.dmaxWindow.isVisible()) 162 self.oneDataSetState() 163 164 def testClose(self): 165 """ Test methods related to closing the window """ 166 self.assertFalse(self.widget.isClosable()) 167 self.widget.close() 168 self.assertTrue(self.widget.isVisible()) 169 self.widget.setClosable(False) 170 self.assertFalse(self.widget.isClosable()) 171 self.widget.close() 172 self.assertTrue(self.widget.isVisible()) 173 self.widget.setClosable(True) 174 self.assertTrue(self.widget.isClosable()) 175 self.widget.setClosable() 176 self.assertTrue(self.widget.isClosable()) 177 self.widget.close() 178 self.assertFalse(self.widget.isVisible()) 121 179 122 180 def testGetNFunc(self): 123 ''' test nfunc getter '''181 """ test nfunc getter """ 124 182 # Float 125 183 self.widget.noOfTermsInput.setText("10.0") … … 142 200 143 201 def testSetCurrentData(self): 144 ''' test current data setter ''' 145 # Create dummy data 146 item1 = GuiUtils.HashableStandardItem("A") 147 item2 = GuiUtils.HashableStandardItem("B") 148 reference_data1 = Data1D(x=[0.1, 0.2], y=[0.0, 0.0], dy=[0.0, 0.0]) 149 reference_data2 = Data1D(x=[0.1, 0.2], y=[0.0, 0.0], dy=[0.0, 0.0]) 150 GuiUtils.updateModelItem(item1, [reference_data1]) 151 GuiUtils.updateModelItem(item2, [reference_data2]) 152 self.widget.performEstimate = MagicMock() 153 self.widget.setData([item1, item2]) 202 """ test current data setter """ 203 self.widget.setData([self.fakeData1, self.fakeData2]) 154 204 155 205 # Check that the current data is reference2 156 self.assertEqual(self.widget._data, item2) 157 206 self.assertEqual(self.widget._data, self.fakeData2) 158 207 # Set the ref to none 159 208 self.widget.setCurrentData(None) 160 self.assertEqual(self.widget._data, item2) 161 209 self.assertEqual(self.widget._data, self.fakeData2) 162 210 # Set the ref to wrong type 163 211 with self.assertRaises(AttributeError): 164 212 self.widget.setCurrentData("Afandi Kebab") 165 166 # Set the reference to ref2 167 self.widget.setCurrentData(item1) 168 self.assertEqual(self.widget._data, item1) 213 # Set the reference to ref1 214 self.widget.setCurrentData(self.fakeData1) 215 self.assertEqual(self.widget._data, self.fakeData1) 216 217 def notestModelChanged(self): 218 """ test the model update """ 219 self.assertTrue(self.widget._calculator.get_dmax(), 140.0) 220 self.widget.maxDistanceInput.setText("750.0") 221 self.assertTrue(self.widget._calculator.get_dmax(), 750.0) 222 self.assertTrue(self.widget._calculator.get_qmax(), 0.0) 223 self.widget.maxQInput.setText("100.0") 224 self.assertTrue(self.widget._calculator.get_dmax(), 100.0) 225 226 def notestHelp(self): 227 """ test help widget show """ 228 # TODO: test help button(s) 229 pass 230 231 def notestOpenExplorerWindow(self): 232 """ open Dx window """ 233 # TODO: test explorer functionality 234 self.widget.openExplorerWindow() 235 self.assertTrue(self.widget.dmaxWindow.isVisible()) 236 169 237 170 238 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.