diff --git a/.travis.yml b/.travis.yml index 990148d..68b576b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ install: # command to run tests script: - - flake8 . --max-line-length=120 --exclude=__init__.py + - flake8 . --exclude=__init__.py - nosetests -v --with-coverage --cover-tests after_success: diff --git a/coda/parser.py b/coda/parser.py index 5e19c41..20c5a9a 100644 --- a/coda/parser.py +++ b/coda/parser.py @@ -67,10 +67,10 @@ def is_valid_coda(self, value): return re.match(r'0{5}\d{9}05[ D] {7}', value) is not None def parse_file(self, fp): - """ Parse the given file. + """ Parse the given file :param: fp: the path to the file to parse or a valid file-like object :returms: return a list of Statement objects found in the input file - :rtype: list + :rtype: list """ if hasattr(fp, 'read'): return self.parse(fp.read()) @@ -135,7 +135,8 @@ def _parseHeader(self, line, statement): statement.version = version = line[127] if version not in ['1', '2']: raise CodaParserException( - ' R001', 'CODA V%s statements are not supported, please contact your bank' % statement.version) + ' R001', 'CODA V%s statements are not supported, please ' + 'contact your bank' % statement.version) statement.creation_date = time.strftime( self.date_format, time.strptime(rmspaces(line[5:11]), '%d%m%y')) statement.separate_application = rmspaces(line[83:88]) @@ -150,13 +151,15 @@ def _parseHeaderDetails(self, line, statement): statement.currency = rmspaces(line[18:21]) elif line[1] == '1': # foreign bank account BBAN structure raise CodaParserException( - ' R1001', 'Foreign bank accounts with BBAN structure are not supported ') + ' R1001', 'Foreign bank accounts with BBAN structure are ' + 'not supported ') elif line[1] == '2': # Belgian bank account IBAN structure statement.acc_number = rmspaces(line[5:21]) statement.currency = rmspaces(line[39:42]) elif line[1] == '3': # foreign bank account IBAN structure raise CodaParserException( - ' R1002', 'Foreign bank accounts with IBAN structure are not supported ') + ' R1002', 'Foreign bank accounts with IBAN structure are ' + 'not supported ') else: # Something else, not supported raise CodaParserException( ' R1003', 'Unsupported bank account structure ') @@ -182,7 +185,8 @@ def _parseMovementRecord(self, line, statement): record.transaction_amount = float(rmspaces(line[32:47])) / 1000 record.transaction_type = int(line[53]) record.transaction_date = time.strftime( - self.date_format, time.strptime(rmspaces(line[47:53]), '%d%m%y')) + self.date_format, time.strptime( + rmspaces(line[47:53]), '%d%m%y')) record.transaction_family = rmspaces(line[54:56]) record.transaction_code = rmspaces(line[56:58]) record.transaction_category = rmspaces(line[58:61]) @@ -196,7 +200,8 @@ def _parseMovementRecord(self, line, statement): # Non-structured communication record.communication = rmspaces(line[62:115]) record.entry_date = time.strftime( - self.date_format, time.strptime(rmspaces(line[115:121]), '%d%m%y')) + self.date_format, time.strptime( + rmspaces(line[115:121]), '%d%m%y')) record.type = MovementRecordType.NORMAL if record.transaction_type in [1, 2, 3]: @@ -253,7 +258,8 @@ def _parseMovementRecord(self, line, statement): else: # movement data record 2.x (x != 1,2,3) raise CodaParserException( - 'R2006', '\nMovement data records of type 2.%s are not supported ' % line[1]) + 'R2006', '\nMovement data records of type 2.%s are not ' + 'supported ' % line[1]) def _parseInformationRecord(self, line, statement): if line[1] == '1': @@ -307,5 +313,3 @@ def join_communications(c1, c2): def rmspaces(s): return " ".join(s.split()) - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/coda/statement.py b/coda/statement.py index f54cc83..7e15435 100644 --- a/coda/statement.py +++ b/coda/statement.py @@ -122,6 +122,3 @@ def __init__(self): self.movements = [] self.informations = [] self.free_comunications = [] - - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/coda/tests/test_parser.py b/coda/tests/test_parser.py index e9631b8..cafaae1 100644 --- a/coda/tests/test_parser.py +++ b/coda/tests/test_parser.py @@ -61,7 +61,8 @@ def _test_first_statement(self, statement): def test_single_statemet_parsing(self): parser = Parser() - with open(os.path.join(BASEPATH, "Coda_v2_3_single_statement.txt")) as f: + with open(os.path.join(BASEPATH, + "Coda_v2_3_single_statement.txt")) as f: content = f.read() statements = parser.parse(content) assert len(statements) == 1 @@ -71,7 +72,8 @@ def test_single_statemet_parsing(self): def test_multi_statemets_parsing(self): parser = Parser() - with open(os.path.join(BASEPATH, "Coda_v2_3_multi_statements.txt")) as f: + with open(os.path.join(BASEPATH, + "Coda_v2_3_multi_statements.txt")) as f: content = f.read() statements = parser.parse(content) assert len(statements) == 2 @@ -112,11 +114,12 @@ def _checkInformation(self, information): def test_wrong_globalisation(self): """Test wrong globalisation - Check that a globalisation line without the corresponding 'end globalisation' - is considered as Normal + Check that a globalisation line without the corresponding + 'end globalisation' is considered as Normal """ parser = Parser() - with open(os.path.join(BASEPATH, "Coda_v2_3_faulty_globalisation.txt")) as f: + with open(os.path.join(BASEPATH, + "Coda_v2_3_faulty_globalisation.txt")) as f: content = f.read() statements = parser.parse(content) eq_(len(statements), 1) @@ -132,7 +135,8 @@ def test_wrong_globalisation_2(self): is considered as Normal (file contains only globalisation statemnts) """ parser = Parser() - with open(os.path.join(BASEPATH, "Coda_v2_3_faulty_globalisation_2.txt")) as f: + with open(os.path.join(BASEPATH, + "Coda_v2_3_faulty_globalisation_2.txt")) as f: content = f.read() statements = parser.parse(content) eq_(len(statements), 1) @@ -157,7 +161,8 @@ def test_globalisation(self): eq_(mv.type, MovementRecordType.GLOBALISATION) else: eq_(mv.type, MovementRecordType.NORMAL) - with open(os.path.join(BASEPATH, "Coda_v2_3_globalisation_2.txt")) as f: + with open(os.path.join(BASEPATH, + "Coda_v2_3_globalisation_2.txt")) as f: content = f.read() statements = parser.parse(content) assert len(statements) == 1 @@ -173,12 +178,13 @@ def test_unsupported_version(self): with assert_raises(CodaParserException) as cm: parser.parse(content) eq_(cm.exception.code, ' R001') - eq_(cm.exception.msg, 'CODA V5 statements are not supported, please contact your bank') + eq_(cm.exception.msg, + 'CODA V5 statements are not supported, please contact your bank') def test_parse_methods(self): parser = Parser() # test a invalid file name - with assert_raises(ValueError) as cm: + with assert_raises(ValueError): parser.parse_file('invalid_file_name') # test parsing from a path to a file parser = Parser() @@ -188,7 +194,7 @@ def test_parse_methods(self): # test parsing from a file-like object parser = Parser() - with open(os.path.join(file_name)) as f: + with open(os.path.join(file_name)): statements = parser.parse_file(file_name) eq_(len(statements), 1) diff --git a/setup.py b/setup.py index 5607df0..a964218 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ +# flake8: noqa import os import sys from setuptools import setup, find_packages