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

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 b1a65b6 was adbb821, checked in by Mathieu Doucet <doucetm@…>, 15 years ago

DataLoader?: modify unit tests to reflect the changes to nsxunit (conversions that were wrong have been corrected)

  • 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 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        self.assertEqual(f.x_unit, '1/A')
27        self.assertEqual(f.y_unit, '1/cm')
28       
29        self.assertEqual(f.meta_data['loader'],"ASCII")
30       
31    def test_truncated_1(self):
32        """
33            Test an ascii file with header and a
34            comment line in the middle of the data section.
35            The business rule says that we should stop
36            reading at the first comment once the data
37            section has started (and treat the comment
38            as though it were the start of a footer).
39        """
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)
46       
47    def test_truncated_2(self):
48        """
49            Test a 6-col ascii file with header and a
50            line with only 2 columns in the middle of the data section.
51            The business rule says that we should stop
52            reading at the first inconsitent line.
53        """
54        # Test .ABS file loaded as ascii
55        f = self.loader.load("ascii_test_3.txt")
56        # 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)
60       
61    def test_truncated_3(self):
62        """
63            Test a 6-col ascii file with complex header and
64            many lines with 2 or 2 columns in the middle of the data section.
65            The business rule says that we should stop
66            reading at the last line of header.
67        """
68        # Test .ABS file loaded as ascii
69        f = self.loader.load("ascii_test_4.abs")
70        # 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)
74       
75    def test_truncated_4(self):
76        """
77            Test mix of 6-col and 2-col.
78            Only the last 5 2-col lines should be read.
79        """
80        # Test .ABS file loaded as ascii
81        f = self.loader.load("ascii_test_5.txt")
82        # 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)
86       
87    def test_truncated_5(self):
88        """
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.
92        """
93        # Test .ABS file loaded as ascii
94        f = self.loader.load("ascii_test_6.txt")
95        # The length of the data is 5
96        self.assertEqual(len(f.x), 4)
97        self.assertEqual(f.x[0],0.013534)
98        self.assertEqual(f.x[3],0.022254)
99       
100if __name__ == '__main__':
101    unittest.main()
102   
Note: See TracBrowser for help on using the repository browser.