Changeset 39551a68 in sasview for src/sas/qtgui/UnitTesting/GuiUtilsTest.py
- Timestamp:
- Aug 1, 2016 7:47:16 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:
- 1af348e
- Parents:
- 28a84e9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/UnitTesting/GuiUtilsTest.py
r28a84e9 r39551a68 10 10 from sas.sascalc.dataloader.loader import Loader 11 11 from sas.sasgui.guiframe.data_manager import DataManager 12 from sas.sasgui.guiframe.dataFitting import Data1D 13 from sas.sasgui.guiframe.dataFitting import Data2D 12 14 13 15 # Tested module 14 16 from GuiUtils import * 15 17 16 class FakeData(object): 17 '''Data1D/2D object for testing''' 18 def __init__(self): 19 self.x = [] 20 self.y = [] 18 app = QtGui.QApplication(sys.argv) 21 19 22 20 class GuiUtilsTest(unittest.TestCase): … … 198 196 """ 199 197 """ 200 self.assertRaises(retrieveData1d("BOOP")) 201 202 # data = FakeData() 203 pass 198 with self.assertRaises(AttributeError): 199 retrieveData1d("BOOP") 200 201 data = Data1D() 202 with self.assertRaises(ValueError): 203 retrieveData1d(data) 204 205 data = Data1D(x=[1.0, 2.0, 3.0], y=[10.0, 11.0, 12.0]) 206 207 text = retrieveData1d(data) 208 209 self.assertIn("Temperature:", text) 210 self.assertIn("Beam_size:", text) 211 self.assertIn("X_min = 1.0: X_max = 3.0", text) 212 self.assertIn("3.0 \t12.0 \t0.0 \t0.0", text) 204 213 205 214 def testRetrieveData2d(self): 206 215 """ 207 216 """ 208 pass 217 with self.assertRaises(AttributeError): 218 retrieveData2d("BOOP") 219 data = Data2D(image=[1.0, 2.0, 3.0], 220 err_image=[0.01, 0.02, 0.03], 221 qx_data=[0.1, 0.2, 0.3], 222 qy_data=[0.1, 0.2, 0.3]) 223 224 text = retrieveData2d(data) 225 226 self.assertIn("Type: Data2D", text) 227 self.assertIn("I_min = 1.0", text) 228 self.assertIn("I_max = 3.0", text) 229 self.assertIn("2 \t0.3 \t0.3 \t3.0 \t0.03 \t0.0 \t0.0", text) 209 230 210 231 def testOnTXTSave(self): 211 232 """ 212 """ 213 pass 233 Test the file writer for saving 1d/2d data 234 """ 235 path = "test123" 236 if os.path.isfile(path): 237 os.remove(path) 238 239 # Broken data 240 data = Data1D(x=[1.0, 2.0, 3.0], y=[]) 241 # Expect a raise 242 with self.assertRaises(IndexError): 243 onTXTSave(data, path) 244 245 # Good data - no dX/dY 246 data = Data1D(x=[1.0, 2.0, 3.0], y=[10.0, 11.0, 12.0]) 247 onTXTSave(data, path) 248 249 self.assertTrue(os.path.isfile(path)) 250 with open(path,'r') as out: 251 data_read = out.read() 252 self.assertEqual("<X> <Y>\n1 10\n2 11\n3 12\n", data_read) 253 254 if os.path.isfile(path): 255 os.remove(path) 256 257 # Good data - with dX/dY 258 data = Data1D(x=[1.0, 2.0, 3.0], y=[10.0, 11.0, 12.0], 259 dx=[0.1, 0.2, 0.3], dy=[0.1, 0.2, 0.3]) 260 261 onTXTSave(data, path) 262 with open(path,'r') as out: 263 data_read = out.read() 264 self.assertIn("<X> <Y> <dY> <dX>\n", data_read) 265 self.assertIn("1 10 0.1 0.1\n", data_read) 266 self.assertIn("2 11 0.2 0.2\n", data_read) 267 self.assertIn("3 12 0.3 0.3\n", data_read) 268 269 if os.path.isfile(path): 270 os.remove(path) 214 271 215 272 def testSaveData1D(self): 216 273 """ 217 """ 218 pass 274 Test the 1D file save method 275 """ 276 data = Data1D(x=[1.0, 2.0, 3.0], y=[10.0, 11.0, 12.0], 277 dx=[0.1, 0.2, 0.3], dy=[0.1, 0.2, 0.3]) 278 279 # Test the .txt format 280 file_name = "test123_out.txt" 281 QtGui.QFileDialog.getSaveFileName = MagicMock(return_value=file_name) 282 data.filename = "test123.txt" 283 saveData1D(data) 284 self.assertTrue(os.path.isfile(file_name)) 285 os.remove(file_name) 286 287 # Test the .xml format 288 file_name = "test123_out.xml" 289 QtGui.QFileDialog.getSaveFileName = MagicMock(return_value=file_name) 290 data.filename = "test123.xml" 291 saveData1D(data) 292 self.assertTrue(os.path.isfile(file_name)) 293 os.remove(file_name) 294 295 # Test the wrong format 296 file_name = "test123_out.mp3" 297 QtGui.QFileDialog.getSaveFileName = MagicMock(return_value=file_name) 298 data.filename = "test123.mp3" 299 saveData1D(data) 300 self.assertFalse(os.path.isfile(file_name)) 219 301 220 302 def testSaveData2D(self): 221 303 """ 222 """ 223 pass 304 Test the 1D file save method 305 """ 306 data = Data2D(image=[1.0, 2.0, 3.0], 307 err_image=[0.01, 0.02, 0.03], 308 qx_data=[0.1, 0.2, 0.3], 309 qy_data=[0.1, 0.2, 0.3]) 310 311 # Test the .txt format 312 file_name = "test123_out.dat" 313 QtGui.QFileDialog.getSaveFileName = MagicMock(return_value=file_name) 314 data.filename = "test123.dat" 315 saveData2D(data) 316 self.assertTrue(os.path.isfile(file_name)) 317 os.remove(file_name) 318 319 # Test the wrong format 320 file_name = "test123_out.mp3" 321 QtGui.QFileDialog.getSaveFileName = MagicMock(return_value=file_name) 322 data.filename = "test123.mp3" 323 saveData2D(data) 324 self.assertFalse(os.path.isfile(file_name)) 325 224 326 225 327 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.