Ignore:
Timestamp:
Apr 17, 2017 12:39:50 PM (7 years ago)
Author:
krzywon
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
8ffafd1
Parents:
beba407
git-author:
Jeff Krzywon <krzywon@…> (04/17/17 12:39:50)
git-committer:
krzywon <krzywon@…> (04/17/17 12:39:50)
Message:

Refactor ASCII reader to use FileReader? class.

File:
1 edited

Legend:

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

    r959eb01 rb09095a  
    66 
    77import unittest 
    8 from sas.sascalc.dataloader.loader import  Loader 
    9   
    10 import os.path 
     8from sas.sascalc.dataloader.loader import Loader 
    119 
    12 class abs_reader(unittest.TestCase): 
     10 
     11class ABSReaderTests(unittest.TestCase): 
    1312     
    1413    def setUp(self): 
    1514        self.loader = Loader() 
     15        self.f1_list = self.loader.load("ascii_test_1.txt") 
     16        self.f1 = self.f1_list[0] 
     17        self.f2_list = self.loader.load("ascii_test_2.txt") 
     18        self.f2 = self.f2_list[0] 
     19        self.f3_list = self.loader.load("ascii_test_3.txt") 
     20        self.f3 = self.f3_list[0] 
     21        self.f4_list = self.loader.load("ascii_test_4.abs") 
     22        self.f4 = self.f4_list[0] 
     23        self.f5_list = self.loader.load("ascii_test_5.txt") 
     24        self.f5 = self.f5_list[0] 
    1625         
    1726    def test_checkdata(self): 
     
    1928            Test .ABS file loaded as ascii 
    2029        """ 
    21         f = self.loader.load("ascii_test_1.txt") 
    2230        # The length of the data is 10 
    23         self.assertEqual(len(f.x), 10) 
    24         self.assertEqual(f.x[0],0.002618) 
    25         self.assertEqual(f.x[9],0.0497) 
    26         self.assertEqual(f.x_unit, '1/A') 
    27         self.assertEqual(f.y_unit, '1/cm') 
     31        self.assertEqual(len(self.f1.x), 10) 
     32        self.assertEqual(self.f1.x[0],0.002618) 
     33        self.assertEqual(self.f1.x[9],0.0497) 
     34        self.assertEqual(self.f1.x_unit, '1/A') 
     35        self.assertEqual(self.f1.y_unit, '1/cm') 
    2836         
    29         self.assertEqual(f.meta_data['loader'],"ASCII") 
     37        self.assertEqual(self.f1.meta_data['loader'],"ASCII") 
    3038         
    3139    def test_truncated_1(self): 
     
    3846            as though it were the start of a footer). 
    3947        """ 
    40         # Test .ABS file loaded as ascii 
    41         f = self.loader.load("ascii_test_2.txt") 
    42         # The length of the data is 10 
    43         self.assertEqual(len(f.x), 5) 
    44         self.assertEqual(f.x[0],0.002618) 
    45         self.assertEqual(f.x[4],0.02356) 
     48        # The length of the data is 5 
     49        self.assertEqual(len(self.f2.x), 5) 
     50        self.assertEqual(self.f2.x[0],0.002618) 
     51        self.assertEqual(self.f2.x[4],0.02356) 
    4652         
    4753    def test_truncated_2(self): 
     
    5258            reading at the first inconsitent line. 
    5359        """ 
    54         # Test .ABS file loaded as ascii 
    55         f = self.loader.load("ascii_test_3.txt") 
    5660        # The length of the data is 5 
    57         self.assertEqual(len(f.x), 5) 
    58         self.assertEqual(f.x[0],0.002618) 
    59         self.assertEqual(f.x[4],0.02356) 
     61        self.assertEqual(len(self.f3.x), 5) 
     62        self.assertEqual(self.f3.x[0],0.002618) 
     63        self.assertEqual(self.f3.x[4],0.02356) 
    6064         
    6165    def test_truncated_3(self): 
     
    6670            reading at the last line of header. 
    6771        """ 
    68         # Test .ABS file loaded as ascii 
    69         f = self.loader.load("ascii_test_4.abs") 
    7072        # The length of the data is 5 
    71         self.assertEqual(len(f.x), 5) 
    72         self.assertEqual(f.x[0],0.012654) 
    73         self.assertEqual(f.x[4],0.02654) 
     73        self.assertEqual(len(self.f4.x), 5) 
     74        self.assertEqual(self.f4.x[0],0.012654) 
     75        self.assertEqual(self.f4.x[4],0.02654) 
    7476         
    7577    def test_truncated_4(self): 
     
    7880            Only the last 5 2-col lines should be read. 
    7981        """ 
    80         # Test .ABS file loaded as ascii 
    81         f = self.loader.load("ascii_test_5.txt") 
    8282        # The length of the data is 5 
    83         self.assertEqual(len(f.x), 5) 
    84         self.assertEqual(f.x[0],0.02879) 
    85         self.assertEqual(f.x[4],0.0497) 
     83        self.assertEqual(len(self.f5.x), 5) 
     84        self.assertEqual(self.f5.x[0],0.02879) 
     85        self.assertEqual(self.f5.x[4],0.0497) 
    8686         
    8787    def test_truncated_5(self): 
    8888        """ 
    89             Test a 6-col ascii file with complex header where one of them has a letter and  
    90             many lines with 2 or 2 columns in the middle of the data section. 
    91             Only last four lines should be read. 
     89            Test a 6-col ascii file with complex header where one of them has a 
     90            letter and many lines with 2 or 2 columns in the middle of the data 
     91            section. Will be rejected because fewer than 5 lines. 
    9292        """ 
    9393        # Test .ABS file loaded as ascii 
Note: See TracChangeset for help on using the changeset viewer.