Skip to content

Commit

Permalink
refactor(pdf): use file_path as first arg to PdfDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-awd committed Sep 2, 2024
1 parent 26957b8 commit 6fddf74
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/monopoly/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/monopoly/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 6fddf74

Please sign in to comment.