source: sasview/DataLoader/test/utest_ascii.py @ b4ad125

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.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since b4ad125 was 5f2d3c78, checked in by Jae Cho <jhjcho@…>, 15 years ago

data line should be composed only with numbers in any of the columns.
Added unittest and testdata

  • Property mode set to 100644
File size: 3.4 KB
Line 
1"""
2    Unit tests for the ascii (n-column) reader
3"""
4import warnings
5warnings.simplefilter("ignore")
6
7import unittest
8from DataLoader.loader import  Loader
9 
10import os.path
11
12class abs_reader(unittest.TestCase):
13   
14    def setUp(self):
15        self.loader = Loader()
16       
17    def test_checkdata(self):
18        """
19            Test .ABS file loaded as ascii
20        """
21        f = self.loader.load("ascii_test_1.txt")
22        # 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       
27        self.assertEqual(f.meta_data['loader'],"ASCII")
28       
29    def test_truncated_1(self):
30        """
31            Test an ascii file with header and a
32            comment line in the middle of the data section.
33            The business rule says that we should stop
34            reading at the first comment once the data
35            section has started (and treat the comment
36            as though it were the start of a footer).
37        """
38        # Test .ABS file loaded as ascii
39        f = self.loader.load("ascii_test_2.txt")
40        # The length of the data is 10
41        self.assertEqual(len(f.x), 5)
42        self.assertEqual(f.x[0],0.002618)
43        self.assertEqual(f.x[4],0.02356)
44       
45    def test_truncated_2(self):
46        """
47            Test a 6-col ascii file with header and a
48            line with only 2 columns in the middle of the data section.
49            The business rule says that we should stop
50            reading at the first inconsitent line.
51        """
52        # Test .ABS file loaded as ascii
53        f = self.loader.load("ascii_test_3.txt")
54        # The length of the data is 5
55        self.assertEqual(len(f.x), 5)
56        self.assertEqual(f.x[0],0.002618)
57        self.assertEqual(f.x[4],0.02356)
58       
59    def test_truncated_3(self):
60        """
61            Test a 6-col ascii file with complex header and
62            many lines with 2 or 2 columns in the middle of the data section.
63            The business rule says that we should stop
64            reading at the last line of header.
65        """
66        # Test .ABS file loaded as ascii
67        f = self.loader.load("ascii_test_4.abs")
68        # The length of the data is 5
69        self.assertEqual(len(f.x), 5)
70        self.assertEqual(f.x[0],0.012654)
71        self.assertEqual(f.x[4],0.02654)
72       
73    def test_truncated_4(self):
74        """
75            Test mix of 6-col and 2-col.
76            Only the last 5 2-col lines should be read.
77        """
78        # Test .ABS file loaded as ascii
79        f = self.loader.load("ascii_test_5.txt")
80        # The length of the data is 5
81        self.assertEqual(len(f.x), 5)
82        self.assertEqual(f.x[0],0.02879)
83        self.assertEqual(f.x[4],0.0497)
84       
85    def test_truncated_5(self):
86        """
87            Test a 6-col ascii file with complex header where one of them has a letter and
88            many lines with 2 or 2 columns in the middle of the data section.
89            Only last four lines should be read.
90        """
91        # Test .ABS file loaded as ascii
92        f = self.loader.load("ascii_test_6.txt")
93        # The length of the data is 5
94        self.assertEqual(len(f.x), 4)
95        self.assertEqual(f.x[0],0.013534)
96        self.assertEqual(f.x[3],0.022254)
97       
98if __name__ == '__main__':
99    unittest.main()
100   
Note: See TracBrowser for help on using the repository browser.