9f97f3abbe
CI - Node Bindings / Build darwin-arm64 (push) Waiting to run
CI - Node Bindings / Build darwin-x64 (push) Waiting to run
CI - Node Bindings / Test win32-x64-msvc (push) Blocked by required conditions
CI - Node Bindings / Build linux-arm64-gnu (push) Waiting to run
CI - Node Bindings / Build linux-x64-gnu (push) Waiting to run
CI - Node Bindings / Build linux-x64-musl (push) Waiting to run
CI - Node Bindings / Build win32-arm64-msvc (push) Waiting to run
CI - Node Bindings / Build win32-x64-msvc (push) Waiting to run
CI - Node Bindings / Test darwin-arm64 (push) Blocked by required conditions
CI - Node Bindings / Test darwin-x64 (push) Blocked by required conditions
CI - Node Bindings / Test linux-x64-gnu (push) Blocked by required conditions
CI - Node Bindings / Test linux-x64-musl (push) Blocked by required conditions
CI - Node Bindings / Test win32-arm64-msvc (push) Blocked by required conditions
CI - Python Bindings / Build aarch64-pc-windows-msvc (push) Waiting to run
CI - Python Bindings / Build x86_64-pc-windows-msvc (push) Waiting to run
CI - Python Bindings / Build x86_64-apple-darwin (push) Waiting to run
CI - Python Bindings / Build aarch64-apple-darwin (push) Waiting to run
CI - Python Bindings / Build aarch64-unknown-linux-gnu (push) Waiting to run
CI - Python Bindings / Test x86_64-apple-darwin (push) Blocked by required conditions
CI - Python Bindings / Test aarch64-apple-darwin (push) Blocked by required conditions
CI - Python Bindings / Test x86_64-unknown-linux-gnu (push) Blocked by required conditions
CI - Python Bindings / Test x86_64-unknown-linux-musl (push) Blocked by required conditions
CI - Python Bindings / Test aarch64-pc-windows-msvc (push) Blocked by required conditions
CI - Python Bindings / Test x86_64-pc-windows-msvc (push) Blocked by required conditions
CI / build-and-test (macos-26-intel) (push) Waiting to run
CI / build-and-test (macos-latest) (push) Waiting to run
CI / build-and-test (windows-11-arm) (push) Waiting to run
CI / build-and-test (windows-latest) (push) Waiting to run
CI - Python Bindings / sdist (push) Failing after 1s
CI - Python Bindings / Build x86_64-unknown-linux-musl (push) Failing after 1s
CI / fmt (push) Failing after 1s
E2E Output Validation / compare-outputs (push) Failing after 1s
Sync Docs to Developer Hub / sync-docs (push) Failing after 1s
CI - Python Bindings / Build x86_64-unknown-linux-gnu (push) Failing after 1s
CI - WASM Bindings / Build WASM (push) Failing after 0s
CI / clippy (push) Failing after 1s
CI / build-and-test (ubuntu-latest) (push) Failing after 0s
CI - WASM Bindings / Edge runtime PDF parse test (push) Has been skipped
CI - WASM Bindings / Browser PDF parse test (push) Has been skipped
E2E Output Validation / upload-dataset (push) Waiting to run
Deploy Demo to GitHub Pages / deploy (push) Failing after 1s
CI / build-docker-image (push) Failing after 3s
103 lines
3.7 KiB
Python
103 lines
3.7 KiB
Python
"""E2E tests for LiteParse.screenshot() — validates Python types match CLI output."""
|
|
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from liteparse import (
|
|
ImageFormat,
|
|
LiteParse,
|
|
ScreenshotBatchResult,
|
|
ScreenshotResult,
|
|
)
|
|
|
|
|
|
class TestScreenshotBasic:
|
|
"""Basic screenshot functionality."""
|
|
|
|
def test_screenshot_returns_batch_result(
|
|
self, parser: LiteParse, invoice_pdf: Path
|
|
):
|
|
result = parser.screenshot(invoice_pdf)
|
|
assert isinstance(result, ScreenshotBatchResult)
|
|
|
|
def test_screenshot_has_screenshots(self, parser: LiteParse, invoice_pdf: Path):
|
|
result = parser.screenshot(invoice_pdf)
|
|
assert len(result) > 0
|
|
assert len(result.screenshots) > 0
|
|
|
|
def test_screenshot_result_fields(self, parser: LiteParse, invoice_pdf: Path):
|
|
result = parser.screenshot(invoice_pdf)
|
|
ss = result.screenshots[0]
|
|
assert isinstance(ss, ScreenshotResult)
|
|
assert isinstance(ss.page_num, int)
|
|
assert ss.page_num >= 1
|
|
assert isinstance(ss.image_path, str)
|
|
assert Path(ss.image_path).exists()
|
|
|
|
def test_screenshot_output_dir(self, parser: LiteParse, invoice_pdf: Path):
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
result = parser.screenshot(invoice_pdf, output_dir=tmpdir)
|
|
assert result.output_dir == tmpdir
|
|
# Files should be in the specified directory
|
|
for ss in result.screenshots:
|
|
assert ss.image_path.startswith(tmpdir)
|
|
|
|
def test_screenshot_png_format(self, parser: LiteParse, invoice_pdf: Path):
|
|
result = parser.screenshot(invoice_pdf, image_format=ImageFormat.PNG)
|
|
for ss in result.screenshots:
|
|
assert ss.image_path.endswith(".png")
|
|
|
|
def test_screenshot_jpg_format(self, parser: LiteParse, invoice_pdf: Path):
|
|
result = parser.screenshot(invoice_pdf, image_format="jpg")
|
|
for ss in result.screenshots:
|
|
assert ss.image_path.endswith(".jpg")
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_screensho_async_basic(self, parser: LiteParse, invoice_pdf: Path):
|
|
result = await parser.screenshot_async(invoice_pdf, image_format="png")
|
|
assert isinstance(result, ScreenshotBatchResult)
|
|
assert len(result.screenshots) > 0
|
|
|
|
|
|
class TestScreenshotOptions:
|
|
"""Test screenshot options are forwarded correctly."""
|
|
|
|
def test_target_pages(self, parser: LiteParse, invoice_pdf: Path):
|
|
# invoice.pdf has 2 pages — screenshot only page 1
|
|
result = parser.screenshot(invoice_pdf, target_pages="1")
|
|
assert len(result) == 1
|
|
assert result.screenshots[0].page_num == 1
|
|
|
|
def test_load_bytes(self, parser: LiteParse, invoice_pdf: Path):
|
|
result = parser.screenshot(invoice_pdf, load_bytes=True)
|
|
for ss in result.screenshots:
|
|
assert ss.image_bytes is not None
|
|
assert len(ss.image_bytes) > 0
|
|
|
|
def test_no_load_bytes(self, parser: LiteParse, invoice_pdf: Path):
|
|
result = parser.screenshot(invoice_pdf, load_bytes=False)
|
|
for ss in result.screenshots:
|
|
assert ss.image_bytes is None
|
|
|
|
def test_get_page_helper(self, parser: LiteParse, invoice_pdf: Path):
|
|
result = parser.screenshot(invoice_pdf)
|
|
page1 = result.get_page(1)
|
|
assert page1 is not None
|
|
assert page1.page_num == 1
|
|
assert result.get_page(999) is None
|
|
|
|
def test_iterable(self, parser: LiteParse, invoice_pdf: Path):
|
|
result = parser.screenshot(invoice_pdf)
|
|
pages = list(result)
|
|
assert len(pages) == len(result)
|
|
|
|
|
|
class TestScreenshotErrors:
|
|
"""Test error handling."""
|
|
|
|
def test_file_not_found(self, parser: LiteParse):
|
|
with pytest.raises(FileNotFoundError):
|
|
parser.screenshot("/nonexistent/file.pdf")
|