From bcc5db212cf584f3fae225d6780c173794ad8381 Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 14 Sep 2026 08:57:30 -0300 Subject: [PATCH] fix: accept fixed-width Ourocard issue headers --- ingestion/parsers.py | 9 ++++++++- tests/test_import_parsers.py | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ingestion/parsers.py b/ingestion/parsers.py index 160e7ba..3ae5d57 100644 --- a/ingestion/parsers.py +++ b/ingestion/parsers.py @@ -137,7 +137,14 @@ def _decode_source(data: bytes) -> tuple[str, str]: def _creation_date(line: str) -> date: - match = re.fullmatch(r'DATA\s+DE\s+EMISS(?:A|Ã)O\s*:\s*(\d{2}/\d{2}/\d{4})', line.strip(), re.I) + line = line.strip() + match = re.fullmatch(r'DATA\s+DE\s+EMISS(?:A|Ã)O\s*:\s*(\d{2}/\d{2}/\d{4})', line, re.I) + if match is None: + match = re.fullmatch( + r'(\d{2}/\d{2}/\d{4})\s{2,}[A-ZÀ-ÖØ-öø-ÿ -]+\s{2,}\d{2}:\d{2}:\d{2}', + line, + re.I, + ) if match is None: raise ParseError('INVALID_CREATION_DATE') try: diff --git a/tests/test_import_parsers.py b/tests/test_import_parsers.py index 32d33c1..f3e39ad 100644 --- a/tests/test_import_parsers.py +++ b/tests/test_import_parsers.py @@ -136,6 +136,17 @@ def test_partial_context_uses_the_validated_line_21_creation_date(): } +def test_partial_context_accepts_fixed_width_line_21_creation_date(): + data = ('\n'.join(['SYNTHETIC HEADER'] * 20 + [ + '15/01/2026 SYNTHETIC-STATEMENT 01:02:03' + ]) + '\n').encode() + + assert partial_context_from_creation_line(data) == { + 'start_date': '2025-02-01', + 'end_date': '2026-01-31', + } + + @pytest.mark.parametrize('data,code', [ (b'SYNTHETIC\n' * 20, 'MISSING_CREATION_DATE'), (('\n'.join(['SYNTHETIC HEADER'] * 20 + ['Data de emiss\u00e3o: 15/01/26']) + '\n').encode(), 'INVALID_CREATION_DATE'),