mirror of
https://github.com/docling-project/docling.git
synced 2026-05-17 13:10:38 +00:00
6238aa35d0
* chore: address stale TODO comments across codebase Signed-off-by: Hassan Raza <raihassanraza10@gmail.com> * refactor: extract list marker helper and add no-pipeline test coverage - Extract duplicated "set marker + add list item" logic in _add_list_item() into _add_list_item_with_marker() helper method - Add tests for defensive "no pipeline" code path in _execute_pipeline() Signed-off-by: Hassan Raza <raihassanraza10@gmail.com> * style: fix ruff formatting in list marker helper Signed-off-by: Hassan Raza <raihassanraza10@gmail.com> * fix: skip bbox validation in fuzzy mode and increase tolerance Fuzzy tests (OCR, image) have inherent coordinate variability, so bbox checks are skipped. For non-fuzzy tests, increase tolerance from 0.01 to 0.5 to account for cross-platform numeric variance. Signed-off-by: Hassan Raza <raihassanraza10@gmail.com> * test: use reasoned bbox tolerances in verify utils Signed-off-by: Hassan Raza <raihassanraza10@gmail.com> * test: scale bbox tolerance by page extent Signed-off-by: Hassan Raza <raihassanraza10@gmail.com> * test: assert bbox presence in verification Signed-off-by: Hassan Raza <raihassanraza10@gmail.com> --------- Signed-off-by: Hassan Raza <raihassanraza10@gmail.com> Signed-off-by: Peter W. J. Staar <91719829+PeterStaar-IBM@users.noreply.github.com> Co-authored-by: Peter W. J. Staar <91719829+PeterStaar-IBM@users.noreply.github.com>
67 lines
2.2 KiB
Python
67 lines
2.2 KiB
Python
from io import BytesIO
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from docling.datamodel.base_models import ConversionStatus, DocumentStream, InputFormat
|
|
from docling.document_converter import ConversionError, DocumentConverter
|
|
|
|
|
|
def get_pdf_path():
|
|
pdf_path = Path("./tests/data/pdf/2305.03393v1-pg9.pdf")
|
|
return pdf_path
|
|
|
|
|
|
@pytest.fixture
|
|
def converter():
|
|
converter = DocumentConverter()
|
|
|
|
return converter
|
|
|
|
|
|
def test_convert_unsupported_doc_format_wout_exception(converter: DocumentConverter):
|
|
result = converter.convert(
|
|
DocumentStream(name="input.xyz", stream=BytesIO(b"xyz")), raises_on_error=False
|
|
)
|
|
assert result.status == ConversionStatus.SKIPPED
|
|
|
|
|
|
def test_convert_unsupported_doc_format_with_exception(converter: DocumentConverter):
|
|
with pytest.raises(ConversionError):
|
|
converter.convert(
|
|
DocumentStream(name="input.xyz", stream=BytesIO(b"xyz")),
|
|
raises_on_error=True,
|
|
)
|
|
|
|
|
|
def test_convert_too_small_filesize_limit_wout_exception(converter: DocumentConverter):
|
|
result = converter.convert(get_pdf_path(), max_file_size=1, raises_on_error=False)
|
|
assert result.status == ConversionStatus.FAILURE
|
|
|
|
|
|
def test_convert_too_small_filesize_limit_with_exception(converter: DocumentConverter):
|
|
with pytest.raises(ConversionError):
|
|
converter.convert(get_pdf_path(), max_file_size=1, raises_on_error=True)
|
|
|
|
|
|
def test_convert_no_pipeline_wout_exception():
|
|
converter = DocumentConverter()
|
|
# Bypass the model validator by setting pipeline_options to None after construction.
|
|
# This triggers the defensive "no pipeline" code path in _execute_pipeline.
|
|
converter.format_to_options[InputFormat.MD].pipeline_options = None
|
|
result = converter.convert(
|
|
DocumentStream(name="test.md", stream=BytesIO(b"# Hello")),
|
|
raises_on_error=False,
|
|
)
|
|
assert result.status == ConversionStatus.FAILURE
|
|
|
|
|
|
def test_convert_no_pipeline_with_exception():
|
|
converter = DocumentConverter()
|
|
converter.format_to_options[InputFormat.MD].pipeline_options = None
|
|
with pytest.raises(ConversionError):
|
|
converter.convert(
|
|
DocumentStream(name="test.md", stream=BytesIO(b"# Hello")),
|
|
raises_on_error=True,
|
|
)
|