File: test_maxibps.py

package info (click to toggle)
ofxstatement-plugins 20181208
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,064 kB
  • sloc: python: 7,004; xml: 1,027; makefile: 135; sh: 84
file content (46 lines) | stat: -rw-r--r-- 1,577 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import unittest
import glob
import os.path
from ofxstatement.plugins.maxibps import PSTextFormatParser


class TestParser(unittest.TestCase):
    pass


def test_generator(test_file_name):
    def test_parser(self):
        with open(test_file_name, "U", encoding="utf-8-sig") as test_file:
            parser = PSTextFormatParser(test_file)
            records = parser.split_records()
            self.assertGreater(len(records), 0,
                               "split input into records\nrecords = %s"
                               % records)

    def test_parseLine(self):
        with open(test_file_name, "U", encoding="utf-8-sig") as test_file:
            parser = PSTextFormatParser(test_file)
            for rec_str in parser.split_records():
                rec = parser.parse_record(rec_str)
                self.assertIsNotNone(rec, "StatementLine created")

    return test_parser, test_parseLine


def additional_tests():
    suite = unittest.TestSuite()
    test_samples_dir = os.path.join(
        os.path.dirname(os.path.realpath(__file__)), "samples")
    tests = glob.glob(os.path.join(test_samples_dir, '*.txt'))
    for t in tests:
        test_base = os.path.splitext(os.path.split(t)[1])[0]
        test_core = 'test_%s' % test_base
        tests = test_generator(t)
        for test in zip(['parser', 'parseLine'], tests):
            test_name = "{}_{}".format(test_core, test[0])
            setattr(TestParser, test_name, test[1])
            suite.addTest(TestParser(test_name))
    return suite

if __name__ == '__main__':
    unittest.main()