Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pdfparser/pdfoxide_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def parse_pdf_pdfoxide(path: str) -> Dict[str, Any]:
# Extract transactions from all pages
all_text = ""
for page_num in range(page_count):
page_text = doc.extract_text(page_num) # type: ignore[attr-defined] or ""
page_text = doc.extract_text(page_num) or "" # type: ignore[attr-defined]
all_text += page_text + "\n"
transactions = extract_transactions(all_text)

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ tabulate>=0.9.0 # For formatted benchmark tables

# Configuration management
python-dotenv>=1.0.0 # Environment variable management, Python 3.9 compatible
pdf-oxide>=0.2.2
42 changes: 42 additions & 0 deletions tests/test_pdfoxide_edge_cases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import pytest
from unittest.mock import MagicMock, patch
from pdfparser.pdfoxide_parser import parse_pdf_pdfoxide

class TestPdfOxideEdgeCases:
@patch('pdfparser.pdfoxide_parser.PdfDocument')
def test_extract_text_returns_none(self, mock_pdf_document_cls, tmp_path):
"""
Regression test for bug where extract_text returning None caused TypeError.
"""
# Create a dummy file so validation passes
pdf_path = tmp_path / "dummy.pdf"
pdf_path.touch()

# Setup mock instance
mock_doc = MagicMock()
mock_pdf_document_cls.return_value = mock_doc

# Mock page_count
mock_doc.page_count.return_value = 2

# Mock extract_text to return None for the second page (index 1)
# First page (index 0) returns "metadata"
# The parser calls extract_text(0) for metadata, and then loops all pages for transactions
def side_effect(page_num):
if page_num == 0:
return "No. Rekening\nAccount No\n:\n123456\nStatement Date\n:\n01/01/2023"
return None

mock_doc.extract_text.side_effect = side_effect

# Call parser
result = parse_pdf_pdfoxide(str(pdf_path))

# Verify result structure
assert result['metadata']['account_no'] == '123456'
# Transactions might be empty as we didn't provide transaction text
assert isinstance(result['transactions'], list)

# Verify full_text handling
# It should contain the text from page 0 and a newline for page 1
assert "123456" in result['full_text']