mirror of
https://github.com/DS4SD/docling.git
synced 2025-12-08 20:58:11 +00:00
fix: improve handling of disallowed formats (#429)
* fix: Fixes and tests for StopIteration on .convert() Signed-off-by: Christoph Auer <cau@zurich.ibm.com> * fix: Remove unnecessary case handling Signed-off-by: Christoph Auer <cau@zurich.ibm.com> * fix: Other test fixes Signed-off-by: Christoph Auer <cau@zurich.ibm.com> * improve handling of unsupported types - Introduced new explicit exception types instead of `RuntimeError` - Introduced new `ConversionStatus` value for unsupported formats - Tidied up converter member typing & removed asserts Signed-off-by: Panos Vagenas <35837085+vagenas@users.noreply.github.com> * robustify & simplify format option resolution Signed-off-by: Panos Vagenas <35837085+vagenas@users.noreply.github.com> * rename new status, populate ConversionResult errors Signed-off-by: Panos Vagenas <35837085+vagenas@users.noreply.github.com> --------- Signed-off-by: Christoph Auer <cau@zurich.ibm.com> Signed-off-by: Panos Vagenas <35837085+vagenas@users.noreply.github.com> Co-authored-by: Panos Vagenas <35837085+vagenas@users.noreply.github.com>
This commit is contained in:
@@ -10,7 +10,7 @@ from docling.document_converter import DocumentConverter, PdfFormatOption
|
||||
|
||||
from .verify_utils import verify_conversion_result_v1, verify_conversion_result_v2
|
||||
|
||||
GENERATE = True
|
||||
GENERATE = False
|
||||
|
||||
|
||||
def get_pdf_path():
|
||||
|
||||
45
tests/test_invalid_input.py
Normal file
45
tests/test_invalid_input.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from docling.datamodel.base_models import ConversionStatus, DocumentStream
|
||||
from docling.document_converter import ConversionError, DocumentConverter
|
||||
|
||||
|
||||
def get_pdf_path():
|
||||
|
||||
pdf_path = Path("./tests/data/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)
|
||||
Reference in New Issue
Block a user