Changeset 3648cbf in sasview


Ignore:
Timestamp:
Oct 25, 2017 10:58:11 AM (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, ticket885, unittest-saveload
Children:
1576693
Parents:
fe15198
Message:

FIx failing unit tests on file reader base class.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/sasdataloader/test/utest_generic_file_reader_class.py

    rbeba407 r3648cbf  
    1717 
    1818    def setUp(self): 
    19         self.reader = FileReader() 
     19        self.reader = TestFileReader() 
    2020        self.bad_file = "ACB123.txt" 
    2121        self.good_file = "123ABC.txt" 
    22         self.msg = "Unable to find file at: {}\n".format(self.bad_file) 
    23         self.msg += "Please check your file path and try again." 
    24         x = np.zeros(0) 
    25         y = np.zeros(0) 
    26         self.reader.current_dataset = plottable_1D(x, y) 
    27         self.reader.current_datainfo = DataInfo() 
    28         self.reader.send_to_output() 
    2922 
    3023    def test_bad_file_path(self): 
    3124        output = self.reader.read(self.bad_file) 
    32         self.assertEqual(len(output[0].errors), 1) 
    33         self.assertEqual(output[0].errors[0], self.msg) 
     25        self.assertEqual(output, []) 
    3426 
    3527    def test_good_file_path(self): 
    36         f_open = open(self.good_file, 'w') 
    37         f_open.close() 
     28        f = open(self.good_file, 'w') 
     29        f.write('123ABC exists!') 
     30        f.close() 
    3831        output = self.reader.read(self.good_file) 
    39         self.assertEqual(len(output[0].errors), 1) 
    40         self.assertEqual(output[0].errors[0], self.msg) 
     32        self.assertEqual(len(output), 1) 
     33        self.assertEqual(output[0].meta_data["blah"], '123ABC exists!') 
    4134 
    4235    def tearDown(self): 
     
    4538        if os.path.isfile(self.good_file): 
    4639            os.remove(self.good_file) 
     40 
     41class TestFileReader(FileReader): 
     42    def get_file_contents(self): 
     43        """ 
     44        Reader specific class to access the contents of the file 
     45        All reader classes that inherit from FileReader must implement 
     46        """ 
     47        x = np.zeros(0) 
     48        y = np.zeros(0) 
     49        self.current_dataset = plottable_1D(x,y) 
     50        self.current_datainfo = DataInfo() 
     51        self.current_datainfo.meta_data["blah"] = self.nextline() 
     52        self.send_to_output() 
Note: See TracChangeset for help on using the changeset viewer.