Skip to content

Commit 7d437ec

Browse files
tests: Add page range support tests for extract_pdf_text
- Introduced `PAGES_OPTION_SETS` to validate extraction with and without page ranges. - Updated `test_async_extract_pdf_text_success` to include `pages` parameter, covering scenarios with specific page ranges. - Enhanced payload handling to conditionally include `pages` when provided. Assisted-by: Codex
1 parent ad5c68d commit 7d437ec

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

tests/test_extract_pdf_text.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ def _make_extracted_text_document_payload(input_id: str) -> dict[str, object]:
6060
for preserve, word_style, word_coordinates in BOOL_OPTION_SETS
6161
]
6262

63+
PAGES_OPTION_SETS = [
64+
pytest.param(None, id="without-pages"),
65+
pytest.param(["1-2"], id="with-pages"),
66+
]
67+
6368

6469
@pytest.mark.parametrize("options", EXTRACT_TEXT_OPTION_SETS)
6570
def test_extract_pdf_text_success(
@@ -163,8 +168,10 @@ def handler(request: httpx.Request) -> httpx.Response:
163168

164169
@pytest.mark.asyncio
165170
@pytest.mark.parametrize("options", EXTRACT_TEXT_OPTION_SETS)
171+
@pytest.mark.parametrize("pages", PAGES_OPTION_SETS)
166172
async def test_async_extract_pdf_text_success(
167173
options: Mapping[str, bool | str],
174+
pages: list[str] | None,
168175
monkeypatch: pytest.MonkeyPatch,
169176
) -> None:
170177
monkeypatch.delenv("PDFREST_API_KEY", raising=False)
@@ -173,6 +180,8 @@ async def test_async_extract_pdf_text_success(
173180
"files": [input_file],
174181
"output_type": "json",
175182
}
183+
if pages is not None:
184+
base_payload["pages"] = pages
176185
payload_input = base_payload | dict(options)
177186
payload_dump = ExtractTextPayload.model_validate(payload_input).model_dump(
178187
mode="json",
@@ -197,13 +206,16 @@ def handler(request: httpx.Request) -> httpx.Response:
197206
api_key=ASYNC_API_KEY,
198207
transport=transport,
199208
) as client:
200-
response = await client.extract_pdf_text(
201-
input_file,
202-
full_text=options["full_text"],
203-
preserve_line_breaks=options["preserve_line_breaks"],
204-
word_style=options["word_style"],
205-
word_coordinates=options["word_coordinates"],
206-
)
209+
request_kwargs: dict[str, object] = {
210+
"full_text": options["full_text"],
211+
"preserve_line_breaks": options["preserve_line_breaks"],
212+
"word_style": options["word_style"],
213+
"word_coordinates": options["word_coordinates"],
214+
}
215+
if pages is not None:
216+
request_kwargs["pages"] = pages
217+
218+
response = await client.extract_pdf_text(input_file, **request_kwargs)
207219

208220
assert seen == {"post": 1}
209221
assert isinstance(response, ExtractedTextDocument)

0 commit comments

Comments
 (0)