source: sasview/test/sasdataloader/test/utest_ascii.py @ aa1db44

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since aa1db44 was a78a02f, checked in by krzywon, 7 years ago

Make suggested changes for unit test fixes.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1"""
2    Unit tests for the ascii (n-column) reader
3"""
4import warnings
5warnings.simplefilter("ignore")
6
7import unittest
8from sas.sascalc.dataloader.loader import Loader
9
10
11class ABSReaderTests(unittest.TestCase):
12   
13    def setUp(self):
14        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]
25
26    def test_checkdata(self):
27        """
28            Test .ABS file loaded as ascii
29        """
30        # The length of the data is 10
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.assertTrue(self.f1.x_unit == 'A^{-1}')
35        self.assertTrue(self.f1.y_unit == 'cm^{-1}')
36       
37        self.assertEqual(self.f1.meta_data['loader'],"ASCII")
38
39    def test_truncated_1(self):
40        """
41            Test an ascii file with header and a
42            comment line in the middle of the data section.
43            The business rule says that we should stop
44            reading at the first comment once the data
45            section has started (and treat the comment
46            as though it were the start of a footer).
47        """
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)
52
53    def test_truncated_2(self):
54        """
55            Test a 6-col ascii file with header and a
56            line with only 2 columns in the middle of the data section.
57            The business rule says that we should stop
58            reading at the first inconsitent line.
59        """
60        # The length of the data is 5
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)
64
65    def test_truncated_3(self):
66        """
67            Test a 6-col ascii file with complex header and
68            many lines with 2 or 2 columns in the middle of the data section.
69            The business rule says that we should stop
70            reading at the last line of header.
71        """
72        # The length of the data is 5
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)
76
77    def test_truncated_4(self):
78        """
79            Test mix of 6-col and 2-col.
80            Only the last 5 2-col lines should be read.
81        """
82        # The length of the data is 5
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)
86
87    def test_truncated_5(self):
88        """
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.
92        """
93        # Test .ABS file loaded as ascii
94        f = None
95        try:
96            f = self.loader.load("ascii_test_6.txt")
97        # The length of the data is 5
98        except:
99            self.assertEqual(f, None)
100
101if __name__ == '__main__':
102    unittest.main()
103   
Note: See TracBrowser for help on using the repository browser.