fix: NBSP-Betraege und ParserError bei ungueltigem Datum
- parse_german_amount: Fix non-breaking space (U+00A0) handling in second replace call
was: .replace(" ", "").replace(" ", "") → now: .replace(" ", "").replace("\xa0", "")
- parse_german_date: Catch ValueError from invalid calendar dates (e.g., 31.02.2026)
and raise ParserError with "Ungültiges Datum" message instead
- Add test for non-breaking space amount parsing
- Add test for invalid date error handling with pytest.raises
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
|
||||
from app.parsers.base import (ParsedStatement, ParsedTransaction,
|
||||
import pytest
|
||||
|
||||
from app.parsers.base import (ParsedStatement, ParsedTransaction, ParserError,
|
||||
parse_german_amount, parse_german_date)
|
||||
from app.parsers.detect import detect_bank
|
||||
from app.parsers.validate import balance_difference, dedup_hash
|
||||
@@ -12,6 +14,7 @@ def test_parse_german_amount():
|
||||
assert parse_german_amount("1.234,56-") == Decimal("-1234.56")
|
||||
assert parse_german_amount("12,00 S") == Decimal("-12.00")
|
||||
assert parse_german_amount("12,00 H") == Decimal("12.00")
|
||||
assert parse_german_amount("1\xa0234,56") == Decimal("1234.56")
|
||||
|
||||
|
||||
def test_parse_german_date():
|
||||
@@ -19,6 +22,11 @@ def test_parse_german_date():
|
||||
assert parse_german_date("03.06.", default_year=2026) == date(2026, 6, 3)
|
||||
|
||||
|
||||
def test_parse_german_date_invalid():
|
||||
with pytest.raises(ParserError):
|
||||
parse_german_date("31.02.2026")
|
||||
|
||||
|
||||
def test_detect_bank():
|
||||
assert detect_bank("... Volksbank Musterstadt eG ...") == "vr"
|
||||
assert detect_bank("... Raiffeisenbank ...") == "vr"
|
||||
|
||||
Reference in New Issue
Block a user