Recursively verify annotations match expected structure.
(true_annots, pred_annots)
| 910 | |
| 911 | |
| 912 | def 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 | |
| 944 | def test_table_of_contents(): |
no test coverage detected