# Copyright (c) 2026 LlamaIndex, Inc. All rights reserved. # Licensed under the OCRia-1 Model and Code License (LICENSE at the root of this repository). # This is not open-source software: see the license for permitted uses. """Reject malformed external sparse maps before they reach geometry/native code.""" import pytest from parse_rl_utils.ocria_attention_grounding.api import FastLayout @pytest.mark.parametrize( "field,value", [ ("width", float("nan")), ("grid", [0, 2]), ("grid", [1.5, 2]), ("idx", [[-1]]), ("idx", [[4]]), ("idx", [[1.5]]), ("val", [[float("nan")]]), ("val", [[-1.0]]), ("val", [[]]), ("has", []), ], ) def test_malformed_capture_is_rejected_before_grounding( field: str, value: object ) -> None: capture = { "width": 100, "height": 100, "grid": [2, 2], "sparse_maps": {"idx": [[0]], "val": [[1.0]], "has": [True]}, } if field in ("width", "grid"): capture[field] = value else: capture["sparse_maps"][field] = value backend = FastLayout.__new__(FastLayout) backend.words = backend.pictures = backend.regions = backend.tables = ( backend.peaks ) = None with pytest.raises(ValueError): backend(answer="word", attention=capture)