From 6fddf747aec69335f8ce63d9bc3dc089558c29e8 Mon Sep 17 00:00:00 2001 From: Benjamin Dornel Date: Tue, 3 Sep 2024 00:45:11 +0800 Subject: [PATCH] refactor(pdf): use file_path as first arg to PdfDocument --- src/monopoly/pdf.py | 4 ++-- src/monopoly/pipeline.py | 2 +- tests/integration/test_parser.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/monopoly/pdf.py b/src/monopoly/pdf.py index bca29009..b3025d8f 100644 --- a/src/monopoly/pdf.py +++ b/src/monopoly/pdf.py @@ -66,13 +66,13 @@ class PdfDocument(fitz.Document): def __init__( self, - passwords: Optional[list[SecretStr]] = None, file_path: Optional[Path] = None, file_bytes: Optional[bytes | BytesIO] = None, + passwords: Optional[list[SecretStr]] = None, ): - self.passwords = passwords or PdfPasswords().pdf_passwords self.file_path = file_path self.file_bytes = file_bytes + self.passwords = passwords or PdfPasswords().pdf_passwords args = {"filename": self.file_path, "stream": self.file_bytes} super().__init__(**args) diff --git a/src/monopoly/pipeline.py b/src/monopoly/pipeline.py index 36629aa6..d49fdfde 100644 --- a/src/monopoly/pipeline.py +++ b/src/monopoly/pipeline.py @@ -42,7 +42,7 @@ def __init__( "Only one of `file_path` or `file_bytes` should be passed" ) - document = PdfDocument(passwords, file_bytes=file_bytes, file_path=file_path) + document = PdfDocument(file_path, file_bytes, passwords) bank = bank or self.detect_bank(document) parser = PdfParser(bank, document) self.handler = self.create_handler(bank, parser) diff --git a/tests/integration/test_parser.py b/tests/integration/test_parser.py index 23a50cb6..d563c142 100644 --- a/tests/integration/test_parser.py +++ b/tests/integration/test_parser.py @@ -24,7 +24,7 @@ def test_get_pages_with_no_text(parser: PdfParser): def test_get_pages_invalid_returns_error(parser: PdfParser): - pdf_document = PdfDocument(fixture_directory / "4_pages_blank.pdf") + pdf_document = PdfDocument(file_path=fixture_directory / "4_pages_blank.pdf") parser.document = pdf_document parser.page_range = slice(99, -99)