[7b64d95] | 1 | """ |
---|
| 2 | Unit tests for the ascii (n-column) reader |
---|
| 3 | """ |
---|
| 4 | import warnings |
---|
| 5 | warnings.simplefilter("ignore") |
---|
| 6 | |
---|
| 7 | import unittest |
---|
| 8 | from DataLoader.loader import Loader |
---|
| 9 | |
---|
| 10 | import os.path |
---|
| 11 | |
---|
| 12 | class abs_reader(unittest.TestCase): |
---|
| 13 | |
---|
| 14 | def setUp(self): |
---|
| 15 | self.loader = Loader() |
---|
| 16 | |
---|
| 17 | def test_checkdata(self): |
---|
[7a4401e] | 18 | """ |
---|
| 19 | Test .ABS file loaded as ascii |
---|
| 20 | """ |
---|
[7b64d95] | 21 | f = self.loader.load("ascii_test_1.txt") |
---|
| 22 | # The length of the data is 10 |
---|
| 23 | self.assertEqual(len(f.x), 10) |
---|
[8e09f63] | 24 | self.assertEqual(f.x[0],0.002618) |
---|
| 25 | self.assertEqual(f.x[9],0.0497) |
---|
[7b64d95] | 26 | |
---|
[7a4401e] | 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) |
---|
[8e09f63] | 40 | self.assertEqual(f.x[0],0.002618) |
---|
| 41 | self.assertEqual(f.x[4],0.02356) |
---|
[7a4401e] | 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") |
---|
[3617aa2] | 52 | # The length of the data is 5 |
---|
[7a4401e] | 53 | self.assertEqual(len(f.x), 5) |
---|
[8e09f63] | 54 | self.assertEqual(f.x[0],0.002618) |
---|
| 55 | self.assertEqual(f.x[4],0.02356) |
---|
[7a4401e] | 56 | |
---|
[8adea21] | 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") |
---|
[3617aa2] | 66 | # The length of the data is 5 |
---|
| 67 | self.assertEqual(len(f.x), 5) |
---|
[af76bd9] | 68 | self.assertEqual(f.x[0],0.012654) |
---|
| 69 | self.assertEqual(f.x[4],0.02654) |
---|
[3617aa2] | 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 |
---|
[8adea21] | 79 | self.assertEqual(len(f.x), 5) |
---|
[3617aa2] | 80 | self.assertEqual(f.x[0],0.02879) |
---|
| 81 | self.assertEqual(f.x[4],0.0497) |
---|
[7a4401e] | 82 | |
---|
[7b64d95] | 83 | |
---|
| 84 | if __name__ == '__main__': |
---|
| 85 | unittest.main() |
---|
| 86 | |
---|