|
4 | 4 |
|
5 | 5 | import pytest |
6 | 6 |
|
| 7 | +from mindee.parsing.v2.field.field_confidence import FieldConfidence |
7 | 8 | from mindee.parsing.v2.field.list_field import ListField |
8 | 9 | from mindee.parsing.v2.field.object_field import ObjectField |
9 | 10 | from mindee.parsing.v2.field.simple_field import SimpleField |
@@ -185,3 +186,42 @@ def test_full_inference_response(): |
185 | 186 | assert inference_result.inference.file.mime_type == "image/jpeg" |
186 | 187 | assert not inference_result.inference.file.alias |
187 | 188 | assert not inference_result.inference.result.options |
| 189 | + |
| 190 | + |
| 191 | +@pytest.mark.v2 |
| 192 | +def test_field_locations_and_confidence() -> None: |
| 193 | + """ |
| 194 | + Validate that the first location polygon for the ``date`` field is correctly |
| 195 | + deserialized together with the associated confidence level. |
| 196 | + """ |
| 197 | + json_sample, _ = _get_product_samples( |
| 198 | + "financial_document", "complete_with_coordinates" |
| 199 | + ) |
| 200 | + |
| 201 | + inference_result = InferenceResponse(json_sample) |
| 202 | + |
| 203 | + date_field: SimpleField = inference_result.inference.result.fields.date |
| 204 | + |
| 205 | + assert date_field.locations, "date field should expose locations" |
| 206 | + loc0 = date_field.locations[0] |
| 207 | + assert loc0 is not None |
| 208 | + assert loc0.page == 0 |
| 209 | + |
| 210 | + polygon = loc0.polygon |
| 211 | + assert polygon is not None |
| 212 | + assert len(polygon[0]) == 2 |
| 213 | + |
| 214 | + assert polygon[0][0] == 0.948979073166918 |
| 215 | + assert polygon[0][1] == 0.23097924535067715 |
| 216 | + |
| 217 | + assert polygon[1][0] == 0.85422 |
| 218 | + assert polygon[1][1] == 0.230072 |
| 219 | + |
| 220 | + assert polygon[2][0] == 0.8540899268330819 |
| 221 | + assert polygon[2][1] == 0.24365775464932288 |
| 222 | + |
| 223 | + assert polygon[3][0] == 0.948849 |
| 224 | + assert polygon[3][1] == 0.244565 |
| 225 | + |
| 226 | + assert date_field.confidence == FieldConfidence.MEDIUM |
| 227 | + assert str(date_field.confidence.value) == "Medium" |
0 commit comments