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:
2026-07-17 17:34:39 +02:00
parent d91bb2e331
commit 78d94a583b
2 changed files with 14 additions and 3 deletions

View File

@@ -29,7 +29,7 @@ class ParsedStatement:
def parse_german_amount(s: str) -> Decimal:
s = s.strip().replace(" ", "").replace(" ", "")
s = s.strip().replace(" ", "").replace("\xa0", "")
neg = s.endswith("-") or s.startswith("-") or s.endswith("S")
s = s.strip("+-SH")
value = Decimal(s.replace(".", "").replace(",", "."))
@@ -43,4 +43,7 @@ def parse_german_date(s: str, default_year: int | None = None) -> date:
year = int(m.group(3)) if m.group(3) else default_year
if year is None:
raise ParserError(f"Jahr fehlt: {s!r}")
return date(year, int(m.group(2)), int(m.group(1)))
try:
return date(year, int(m.group(2)), int(m.group(1)))
except ValueError:
raise ParserError(f"Ungültiges Datum: {s!r}")