Changeset 94f074c4 in sasview


Ignore:
Timestamp:
Apr 10, 2018 6:01:14 AM (6 years ago)
Author:
GitHub <noreply@…>
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 06:01:14)
git-committer:
GitHub <noreply@…> (04/10/18 06:01:14)
Message:

Merge pull request #143 from SasView?/ticket-1068-2

Fixes #1068

Files:
6 added
6 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/dataloader/file_reader_base_class.py

    ra58b5a0 r4a8d55c  
    3131FIELDS_2D = ('data', 'qx_data', 'qy_data', 'q_data', 'err_data', 
    3232                 'dqx_data', 'dqy_data', 'mask') 
    33  
     33DEPRECATION_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.") 
    3438 
    3539class FileReader(object): 
     
    4044    # List of allowed extensions 
    4145    ext = ['.txt'] 
     46    # Deprecated extensions 
     47    deprecated_extensions = ['.asc', '.nxs'] 
    4248    # Bypass extension check and try to load anyway 
    4349    allow_all = False 
     
    8793                    if not self.f_open.closed: 
    8894                        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) 
    8998                    if len(self.output) > 0: 
    9099                        # Sort the data that's been loaded 
     
    146155        else: 
    147156            logger.warning(msg) 
     157            raise NoKnownLoaderException(msg) 
    148158 
    149159    def send_to_output(self): 
  • src/sas/sascalc/dataloader/loader.py

    rdc8d1c2 r4a8d55c  
    9090            ascii_loader = ascii_reader.Reader() 
    9191            return ascii_loader.read(path) 
     92        except NoKnownLoaderException: 
     93            pass  # Try the Cansas XML reader 
    9294        except DefaultReaderException: 
    9395            pass  # Loader specific error to try the cansas XML reader 
     
    100102            cansas_loader = cansas_reader.Reader() 
    101103            return cansas_loader.read(path) 
     104        except NoKnownLoaderException: 
     105            pass  # Try the NXcanSAS reader 
    102106        except DefaultReaderException: 
    103107            pass  # Loader specific error to try the NXcanSAS reader 
  • src/sas/sasgui/guiframe/local_perspectives/data_loader/data_loader.py

    r20fa5fe r2924532  
    185185            try: 
    186186                message = "Loading {}...\n".format(p_file) 
    187                 self.load_update(output=output, message=message, info="info") 
     187                self.load_update(message=message, info="info") 
    188188                temp = self.loader.load(p_file, format) 
    189189                if not isinstance(temp, list): 
     
    201201                        else: 
    202202                            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") 
    209206 
    210207            except NoKnownLoaderException as e: 
    211208                exception_occurred = True 
    212                 logger.error(e.message) 
    213  
    214209                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") 
    216213 
    217214            except Exception as e: 
    218215                exception_occurred = True 
    219                 logger.error(e.message) 
    220  
    221216                file_err = "The Data file you selected could not be " 
    222217                file_err += "loaded.\nMake sure the content of your file" 
     
    225220                file_err += " following:\n" 
    226221                file_err += e.message 
    227                 file_errors[basename] = [file_err] 
     222                self.load_complete(output=None, 
     223                                   message=file_err, 
     224                                   info="error") 
    228225 
    229226        if len(file_errors) > 0: 
    230227            error_message = "" 
    231228            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 " 
    233230                error_message += "loading {}:\n".format(filename) 
    234231                for message in error_array: 
    235232                    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 
    241239            self.load_complete(output=output, message="Loading data complete!", 
    242240                               info="info") 
     
    244242            self.load_complete(output=None, message=error_message, info="error") 
    245243 
    246  
    247     def load_update(self, output=None, message="", info="warning"): 
     244    def load_update(self, message="", info="warning"): 
    248245        """ 
    249246        print update on the status bar 
    250247        """ 
    251248        if message != "": 
    252             wx.PostEvent(self.parent, StatusEvent(status=message, info=info, 
     249            wx.PostEvent(self.parent, StatusEvent(status=message, 
     250                                                  info=info, 
    253251                                                  type="progress")) 
    254252 
     
    257255         post message to status bar and return list of data 
    258256        """ 
    259         wx.PostEvent(self.parent, StatusEvent(status=message, info=info, 
     257        wx.PostEvent(self.parent, StatusEvent(status=message, 
     258                                              info=info, 
    260259                                              type="stop")) 
    261260        if output is not None: 
  • test/sasdataloader/test/utest_generic_file_reader_class.py

    rf53d684 r4a8d55c  
    88import numpy as np 
    99 
    10 from sas.sascalc.dataloader.data_info import DataInfo, plottable_1D 
     10from sas.sascalc.dataloader.data_info import DataInfo, plottable_1D, Data1D 
     11from sas.sascalc.dataloader.loader import Loader 
     12from sas.sascalc.dataloader.loader_exceptions import NoKnownLoaderException 
    1113from sas.sascalc.dataloader.file_reader_base_class import FileReader 
    1214 
     
    2426        self.bad_file = find("ACB123.txt") 
    2527        self.good_file = find("123ABC.txt") 
     28        self.generic_reader = Loader() 
     29        self.deprecated_file_type = find("FEB18012.ASC") 
    2630 
    2731    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) 
    3034 
    3135    def test_good_file_path(self): 
     
    3640        self.assertEqual(len(output), 1) 
    3741        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") 
    3880 
    3981    def tearDown(self): 
  • build_tools/requirements.txt

    r36ca21e rc16172d  
    33pylint 
    44unittest-xml-reporting==1.10.0 
    5 pyparsing==1.5.5 
     5pyparsing>=2.0 
    66html5lib==0.95 
    77reportlab==2.5 
  • setup.py

    r1a3602d rc16172d  
    402402 
    403403required = [ 
    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', 
    405405 
    406406    # 'lxml>=2.2.2', 
Note: See TracChangeset for help on using the changeset viewer.