Files
docling-core/tests/test_cli_serialize.py
e810e290c4 fix(dclq): use typer's vendored click; allow typer 0.27 (#928)
* fix(dclq): use typer's vendored click; allow typer 0.27

typer >=0.26 vendors its own copy of click (typer._click) and raises those
exceptions instead of the external click package's. The dclq CLI referenced
the external click, so on typer >=0.26 bad input escaped the exit-code
handlers and the context-flag callback (-C/-A/-B/--context-scope) silently
no-op'd because the isinstance(param, click.Option) check no longer matched.

Import ClickException and Parameter from typer._click, catch the public
typer.Exit (moved out of typer._click in 0.27), and duck-type the option
check. Set the [dclq] typer range to >=0.26,<0.28, raise the core typer cap
to <0.28, and drop the now-unused external click dependency.

Signed-off-by: Christoph Auer <cau@zurich.ibm.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(dclq): use typer.CallbackParam; drop click from tests

Annotate the context-flag callback with the public typer.CallbackParam
instead of typer._click.Parameter, read param_type_name directly, and
strip ANSI codes in test_cli_serialize with a regex instead of importing
click.unstyle, which only resolved through a transitive dev dependency.

Signed-off-by: Christoph Auer <cau@zurich.ibm.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Update pyproject.toml

Co-authored-by: Panos Vagenas <35837085+vagenas@users.noreply.github.com>
Signed-off-by: Christoph Auer <60343111+cau-git@users.noreply.github.com>

---------

Signed-off-by: Christoph Auer <cau@zurich.ibm.com>
Signed-off-by: Christoph Auer <60343111+cau-git@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Panos Vagenas <35837085+vagenas@users.noreply.github.com>
2026-10-27 16:54:28 +01:00

54 lines
1.6 KiB
Python

"""Tests for the ``docling-serialize`` CLI."""
import re
import zipfile
from pathlib import Path
from typer.testing import CliRunner
from docling_core.cli.serialize import app
from docling_core.types.doc import DoclingDocument
DOC_LANG_ARCHIVE_FIXTURE = Path("tests/data/doc/doclang_archive/save/two_pages.json")
def test_serialize_json_to_dclx_packages_images(tmp_path: Path) -> None:
"""DCLX output packages page rasters and picture assets."""
output = tmp_path / "nested" / "two_pages.dclx"
result = CliRunner().invoke(
app,
[str(DOC_LANG_ARCHIVE_FIXTURE), "--to", "dclx", "--output", str(output)],
)
assert result.exit_code == 0, result.output
assert output.is_file()
assert f"Wrote {output}" in result.output
with zipfile.ZipFile(output) as archive:
names = archive.namelist()
assert "document.xml" in names
assert "pages/1.png" in names
assert "pages/2.png" in names
assert any(name.startswith("assets/") for name in names)
loaded = DoclingDocument.load_from_doclang_archive(
output,
artifacts_dir=tmp_path / "loaded",
)
assert len(loaded.pages) == 2
assert loaded.pictures
assert loaded.pictures[0].image is not None
assert loaded.pictures[0].image.pil_image is not None
def test_serialize_dclx_requires_output_path() -> None:
"""Binary DCLX output is not written to standard output."""
result = CliRunner().invoke(
app,
[str(DOC_LANG_ARCHIVE_FIXTURE), "--to", "dclx"],
)
assert result.exit_code == 2
assert "--output is required when --to dclx" in re.sub(r"\x1b\[[0-9;]*m", "", result.output)