[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) |
---|
| 24 | |
---|
[7a4401e] | 25 | def test_truncated_1(self): |
---|
| 26 | """ |
---|
| 27 | Test an ascii file with header and a |
---|
| 28 | comment line in the middle of the data section. |
---|
| 29 | The business rule says that we should stop |
---|
| 30 | reading at the first comment once the data |
---|
| 31 | section has started (and treat the comment |
---|
| 32 | as though it were the start of a footer). |
---|
| 33 | """ |
---|
| 34 | # Test .ABS file loaded as ascii |
---|
| 35 | f = self.loader.load("ascii_test_2.txt") |
---|
| 36 | # The length of the data is 10 |
---|
| 37 | self.assertEqual(len(f.x), 5) |
---|
| 38 | |
---|
| 39 | def test_truncated_2(self): |
---|
| 40 | """ |
---|
| 41 | Test a 6-col ascii file with header and a |
---|
| 42 | line with only 2 columns in the middle of the data section. |
---|
| 43 | The business rule says that we should stop |
---|
| 44 | reading at the first inconsitent line. |
---|
| 45 | """ |
---|
| 46 | # Test .ABS file loaded as ascii |
---|
| 47 | f = self.loader.load("ascii_test_3.txt") |
---|
[3617aa2] | 48 | # The length of the data is 5 |
---|
[7a4401e] | 49 | self.assertEqual(len(f.x), 5) |
---|
| 50 | |
---|
[8adea21] | 51 | def test_truncated_3(self): |
---|
| 52 | """ |
---|
| 53 | Test a 6-col ascii file with complex header and |
---|
| 54 | many lines with 2 or 2 columns in the middle of the data section. |
---|
| 55 | The business rule says that we should stop |
---|
| 56 | reading at the last line of header. |
---|
| 57 | """ |
---|
| 58 | # Test .ABS file loaded as ascii |
---|
| 59 | f = self.loader.load("ascii_test_4.abs") |
---|
[3617aa2] | 60 | # The length of the data is 5 |
---|
| 61 | self.assertEqual(len(f.x), 5) |
---|
| 62 | |
---|
| 63 | def test_truncated_4(self): |
---|
| 64 | """ |
---|
| 65 | Test mix of 6-col and 2-col. |
---|
| 66 | Only the last 5 2-col lines should be read. |
---|
| 67 | """ |
---|
| 68 | # Test .ABS file loaded as ascii |
---|
| 69 | f = self.loader.load("ascii_test_5.txt") |
---|
| 70 | # The length of the data is 5 |
---|
[8adea21] | 71 | self.assertEqual(len(f.x), 5) |
---|
[3617aa2] | 72 | self.assertEqual(f.x[0],0.02879) |
---|
| 73 | self.assertEqual(f.x[4],0.0497) |
---|
[7a4401e] | 74 | |
---|
[7b64d95] | 75 | |
---|
| 76 | if __name__ == '__main__': |
---|
| 77 | unittest.main() |
---|
| 78 | |
---|