Skip to content

Commit 8a44f70

Browse files
it do be coveraging
1 parent d9c9c4b commit 8a44f70

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

tests/test_client_v2.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from mindee import ClientV2, InferencePredictOptions, LocalResponse
44
from mindee.error.mindee_error import MindeeApiV2Error
55
from mindee.error.mindee_http_error_v2 import MindeeHTTPErrorV2
6-
from mindee.input import LocalInputSource
6+
from mindee.input import LocalInputSource, PathInput
7+
from mindee.mindee_http.base_settings import USER_AGENT
78
from tests.test_inputs import FILE_TYPES_DIR, V2_DATA_DIR
89
from tests.utils import dummy_envvars
910

@@ -22,9 +23,7 @@ class _FakeResp:
2223

2324
def json(self):
2425
# Shape must match what handle_error_v2 expects
25-
return {
26-
"error": {"status": -1, "detail": "forced failure from test"},
27-
}
26+
return {"status": -1, "detail": "forced failure from test"}
2827

2928
monkeypatch.setenv("MINDEE_V2_BASE_URL", "https://dummy-url")
3029

@@ -57,6 +56,8 @@ def test_enqueue_path_with_env_token(custom_base_url_client):
5756
assert custom_base_url_client.mindee_api.base_url == "https://dummy-url"
5857
assert custom_base_url_client.mindee_api.url_root == "https://dummy-url"
5958
assert custom_base_url_client.mindee_api.api_key == "dummy"
59+
assert custom_base_url_client.mindee_api.base_headers["Authorization"] == "dummy"
60+
assert custom_base_url_client.mindee_api.base_headers["User-Agent"] == USER_AGENT
6061
input_doc: LocalInputSource = custom_base_url_client.source_from_path(
6162
f"{FILE_TYPES_DIR}/receipt.jpg"
6263
)
@@ -90,3 +91,16 @@ def test_loads_from_prediction(env_client):
9091
)
9192
prediction = env_client.load_inference(input_inference)
9293
assert prediction.inference.model.id == "12345678-1234-1234-1234-123456789abc"
94+
95+
96+
@pytest.mark.v2
97+
def test_error_handling(custom_base_url_client):
98+
with pytest.raises(MindeeHTTPErrorV2) as e:
99+
custom_base_url_client.enqueue(
100+
PathInput(
101+
V2_DATA_DIR / "products" / "financial_document" / "default_sample.jpg"
102+
),
103+
InferencePredictOptions("dummy-model"),
104+
)
105+
assert e.status_code == -1
106+
assert e.detail == "forced failure from test"

tests/v2/test_inference_response.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ def inference_result_json() -> StringDict:
9090
}
9191
},
9292
},
93-
"options": None,
93+
"options": {
94+
"raw_text": ["toto", "tata", "titi"],
95+
},
9496
},
9597
}
9698
}
@@ -164,6 +166,10 @@ def test_inference_response(inference_result_json):
164166
== "value_9"
165167
)
166168

169+
assert inference_result.inference.result.options
170+
assert len(inference_result.inference.result.options.raw_text) == 3
171+
assert inference_result.inference.result.options.raw_text[0] == "toto"
172+
167173

168174
@pytest.mark.v2
169175
def test_full_inference_response():
@@ -188,4 +194,5 @@ def test_full_inference_response():
188194

189195
assert isinstance(load_response.inference.file, InferenceFile)
190196
assert load_response.inference.file.name == "complete.jpg"
191-
assert load_response.inference.file.alias == None
197+
assert not load_response.inference.file.alias
198+
assert not load_response.inference.result.options

0 commit comments

Comments
 (0)