source: sasview/test/sasdataloader/test/utest_generic_file_reader_class.py @ beba407

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

Start of a base file loading class and a couple unit tests for it.

  • Property mode set to 100644
File size: 1.4 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 = FileReader()
20        self.bad_file = "ACB123.txt"
21        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()
29
30    def test_bad_file_path(self):
31        output = self.reader.read(self.bad_file)
32        self.assertEqual(len(output[0].errors), 1)
33        self.assertEqual(output[0].errors[0], self.msg)
34
35    def test_good_file_path(self):
36        f_open = open(self.good_file, 'w')
37        f_open.close()
38        output = self.reader.read(self.good_file)
39        self.assertEqual(len(output[0].errors), 1)
40        self.assertEqual(output[0].errors[0], self.msg)
41
42    def tearDown(self):
43        if os.path.isfile(self.bad_file):
44            os.remove(self.bad_file)
45        if os.path.isfile(self.good_file):
46            os.remove(self.good_file)
Note: See TracBrowser for help on using the repository browser.