Skip to content

Commit bc90c5d

Browse files
authored
Test markitdown-ocr in CI against the sibling markitdown (#2378)
* Test markitdown-ocr in CI against the sibling markitdown * Run the full matrix.
1 parent 2dffd8b commit bc90c5d

4 files changed

Lines changed: 56 additions & 11 deletions

File tree

.github/workflows/tests.yml

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,45 @@
11
name: tests
22
on: [pull_request]
3+
permissions:
4+
contents: read
35

46
jobs:
57
tests:
68
runs-on: ubuntu-latest
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
python-version: ["3.10", "3.11", "3.12", "3.13"]
13+
714
steps:
815
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
916
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
1017
with:
11-
python-version: |
12-
3.10
13-
3.11
14-
3.12
18+
python-version: ${{ matrix.python-version }}
19+
1520
- name: Install Hatch
1621
run: pipx install hatch
1722
- name: Run tests
1823
run: cd packages/markitdown; hatch test
24+
25+
ocr-tests:
26+
runs-on: ubuntu-latest
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
python-version: ["3.10", "3.11", "3.12", "3.13"]
31+
32+
steps:
33+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
34+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
35+
with:
36+
python-version: ${{ matrix.python-version }}
37+
38+
# Install markitdown from the local checkout rather than PyPI, so the
39+
# plugin is tested against the sibling package it ships alongside.
40+
- name: Install packages
41+
run: pip install ./packages/markitdown ./packages/markitdown-ocr pytest
42+
43+
- name: Run tests
44+
working-directory: packages/markitdown-ocr
45+
run: pytest

packages/markitdown-ocr/tests/test_pdf_converter.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,30 @@ def test_pdf_complex_layout(svc: MockOCRService) -> None:
144144

145145

146146
# ---------------------------------------------------------------------------
147-
# pdf_multipage.pdf — pdfplumber/pdfminer fail (EOF); PyMuPDF fallback used
147+
# pdf_multipage.pdf
148148
# ---------------------------------------------------------------------------
149149

150150

151151
def test_pdf_multipage(svc: MockOCRService) -> None:
152-
# pdfplumber cannot open this file (Unexpected EOF), so _ocr_full_pages
153-
# falls back to PyMuPDF for page rendering. Each page becomes one OCR block.
154152
expected = (
155-
f"## Page 1\n\n\n{_OCR_BLOCK}\n\n\n"
156-
f"## Page 2\n\n\n{_OCR_BLOCK}\n\n\n"
157-
f"## Page 3\n\n\n{_OCR_BLOCK}"
153+
"## Page 1\n\n\n"
154+
"Page 1 - Content before image\n\n"
155+
"This is important text that appears BEFORE the image.\n\n\n\n"
156+
"*[Image OCR]\nMOCK_OCR_TEXT_12345\n[End OCR]*\n\n\n"
157+
"This text appears AFTER the image on page 1.\n\n"
158+
"More content follows here.\n\n\n"
159+
"## Page 2\n\n\n"
160+
"Page 2 - Content with image at end\n\n"
161+
"Main content of page 2 starts here.\n\n"
162+
"This is paragraph 1.\n\n"
163+
"This is paragraph 2.\n\n"
164+
"Final paragraph before image.\n\n\n\n"
165+
"*[Image OCR]\nMOCK_OCR_TEXT_12345\n[End OCR]*\n\n\n\n"
166+
"## Page 3\n\n\n"
167+
"Page 3 - Image at top\n\n\n\n"
168+
"*[Image OCR]\nMOCK_OCR_TEXT_12345\n[End OCR]*\n\n\n"
169+
"Content that follows the image.\n\n"
170+
"This text is AFTER the image."
158171
)
159172
assert _convert("pdf_multipage.pdf", svc) == expected
160173

packages/markitdown/src/markitdown/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def main():
219219
elif args.use_cu:
220220
if args.cu_endpoint is None:
221221
_exit_with_error(
222-
"Content Understanding Endpoint (--cu-endpoint) is required when using --use-cu."
222+
"Content Understanding Endpoint (--cu-endpoint) is required when using --use-cu. "
223223
"Pass --cu-endpoint or set MARKITDOWN_CU_ENDPOINT."
224224
)
225225

packages/markitdown/src/markitdown/converter_utils/docx/pre_process.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ def _pre_process_strike(content: bytes) -> bytes:
114114
Returns:
115115
bytes: The processed content with "dstrike" elements renamed to "strike", encoded as bytes.
116116
"""
117+
# Double strikethrough is rare, and parsing/reserializing the XML is expensive
118+
# on large documents, so skip the round-trip when there is nothing to rename.
119+
if b"dstrike" not in content:
120+
return content
121+
117122
soup = BeautifulSoup(content.decode(), features="xml")
118123
for tag in soup.find_all("dstrike"):
119124
tag.name = "strike"

0 commit comments

Comments
 (0)