Changeset 94f074c4 in sasview
- Timestamp:
- Apr 10, 2018 8:01:14 AM (7 years ago)
- Branches:
- master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, unittest-saveload
- Children:
- 3388337, 1176137
- Parents:
- fc25457 (diff), 63ddc03 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - git-author:
- Jeff Krzywon <krzywon@…> (04/10/18 08:01:14)
- git-committer:
- GitHub <noreply@…> (04/10/18 08:01:14)
- Files:
-
- 6 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/file_reader_base_class.py
ra58b5a0 r4a8d55c 31 31 FIELDS_2D = ('data', 'qx_data', 'qy_data', 'q_data', 'err_data', 32 32 'dqx_data', 'dqy_data', 'mask') 33 33 DEPRECATION_MESSAGE = ("\rThe extension of this file suggests the data set migh" 34 "t not be fully reduced. Support for the reader associat" 35 "ed with this file type has been removed. An attempt to " 36 "load the file was made, but, should it be successful, " 37 "SasView cannot guarantee the accuracy of the data.") 34 38 35 39 class FileReader(object): … … 40 44 # List of allowed extensions 41 45 ext = ['.txt'] 46 # Deprecated extensions 47 deprecated_extensions = ['.asc', '.nxs'] 42 48 # Bypass extension check and try to load anyway 43 49 allow_all = False … … 87 93 if not self.f_open.closed: 88 94 self.f_open.close() 95 if any(filepath.lower().endswith(ext) for ext in 96 self.deprecated_extensions): 97 self.handle_error_message(DEPRECATION_MESSAGE) 89 98 if len(self.output) > 0: 90 99 # Sort the data that's been loaded … … 146 155 else: 147 156 logger.warning(msg) 157 raise NoKnownLoaderException(msg) 148 158 149 159 def send_to_output(self): -
src/sas/sascalc/dataloader/loader.py
rdc8d1c2 r4a8d55c 90 90 ascii_loader = ascii_reader.Reader() 91 91 return ascii_loader.read(path) 92 except NoKnownLoaderException: 93 pass # Try the Cansas XML reader 92 94 except DefaultReaderException: 93 95 pass # Loader specific error to try the cansas XML reader … … 100 102 cansas_loader = cansas_reader.Reader() 101 103 return cansas_loader.read(path) 104 except NoKnownLoaderException: 105 pass # Try the NXcanSAS reader 102 106 except DefaultReaderException: 103 107 pass # Loader specific error to try the NXcanSAS reader -
src/sas/sasgui/guiframe/local_perspectives/data_loader/data_loader.py
r20fa5fe r2924532 185 185 try: 186 186 message = "Loading {}...\n".format(p_file) 187 self.load_update( output=output,message=message, info="info")187 self.load_update(message=message, info="info") 188 188 temp = self.loader.load(p_file, format) 189 189 if not isinstance(temp, list): … … 201 201 else: 202 202 file_errors[basename] = [error_message] 203 self.load_update(output=output, 204 message=error_message, info="warning") 205 206 self.load_update(output=output, 207 message="Loaded {}\n".format(p_file), 208 info="info") 203 204 self.load_update(message="Loaded {}\n".format(p_file), 205 info="info") 209 206 210 207 except NoKnownLoaderException as e: 211 208 exception_occurred = True 212 logger.error(e.message)213 214 209 error_message = "Loading data failed!\n" + e.message 215 self.load_update(output=None, message=e.message, info="warning") 210 self.load_complete(output=None, 211 message=error_message, 212 info="warning") 216 213 217 214 except Exception as e: 218 215 exception_occurred = True 219 logger.error(e.message)220 221 216 file_err = "The Data file you selected could not be " 222 217 file_err += "loaded.\nMake sure the content of your file" … … 225 220 file_err += " following:\n" 226 221 file_err += e.message 227 file_errors[basename] = [file_err] 222 self.load_complete(output=None, 223 message=file_err, 224 info="error") 228 225 229 226 if len(file_errors) > 0: 230 227 error_message = "" 231 228 for filename, error_array in file_errors.iteritems(): 232 error_message += "The following errors occured whilst "229 error_message += "The following issues were found whilst " 233 230 error_message += "loading {}:\n".format(filename) 234 231 for message in error_array: 235 232 error_message += message + "\n" 236 error_message += "\n" 237 if not exception_occurred: # Some data loaded but with errors 238 self.load_update(output=output, message=error_message, info="error") 239 240 if not exception_occurred: # Everything loaded as expected 233 error_message = error_message[:-1] 234 self.load_complete(output=output, 235 message=error_message, 236 info="error") 237 238 elif not exception_occurred: # Everything loaded as expected 241 239 self.load_complete(output=output, message="Loading data complete!", 242 240 info="info") … … 244 242 self.load_complete(output=None, message=error_message, info="error") 245 243 246 247 def load_update(self, output=None, message="", info="warning"): 244 def load_update(self, message="", info="warning"): 248 245 """ 249 246 print update on the status bar 250 247 """ 251 248 if message != "": 252 wx.PostEvent(self.parent, StatusEvent(status=message, info=info, 249 wx.PostEvent(self.parent, StatusEvent(status=message, 250 info=info, 253 251 type="progress")) 254 252 … … 257 255 post message to status bar and return list of data 258 256 """ 259 wx.PostEvent(self.parent, StatusEvent(status=message, info=info, 257 wx.PostEvent(self.parent, StatusEvent(status=message, 258 info=info, 260 259 type="stop")) 261 260 if output is not None: -
test/sasdataloader/test/utest_generic_file_reader_class.py
rf53d684 r4a8d55c 8 8 import numpy as np 9 9 10 from sas.sascalc.dataloader.data_info import DataInfo, plottable_1D 10 from sas.sascalc.dataloader.data_info import DataInfo, plottable_1D, Data1D 11 from sas.sascalc.dataloader.loader import Loader 12 from sas.sascalc.dataloader.loader_exceptions import NoKnownLoaderException 11 13 from sas.sascalc.dataloader.file_reader_base_class import FileReader 12 14 … … 24 26 self.bad_file = find("ACB123.txt") 25 27 self.good_file = find("123ABC.txt") 28 self.generic_reader = Loader() 29 self.deprecated_file_type = find("FEB18012.ASC") 26 30 27 31 def test_bad_file_path(self): 28 output = self.reader.read(self.bad_file)29 self.assertEqual(output, [])32 self.assertRaises(NoKnownLoaderException, self.reader.read, 33 self.bad_file) 30 34 31 35 def test_good_file_path(self): … … 36 40 self.assertEqual(len(output), 1) 37 41 self.assertEqual(output[0].meta_data["blah"], '123ABC exists!') 42 43 def test_old_file_types(self): 44 f = self.generic_reader.load(self.deprecated_file_type) 45 last_f = f[0] 46 if hasattr(last_f, "errors"): 47 self.assertEquals(len(last_f.errors), 1) 48 else: 49 self.fail("Errors did not propogate to the file properly.") 50 51 def test_same_file_unknown_extensions(self): 52 # Five files, all with the same content, but different file extensions 53 no_ext = find("test_data//TestExtensions") 54 not_xml = find("test_data//TestExtensions.notxml") 55 # Deprecated extensions 56 asc_dep = find("test_data//TestExtensions.asc") 57 nxs_dep = find("test_data//TestExtensions.nxs") 58 # Native extension as a baseline 59 xml_native = find("test_data//TestExtensions.xml") 60 # Load the files and check contents 61 no_ext_load = self.generic_reader.load(no_ext) 62 asc_load = self.generic_reader.load(asc_dep) 63 nxs_load = self.generic_reader.load(nxs_dep) 64 not_xml_load = self.generic_reader.load(not_xml) 65 xml_load = self.generic_reader.load(xml_native) 66 self.check_unknown_extension(no_ext_load[0]) 67 self.check_unknown_extension(asc_load[0]) 68 self.check_unknown_extension(nxs_load[0]) 69 self.check_unknown_extension(not_xml_load[0]) 70 self.check_unknown_extension(xml_load[0]) 71 # Be sure the deprecation warning is passed with the file 72 self.assertEquals(len(asc_load[0].errors), 1) 73 self.assertEquals(len(nxs_load[0].errors), 1) 74 75 def check_unknown_extension(self, data): 76 self.assertTrue(isinstance(data, Data1D)) 77 self.assertEquals(len(data.x), 138) 78 self.assertEquals(data.sample.ID, "TK49 c10_SANS") 79 self.assertEquals(data.meta_data["loader"], "CanSAS XML 1D") 38 80 39 81 def tearDown(self): -
build_tools/requirements.txt
r36ca21e rc16172d 3 3 pylint 4 4 unittest-xml-reporting==1.10.0 5 pyparsing ==1.5.55 pyparsing>=2.0 6 6 html5lib==0.95 7 7 reportlab==2.5 -
setup.py
r1a3602d rc16172d 402 402 403 403 required = [ 404 'bumps>=0.7.5.9', 'periodictable>=1.5.0', 'pyparsing <2.0.0',404 'bumps>=0.7.5.9', 'periodictable>=1.5.0', 'pyparsing>=2.0.0', 405 405 406 406 # 'lxml>=2.2.2',
Note: See TracChangeset
for help on using the changeset viewer.