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

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 c09ac449 was af76bd9, checked in by Jae Cho <jhjcho@…>, 16 years ago

changed test values

  • Property mode set to 100644
File size: 2.8 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    def test_truncated_1(self):
28        """
29            Test an ascii file with header and a
30            comment line in the middle of the data section.
31            The business rule says that we should stop
32            reading at the first comment once the data
33            section has started (and treat the comment
34            as though it were the start of a footer).
35        """
36        # Test .ABS file loaded as ascii
37        f = self.loader.load("ascii_test_2.txt")
38        # The length of the data is 10
39        self.assertEqual(len(f.x), 5)
40        self.assertEqual(f.x[0],0.002618)
41        self.assertEqual(f.x[4],0.02356)
42       
43    def test_truncated_2(self):
44        """
45            Test a 6-col ascii file with header and a
46            line with only 2 columns in the middle of the data section.
47            The business rule says that we should stop
48            reading at the first inconsitent line.
49        """
50        # Test .ABS file loaded as ascii
51        f = self.loader.load("ascii_test_3.txt")
52        # The length of the data is 5
53        self.assertEqual(len(f.x), 5)
54        self.assertEqual(f.x[0],0.002618)
55        self.assertEqual(f.x[4],0.02356)
56       
57    def test_truncated_3(self):
58        """
59            Test a 6-col ascii file with complex header and
60            many lines with 2 or 2 columns in the middle of the data section.
61            The business rule says that we should stop
62            reading at the last line of header.
63        """
64        # Test .ABS file loaded as ascii
65        f = self.loader.load("ascii_test_4.abs")
66        # The length of the data is 5
67        self.assertEqual(len(f.x), 5)
68        self.assertEqual(f.x[0],0.012654)
69        self.assertEqual(f.x[4],0.02654)
70       
71    def test_truncated_4(self):
72        """
73            Test mix of 6-col and 2-col.
74            Only the last 5 2-col lines should be read.
75        """
76        # Test .ABS file loaded as ascii
77        f = self.loader.load("ascii_test_5.txt")
78        # The length of the data is 5
79        self.assertEqual(len(f.x), 5)
80        self.assertEqual(f.x[0],0.02879)
81        self.assertEqual(f.x[4],0.0497)
82       
83       
84if __name__ == '__main__':
85    unittest.main()
86   
Note: See TracBrowser for help on using the repository browser.