MCPcopy Create free account
hub / github.com/docling-project/docling-parse / verify_annotations_recursive

Function verify_annotations_recursive

tests/test_parse.py:912–941  ·  view source on GitHub ↗

Recursively verify annotations match expected structure.

(true_annots, pred_annots)

Source from the content-addressed store, hash-verified

910
911
912def verify_annotations_recursive(true_annots, pred_annots):
913 """Recursively verify annotations match expected structure."""
914 if isinstance(true_annots, dict):
915 for k, v in true_annots.items():
916 assert k in pred_annots, f"Missing key: {k}"
917 verify_annotations_recursive(true_annots[k], pred_annots[k])
918
919 elif isinstance(true_annots, list):
920 assert len(true_annots) == len(pred_annots), "List length mismatch"
921 for i, _ in enumerate(true_annots):
922 verify_annotations_recursive(true_annots[i], pred_annots[i])
923
924 elif isinstance(true_annots, str):
925 assert true_annots == pred_annots, (
926 f"String mismatch: {true_annots}!={pred_annots}"
927 )
928
929 elif isinstance(true_annots, int):
930 assert true_annots == pred_annots, f"Int mismatch: {true_annots}!={pred_annots}"
931
932 elif isinstance(true_annots, float):
933 assert abs(true_annots - pred_annots) < 1e-6, (
934 f"Float mismatch: {true_annots}!={pred_annots}"
935 )
936
937 elif true_annots is None:
938 assert pred_annots is None, "Expected None"
939
940 else:
941 assert True # Other types pass
942
943
944def test_table_of_contents():

Callers 1

Calls 1

itemsMethod · 0.80

Tested by

no test coverage detected