mirror of
https://github.com/DS4SD/docling.git
synced 2025-12-08 12:48:28 +00:00
ci: add coverage and ruff (#1383)
* add coverage calculation and push Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * new codecov version and usage of token Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * enable ruff formatter instead of black and isort Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * apply ruff lint fixes Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * apply ruff unsafe fixes Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * add removed imports Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * runs 1 on linter issues Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * finalize linter fixes Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * Update pyproject.toml Co-authored-by: Cesar Berrospi Ramis <75900930+ceberam@users.noreply.github.com> Signed-off-by: Michele Dolfi <97102151+dolfim-ibm@users.noreply.github.com> --------- Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> Signed-off-by: Michele Dolfi <97102151+dolfim-ibm@users.noreply.github.com> Co-authored-by: Cesar Berrospi Ramis <75900930+ceberam@users.noreply.github.com>
This commit is contained in:
@@ -12,10 +12,9 @@ from docling.document_converter import PdfFormatOption
|
||||
|
||||
|
||||
def test_in_doc_from_valid_path():
|
||||
|
||||
test_doc_path = Path("./tests/data/pdf/2206.01062.pdf")
|
||||
doc = _make_input_doc(test_doc_path)
|
||||
assert doc.valid == True
|
||||
assert doc.valid is True
|
||||
|
||||
|
||||
def test_in_doc_from_invalid_path():
|
||||
@@ -23,29 +22,26 @@ def test_in_doc_from_invalid_path():
|
||||
|
||||
doc = _make_input_doc(test_doc_path)
|
||||
|
||||
assert doc.valid == False
|
||||
assert doc.valid is False
|
||||
|
||||
|
||||
def test_in_doc_from_valid_buf():
|
||||
|
||||
buf = BytesIO(Path("./tests/data/pdf/2206.01062.pdf").open("rb").read())
|
||||
stream = DocumentStream(name="my_doc.pdf", stream=buf)
|
||||
|
||||
doc = _make_input_doc_from_stream(stream)
|
||||
assert doc.valid == True
|
||||
assert doc.valid is True
|
||||
|
||||
|
||||
def test_in_doc_from_invalid_buf():
|
||||
|
||||
buf = BytesIO(b"")
|
||||
stream = DocumentStream(name="my_doc.pdf", stream=buf)
|
||||
|
||||
doc = _make_input_doc_from_stream(stream)
|
||||
assert doc.valid == False
|
||||
assert doc.valid is False
|
||||
|
||||
|
||||
def test_image_in_pdf_backend():
|
||||
|
||||
in_doc = InputDocument(
|
||||
path_or_stream=Path("tests/data/2305.03393v1-pg9-img.png"),
|
||||
format=InputFormat.IMAGE,
|
||||
@@ -76,7 +72,6 @@ def test_image_in_pdf_backend():
|
||||
|
||||
|
||||
def test_in_doc_with_page_range():
|
||||
|
||||
test_doc_path = Path("./tests/data/pdf/2206.01062.pdf")
|
||||
limits = DocumentLimits()
|
||||
limits.page_range = (1, 10)
|
||||
@@ -87,7 +82,7 @@ def test_in_doc_with_page_range():
|
||||
backend=PyPdfiumDocumentBackend,
|
||||
limits=limits,
|
||||
)
|
||||
assert doc.valid == True
|
||||
assert doc.valid is True
|
||||
|
||||
limits.page_range = (9, 9)
|
||||
|
||||
@@ -97,7 +92,7 @@ def test_in_doc_with_page_range():
|
||||
backend=PyPdfiumDocumentBackend,
|
||||
limits=limits,
|
||||
)
|
||||
assert doc.valid == True
|
||||
assert doc.valid is True
|
||||
|
||||
limits.page_range = (11, 12)
|
||||
|
||||
@@ -107,7 +102,7 @@ def test_in_doc_with_page_range():
|
||||
backend=PyPdfiumDocumentBackend,
|
||||
limits=limits,
|
||||
)
|
||||
assert doc.valid == False
|
||||
assert doc.valid is False
|
||||
|
||||
|
||||
def test_guess_format(tmp_path):
|
||||
@@ -192,17 +187,17 @@ def test_guess_format(tmp_path):
|
||||
)
|
||||
doc_path = temp_dir / "docling_test.xml"
|
||||
doc_path.write_text(xml_content, encoding="utf-8")
|
||||
assert dci._guess_format(doc_path) == None
|
||||
assert dci._guess_format(doc_path) is None
|
||||
buf = BytesIO(Path(doc_path).open("rb").read())
|
||||
stream = DocumentStream(name="docling_test.xml", stream=buf)
|
||||
assert dci._guess_format(stream) == None
|
||||
assert dci._guess_format(stream) is None
|
||||
|
||||
# Invalid USPTO patent (as plain text)
|
||||
stream = DocumentStream(name="pftaps057006474.txt", stream=BytesIO(b"xyz"))
|
||||
assert dci._guess_format(stream) == None
|
||||
assert dci._guess_format(stream) is None
|
||||
doc_path = temp_dir / "pftaps_wrong.txt"
|
||||
doc_path.write_text("xyz", encoding="utf-8")
|
||||
assert dci._guess_format(doc_path) == None
|
||||
assert dci._guess_format(doc_path) is None
|
||||
|
||||
# Valid Docling JSON
|
||||
test_str = '{"name": ""}'
|
||||
|
||||
Reference in New Issue
Block a user