Changeset 1042dba in sasview for src/sas/qtgui/UnitTesting
- Timestamp:
- Jun 17, 2016 9:56:01 AM (8 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:
- 9e426c1
- Parents:
- a281ab8
- Location:
- src/sas/qtgui/UnitTesting
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/UnitTesting/DataExplorerTest.py
ra281ab8 r1042dba 9 9 # Local 10 10 from sas.sasgui.guiframe.dataFitting import Data1D 11 from sas.sascalc.dataloader.loader import Loader 12 from sas.sasgui.guiframe.data_manager import DataManager 13 11 14 from DataExplorer import DataExplorerWindow 12 15 from GuiManager import GuiManager 13 16 from GuiUtils import * 14 17 from UnitTesting.TestUtils import QtSignalSpy 18 from Plotter import Plotter 15 19 16 20 app = QApplication(sys.argv) … … 297 301 self.assertTrue(self.form.manager.add_data.called) 298 302 303 def testNewPlot(self): 304 """ 305 Creating new plots from Data1D/2D 306 """ 307 loader = Loader() 308 manager = DataManager() 309 310 # get Data1D 311 p_file="cyl_400_20.txt" 312 output_object = loader.load(p_file) 313 new_data = [manager.create_gui_data(output_object, p_file)] 314 315 # Mask the plot show call 316 Plotter.show = MagicMock() 317 318 # Mask retrieval of the data 319 self.form.plotsFromCheckedItems = MagicMock(return_value=new_data) 320 321 # Call the plotting method 322 self.form.newPlot() 323 324 # The plot was displayed 325 self.assertTrue(Plotter.show.called) 326 299 327 300 328 if __name__ == "__main__": -
src/sas/qtgui/UnitTesting/GuiUtilsTest.py
ra281ab8 r1042dba 1 1 import sys 2 2 import unittest 3 4 from PyQt4 import QtCore 5 from PyQt4 import QtGui 6 7 # SV imports 8 from sas.sascalc.dataloader.loader import Loader 9 from sas.sasgui.guiframe.data_manager import DataManager 3 10 4 11 # Tested module … … 12 19 13 20 def tearDown(self): 14 ''' empty'''21 '''Empty''' 15 22 pass 16 23 … … 76 83 self.assertEqual(str(list_from_item[1]), test_list[1]) 77 84 85 86 def testPlotsFromCheckedItems(self): 87 """ 88 Test addition of a plottable to the model 89 """ 90 91 # Mockup data 92 test_list0 = "FRIDAY" 93 test_list1 = "SATURDAY" 94 test_list2 = "MONDAY" 95 96 # Main item ("file") 97 checkbox_model = QtGui.QStandardItemModel() 98 checkbox_item = QtGui.QStandardItem(True) 99 checkbox_item.setCheckable(True) 100 checkbox_item.setCheckState(QtCore.Qt.Checked) 101 test_item0 = QtGui.QStandardItem() 102 test_item0.setData(QtCore.QVariant(test_list0)) 103 104 # Checked item 1 105 test_item1 = QtGui.QStandardItem(True) 106 test_item1.setCheckable(True) 107 test_item1.setCheckState(QtCore.Qt.Checked) 108 object_item = QtGui.QStandardItem() 109 object_item.setData(QtCore.QVariant(test_list1)) 110 test_item1.setChild(0, object_item) 111 112 checkbox_item.setChild(0, test_item0) 113 checkbox_item.appendRow(test_item1) 114 115 # Unchecked item 2 116 test_item2 = QtGui.QStandardItem(True) 117 test_item2.setCheckable(True) 118 test_item2.setCheckState(QtCore.Qt.Unchecked) 119 object_item = QtGui.QStandardItem() 120 object_item.setData(QtCore.QVariant(test_list2)) 121 test_item2.setChild(0, object_item) 122 checkbox_item.appendRow(test_item2) 123 124 checkbox_model.appendRow(checkbox_item) 125 126 # Pull out the "plottable" documents 127 plot_list = plotsFromCheckedItems(checkbox_model) 128 129 # Make sure only the checked data is present 130 # FRIDAY IN 131 self.assertIn(test_list0, plot_list) 132 # SATURDAY IN 133 self.assertIn(test_list1, plot_list) 134 # MONDAY NOT IN 135 self.assertNotIn(test_list2, plot_list) 136 137 def testInfoFromData(self): 138 """ 139 Test Info element extraction from a plottable object 140 """ 141 loader = Loader() 142 manager = DataManager() 143 144 # get Data1D 145 p_file="cyl_400_20.txt" 146 output_object = loader.load(p_file) 147 new_data = manager.create_gui_data(output_object, p_file) 148 149 # Extract Info elements into a model item 150 item = infoFromData(new_data) 151 152 # Test the item and its children 153 self.assertIsInstance(item, QtGui.QStandardItem) 154 self.assertEqual(item.rowCount(), 5) 155 self.assertEqual(item.text(), "Info") 156 self.assertIn(p_file, item.child(0).text()) 157 self.assertIn("Run", item.child(1).text()) 158 self.assertIn("Data1D", item.child(2).text()) 159 self.assertIn(p_file, item.child(3).text()) 160 self.assertIn("Process",item.child(4).text()) 161 162 78 163 if __name__ == "__main__": 79 164 unittest.main()
Note: See TracChangeset
for help on using the changeset viewer.