|
| 1 | +import json |
| 2 | + |
1 | 3 | import pytest |
2 | 4 |
|
| 5 | +from mindee import ClientV2, LocalResponse |
3 | 6 | from mindee.parsing.common.string_dict import StringDict |
4 | 7 | from mindee.parsing.v2 import ( |
5 | 8 | Inference, |
| 9 | + InferenceFile, |
| 10 | + InferenceModel, |
6 | 11 | InferenceResponse, |
7 | | - InferenceResult, |
8 | 12 | ListField, |
9 | 13 | ObjectField, |
10 | 14 | SimpleField, |
11 | 15 | ) |
| 16 | +from tests.test_inputs import V2_DATA_DIR |
12 | 17 |
|
13 | 18 |
|
14 | 19 | @pytest.fixture |
15 | | -def inference_json() -> StringDict: |
| 20 | +def inference_result_json() -> StringDict: |
16 | 21 | return { |
17 | 22 | "inference": { |
18 | 23 | "model": {"id": "test-model-id"}, |
@@ -92,8 +97,8 @@ def inference_json() -> StringDict: |
92 | 97 |
|
93 | 98 |
|
94 | 99 | @pytest.mark.v2 |
95 | | -def test_inference(inference_json): |
96 | | - inference_result = InferenceResponse(inference_json) |
| 100 | +def test_inference_response(inference_result_json): |
| 101 | + inference_result = InferenceResponse(inference_result_json) |
97 | 102 | assert isinstance(inference_result.inference, Inference) |
98 | 103 | assert isinstance( |
99 | 104 | inference_result.inference.result.fields.field_simple, SimpleField |
@@ -158,3 +163,29 @@ def test_inference(inference_json): |
158 | 163 | .value |
159 | 164 | == "value_9" |
160 | 165 | ) |
| 166 | + |
| 167 | + |
| 168 | +@pytest.mark.v2 |
| 169 | +def test_full_inference_response(): |
| 170 | + client_v2 = ClientV2("dummy") |
| 171 | + load_response = client_v2.load_inference( |
| 172 | + LocalResponse(V2_DATA_DIR / "products" / "financial_document" / "complete.json") |
| 173 | + ) |
| 174 | + |
| 175 | + assert isinstance(load_response.inference, Inference) |
| 176 | + assert load_response.inference.id == "12345678-1234-1234-1234-123456789abc" |
| 177 | + assert isinstance(load_response.inference.result.fields.date, SimpleField) |
| 178 | + assert load_response.inference.result.fields.date.value == "2019-11-02" |
| 179 | + assert isinstance(load_response.inference.result.fields.taxes, ListField) |
| 180 | + assert isinstance(load_response.inference.result.fields.taxes.items[0], ObjectField) |
| 181 | + assert ( |
| 182 | + load_response.inference.result.fields.taxes.items[0].fields["base"].value |
| 183 | + == 31.5 |
| 184 | + ) |
| 185 | + |
| 186 | + assert isinstance(load_response.inference.model, InferenceModel) |
| 187 | + assert load_response.inference.model.id == "12345678-1234-1234-1234-123456789abc" |
| 188 | + |
| 189 | + assert isinstance(load_response.inference.file, InferenceFile) |
| 190 | + assert load_response.inference.file.name == "complete.jpg" |
| 191 | + assert load_response.inference.file.alias == None |
0 commit comments