Skip to content

Commit

Permalink
[PEP8]
Browse files Browse the repository at this point in the history
  • Loading branch information
lmignon committed Mar 22, 2015
1 parent b5081cc commit 94c9920
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 14 additions & 10 deletions coda/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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])
Expand All @@ -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 ')
Expand All @@ -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])
Expand All @@ -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]:
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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:
3 changes: 0 additions & 3 deletions coda/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,3 @@ def __init__(self):
self.movements = []
self.informations = []
self.free_comunications = []


# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
26 changes: 16 additions & 10 deletions coda/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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)

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa
import os
import sys
from setuptools import setup, find_packages
Expand Down

0 comments on commit 94c9920

Please sign in to comment.