11import pytest
2- from docling_core .types .doc import DoclingDocument , ProvenanceItem
2+ from docling_core .types .doc import DoclingDocument , ImageRef , ProvenanceItem
33from docling_core .types .doc .base import BoundingBox , Size
44from docling_core .types .doc .labels import DocItemLabel
5+ from PIL import Image
56
67from tests .verify_utils import verify_docitems
78
@@ -24,6 +25,14 @@ def _make_doc_with_bbox(
2425 return doc
2526
2627
28+ def _make_doc_with_picture (* , image_size : tuple [int , int ]) -> DoclingDocument :
29+ doc = DoclingDocument (name = "test" )
30+ doc .add_picture (
31+ image = ImageRef .from_pil (Image .new ("RGB" , image_size , "red" ), dpi = 72 )
32+ )
33+ return doc
34+
35+
2736def test_verify_docitems_allows_small_bbox_variance_for_non_fuzzy_docs ():
2837 verify_docitems (
2938 doc_pred = _make_doc_with_bbox (left = 11.53 ),
@@ -78,3 +87,29 @@ def test_verify_docitems_rejects_bbox_presence_mismatch():
7887 fuzzy = False ,
7988 pdf_filename = "fixture.json" ,
8089 )
90+
91+
92+ def test_verify_docitems_rejects_picture_count_mismatch ():
93+ doc_true = _make_doc_with_picture (image_size = (2 , 2 ))
94+ doc_pred = DoclingDocument (name = "test" )
95+
96+ with pytest .raises (AssertionError , match = "Picture lengths do not match" ):
97+ verify_docitems (
98+ doc_pred = doc_pred ,
99+ doc_true = doc_true ,
100+ fuzzy = False ,
101+ pdf_filename = "fixture.json" ,
102+ )
103+
104+
105+ def test_verify_docitems_uses_predicted_picture_image ():
106+ doc_true = _make_doc_with_picture (image_size = (2 , 2 ))
107+ doc_pred = _make_doc_with_picture (image_size = (3 , 2 ))
108+
109+ with pytest .raises (AssertionError ):
110+ verify_docitems (
111+ doc_pred = doc_pred ,
112+ doc_true = doc_true ,
113+ fuzzy = False ,
114+ pdf_filename = "fixture.json" ,
115+ )
0 commit comments