[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") |
---|
| 48 | # The length of the data is 10 |
---|
| 49 | self.assertEqual(len(f.x), 5) |
---|
| 50 | |
---|
| 51 | |
---|
[7b64d95] | 52 | |
---|
| 53 | if __name__ == '__main__': |
---|
| 54 | unittest.main() |
---|
| 55 | |
---|