Skip to content

Commit bf978d0

Browse files
committed
Hard-Testing Importers with fixes and more Tests
1 parent 8abce10 commit bf978d0

6 files changed

Lines changed: 41 additions & 9 deletions

reader/Comdirect.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ def from_pdf(self, filepath):
8282
filepath,
8383
pages="2-end",
8484
flavor="stream",
85-
row_tol=10,
86-
columns=["115,187,305,500"]*16
85+
row_tol=12,
86+
columns=["115,187,305,500"],
87+
table_areas=["0,830,590,0"]
8788
)
8889
#TODO: Hack-araound: https://github.com/atlanhq/camelot/issues/357#issuecomment-520986016
8990

@@ -118,6 +119,7 @@ def from_pdf(self, filepath):
118119
for i, row in enumerated_table:
119120

120121
if re_datecheck.match(row[0]) is None:
122+
print("skip row", row)
121123
continue # Skip Header and unvalid Rows
122124

123125
amount = float(row[4].replace('.', '').replace(',', '.'))

reader/Volksbank_Mittelhessen.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def from_pdf(self, filepath):
8282
pages="all", # End -1
8383
flavor="stream",
8484
table_areas=["60,629,573,51"],
85-
columns=["75,112,440,526"],
85+
columns=["75,115,455"],
8686
split_text=True
8787
)
8888

@@ -103,11 +103,11 @@ def from_pdf(self, filepath):
103103
if row[2].replace(' ', '').lower().startswith('alterkontostand'):
104104
# Last row before transactions
105105
start_index = self.all_rows.index(row) + 1
106-
date_tx_year = row[2][-4:] # Jahr für die Transaktionen merken
107106

108107
if row[2].replace(' ', '').lower().startswith('neuerkontostand'):
109108
# First row after transactions + final line
110109
end_index = self.all_rows.index(row) - 1
110+
date_tx_year = row[2][-4:] # Jahr für die Transaktionen merken
111111
break
112112

113113
if date_tx_year is None or re.match(r'^\d{4}$', date_tx_year) is None:
@@ -125,8 +125,9 @@ def from_pdf(self, filepath):
125125
continue # Skip Header and unvalid Rows
126126

127127
# Positives 'Haben' oder negatives 'Soll'
128-
amount = f'-{row[3]}' if row[3] else row[4]
129-
amount = amount[:-2].replace('.', '').replace(',', '.')
128+
amount_prefix = '' if row[3][-1] == 'H' else '-'
129+
amount = f"{amount_prefix}{re.sub(r'H|S', '', row[3]).strip()}"
130+
amount = amount.replace('.', '').replace(',', '.')
130131

131132
line = {
132133
'date_tx': self._parse_from_strftime(f"{row[0]}{date_tx_year}", "%d.%m.%Y"),

tests/test_unit_reader_Comdirect.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_read_from_csv(test_app):
2828

2929

3030
# Look for test files and create a tuple list
31-
test_folder = os.path.join('/tmp', 'comdirect')
31+
test_folder = os.path.join('/tmp', 'Comdirect')
3232
test_files = []
3333
if not os.path.isdir(test_folder):
3434
test_files = [()]
@@ -48,6 +48,7 @@ def test_read_from_pdf(test_app, full_path):
4848

4949
with test_app.app_context():
5050
transaction_list = Comdirect().from_pdf(full_path)
51+
assert transaction_list, "No transactions found in PDF file"
5152

5253
# Check Reader Ergebnisse
5354
check_transaktion_list(transaction_list)

tests/test_unit_reader_Commerzbank.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_read_from_csv(test_app):
2727

2828

2929
# Look for test files and create a tuple list
30-
test_folder = os.path.join('/tmp', 'commerzbank')
30+
test_folder = os.path.join('/tmp', 'Commerzbank')
3131
test_files = []
3232
if not os.path.isdir(test_folder):
3333
test_files = [()]
@@ -47,6 +47,7 @@ def test_read_from_pdf(test_app, full_path):
4747

4848
with test_app.app_context():
4949
transaction_list = Commerzbank().from_pdf(full_path)
50+
assert transaction_list, "No transactions found in PDF file"
5051

5152
# Check Reader Ergebnisse
5253
check_transaktion_list(transaction_list)

tests/test_unit_reader_Generic.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,29 @@ def test_read_from_pdf():
3636
def test_read_from_http():
3737
"""Testet das Einlesen Kontoumsätzen aus einer Online-Quelle"""
3838
return None
39+
40+
def test_strftime_parser(test_app):
41+
"""Testet den strftime Parser des Generic Readers"""
42+
with test_app.app_context():
43+
reader = Generic()
44+
45+
# Teste verschiedene Datumsformate
46+
date_formats = [
47+
("%d.%m.%Y", "25.12.2023", 1703462400.0),
48+
("%Y-%m-%d", "2023-12-25", 1703462400.0),
49+
("%m/%d/%Y", "12/25/2023", 1703462400.0),
50+
]
51+
52+
for fmt, date_str, expected_timestamp in date_formats:
53+
ts = reader._parse_from_strftime(date_str, fmt) # pylint: disable=protected-access
54+
assert ts == expected_timestamp, f"Failed for format {fmt}"
55+
56+
# Teste automatische Korrektur (31.11. / 30.02. etc.)
57+
date_formats = [
58+
("%d.%m.%Y", "31.11.2023", 1701302400.0), # Korrigiert zu 30.11.2023
59+
("%d.%m.%Y", "30.02.2024", 1709164800.0), # Korrigiert zu 28.02.2024
60+
]
61+
62+
for fmt, date_str, expected_timestamp in date_formats:
63+
ts = reader._parse_from_strftime(date_str, fmt) # pylint: disable=protected-access
64+
assert ts == expected_timestamp, f"Failed for format {fmt}"

tests/test_unit_reader_Volksbank-Mittelhessen.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_read_from_csv(test_app):
2828

2929

3030
# Look for test files and create a tuple list
31-
test_folder = os.path.join('/tmp', 'volksbank-mittelhessen')
31+
test_folder = os.path.join('/tmp', 'Volksbank_Mittelhessen')
3232
test_files = []
3333
if not os.path.isdir(test_folder):
3434
test_files = [()]
@@ -48,6 +48,7 @@ def test_read_from_pdf(test_app, full_path):
4848

4949
with test_app.app_context():
5050
transaction_list = Volksbank_Mittelhessen().from_pdf(full_path)
51+
assert transaction_list, "No transactions found in PDF file"
5152

5253
# Check Reader Ergebnisse
5354
check_transaktion_list(transaction_list)

0 commit comments

Comments
 (0)