Skip to content

Commit 8abce10

Browse files
committed
Datefunktionen und Testschleife übernommen
1 parent 8d11b55 commit 8abce10

4 files changed

Lines changed: 41 additions & 29 deletions

File tree

reader/Comdirect.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,8 @@ def from_csv(self, filepath):
4242
continue
4343

4444
amount = float(row['Umsatz in EUR'].replace(',', '.'))
45-
date_tx = datetime.datetime.strptime(
46-
date_tx, date_format
47-
).replace(tzinfo=datetime.timezone.utc).timestamp()
48-
valuta = datetime.datetime.strptime(
49-
row['Wertstellung (Valuta)'], date_format
50-
).replace(tzinfo=datetime.timezone.utc).timestamp()
45+
date_tx = self._parse_from_strftime(date_tx, date_format)
46+
valuta = self._parse_from_strftime(row['Wertstellung (Valuta)'], date_format)
5147

5248
text_tx = row['Buchungstext']
5349
match = rx.match(text_tx)

reader/Volksbank_Mittelhessen.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ def from_pdf(self, filepath):
8383
flavor="stream",
8484
table_areas=["60,629,573,51"],
8585
columns=["75,112,440,526"],
86-
split_text=True,
87-
#layout_kwargs={ # übernommen von Commerzbank, da ähnliches Layout
88-
# "char_margin": 2,
89-
# "word_margin": 0.5,
90-
#},
86+
split_text=True
9187
)
9288

9389
# Tabellen aller Seiten zusammenfügen
@@ -133,12 +129,8 @@ def from_pdf(self, filepath):
133129
amount = amount[:-2].replace('.', '').replace(',', '.')
134130

135131
line = {
136-
'date_tx': datetime.datetime.strptime(
137-
f"{row[0]}{date_tx_year}", "%d.%m.%Y"
138-
).replace(tzinfo=datetime.timezone.utc).timestamp(),
139-
'valuta': datetime.datetime.strptime(
140-
f"{row[1]}{date_tx_year}", "%d.%m.%Y"
141-
).replace(tzinfo=datetime.timezone.utc).timestamp(),
132+
'date_tx': self._parse_from_strftime(f"{row[0]}{date_tx_year}", "%d.%m.%Y"),
133+
'valuta': self._parse_from_strftime(f"{row[1]}{date_tx_year}", "%d.%m.%Y"),
142134
'art': row[2],
143135
'text_tx': "",
144136
'amount': float(amount),

tests/test_unit_reader_Comdirect.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,27 @@ def test_read_from_csv(test_app):
2727
check_transaktion_list(transaction_list)
2828

2929

30-
def test_read_from_pdf(test_app):
30+
# Look for test files and create a tuple list
31+
test_folder = os.path.join('/tmp', 'comdirect')
32+
test_files = []
33+
if not os.path.isdir(test_folder):
34+
test_files = [()]
35+
else:
36+
for file in os.listdir(test_folder):
37+
test_files.append(
38+
(os.path.join(test_folder, file))
39+
)
40+
41+
# Using every test file in its own test
42+
@pytest.mark.parametrize("full_path", test_files)
43+
def test_read_from_pdf(test_app, full_path):
3144
"""Testet das Einlesen einer PDF Datei mit Kontoumsätzen"""
32-
test_file_pdf = os.path.join('/tmp', 'comdirect.pdf')
33-
if not os.path.isfile(test_file_pdf):
34-
# Test file not provided (sensitive data is not part of git repo)
35-
pytest.skip("Testfile /tmp/comdirect.pdf not found....skipping")
45+
if not full_path:
46+
# Test files not provided (sensitive data is not part of git repo)
47+
pytest.skip("Testfile not provided....skipping")
3648

3749
with test_app.app_context():
38-
transaction_list = Comdirect().from_pdf(test_file_pdf)
50+
transaction_list = Comdirect().from_pdf(full_path)
3951

4052
# Check Reader Ergebnisse
4153
check_transaktion_list(transaction_list)

tests/test_unit_reader_Volksbank-Mittelhessen.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,27 @@ def test_read_from_csv(test_app):
2727
check_transaktion_list(transaction_list)
2828

2929

30-
def test_read_from_pdf(test_app):
30+
# Look for test files and create a tuple list
31+
test_folder = os.path.join('/tmp', 'volksbank-mittelhessen')
32+
test_files = []
33+
if not os.path.isdir(test_folder):
34+
test_files = [()]
35+
else:
36+
for file in os.listdir(test_folder):
37+
test_files.append(
38+
(os.path.join(test_folder, file))
39+
)
40+
41+
# Using every test file in its own test
42+
@pytest.mark.parametrize("full_path", test_files)
43+
def test_read_from_pdf(test_app, full_path):
3144
"""Testet das Einlesen einer PDF Datei mit Kontoumsätzen"""
32-
test_file_pdf = os.path.join('/tmp', 'volksbank-mittelhessen.pdf')
33-
if not os.path.isfile(test_file_pdf):
34-
# Test file not provided (sensitive data is not part of git repo)
35-
pytest.skip("Testfile /tmp/volksbank-mittelhessen.pdf not found....skipping")
45+
if not full_path:
46+
# Test files not provided (sensitive data is not part of git repo)
47+
pytest.skip("Testfile not provided....skipping")
3648

3749
with test_app.app_context():
38-
transaction_list = Volksbank_Mittelhessen().from_pdf(test_file_pdf)
50+
transaction_list = Volksbank_Mittelhessen().from_pdf(full_path)
3951

4052
# Check Reader Ergebnisse
4153
check_transaktion_list(transaction_list)

0 commit comments

Comments
 (0)