source: sasview/test/sasdataloader/test/utest_generic_file_reader_class.py @ 3648cbf

magnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 3648cbf was 3648cbf, checked in by krzywon, 6 years ago

FIx failing unit tests on file reader base class.

  • Property mode set to 100644
File size: 1.5 KB
Line 
1"""
2    Unit tests for the generic file reader class
3"""
4
5import os
6import unittest
7import logging
8import numpy as np
9
10from sas.sascalc.dataloader.data_info import DataInfo, plottable_1D
11from sas.sascalc.dataloader.file_reader_base_class import FileReader
12
13logger = logging.getLogger(__name__)
14
15
16class GenericFileReaderTests(unittest.TestCase):
17
18    def setUp(self):
19        self.reader = TestFileReader()
20        self.bad_file = "ACB123.txt"
21        self.good_file = "123ABC.txt"
22
23    def test_bad_file_path(self):
24        output = self.reader.read(self.bad_file)
25        self.assertEqual(output, [])
26
27    def test_good_file_path(self):
28        f = open(self.good_file, 'w')
29        f.write('123ABC exists!')
30        f.close()
31        output = self.reader.read(self.good_file)
32        self.assertEqual(len(output), 1)
33        self.assertEqual(output[0].meta_data["blah"], '123ABC exists!')
34
35    def tearDown(self):
36        if os.path.isfile(self.bad_file):
37            os.remove(self.bad_file)
38        if os.path.isfile(self.good_file):
39            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 TracBrowser for help on using the repository browser.