Changeset 4a8d55c in sasview


Ignore:
Timestamp:
Mar 27, 2018 12:05:36 PM (7 years ago)
Author:
krzywon
Branches:
master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, unittest-saveload
Children:
63ddc03
Parents:
2924532
Message:

Propagate through loader when errors are thrown regardless of the error. Add tests using the same file with different extensions (including deprecated extensions).

Files:
5 added
3 edited

Legend:

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

    r2924532 r4a8d55c  
    3434                       "t not be fully reduced. Support for the reader associat" 
    3535                       "ed with this file type has been removed. An attempt to " 
    36                        "load the file was made, however, even if a data set was" 
    37                        " generated, SasView cannot guarantee the accuracy of th" 
    38                        "e data.") 
     36                       "load the file was made, but, should it be successful, " 
     37                       "SasView cannot guarantee the accuracy of the data.") 
    3938 
    4039class FileReader(object): 
  • 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 
  • test/sasdataloader/test/utest_generic_file_reader_class.py

    r425feff 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 
    1111from sas.sascalc.dataloader.loader import Loader 
    1212from sas.sascalc.dataloader.loader_exceptions import NoKnownLoaderException 
     
    4949            self.fail("Errors did not propogate to the file properly.") 
    5050 
     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") 
     80 
    5181    def tearDown(self): 
    5282        if os.path.isfile(self.bad_file): 
Note: See TracChangeset for help on using the changeset viewer.