44
55from __future__ import annotations
66
7- from typing import TYPE_CHECKING
7+ import io
8+ from typing import TYPE_CHECKING , BinaryIO
89
910import pytest
1011from mock_vws import MockVWS
1112from mock_vws .database import VuforiaDatabase
1213from vws import VWS , CloudRecoService
1314
1415if TYPE_CHECKING :
15- from collections .abc import Iterator
16+ from collections .abc import Generator
17+ from pathlib import Path
1618
1719
1820@pytest .fixture (name = "_mock_database" )
19- def mock_database () -> Iterator [VuforiaDatabase ]:
21+ def mock_database () -> Generator [VuforiaDatabase , None , None ]:
2022 """
2123 Yield a mock ``VuforiaDatabase``.
2224 """
@@ -29,7 +31,7 @@ def mock_database() -> Iterator[VuforiaDatabase]:
2931@pytest .fixture ()
3032def vws_client (_mock_database : VuforiaDatabase ) -> VWS :
3133 """
32- Yield a VWS client which connects to a mock database.
34+ A VWS client which connects to a mock database.
3335 """
3436 return VWS (
3537 server_access_key = _mock_database .server_access_key ,
@@ -40,9 +42,33 @@ def vws_client(_mock_database: VuforiaDatabase) -> VWS:
4042@pytest .fixture ()
4143def cloud_reco_client (_mock_database : VuforiaDatabase ) -> CloudRecoService :
4244 """
43- Yield a ``CloudRecoService`` client which connects to a mock database.
45+ A ``CloudRecoService`` client which connects to a mock database.
4446 """
4547 return CloudRecoService (
4648 client_access_key = _mock_database .client_access_key ,
4749 client_secret_key = _mock_database .client_secret_key ,
4850 )
51+
52+
53+ @pytest .fixture ()
54+ def image_file (
55+ high_quality_image : io .BytesIO ,
56+ tmp_path : Path ,
57+ ) -> Generator [io .BufferedRandom , None , None ]:
58+ """An image file object."""
59+ file = tmp_path / "image.jpg"
60+ file .touch ()
61+ with file .open ("r+b" ) as fileobj :
62+ buffer = high_quality_image .getvalue ()
63+ fileobj .write (buffer )
64+ yield fileobj
65+
66+
67+ @pytest .fixture (params = ["high_quality_image" , "image_file" ])
68+ def image (
69+ request : pytest .FixtureRequest ,
70+ ) -> BinaryIO :
71+ """An image in any of the types that the API accepts."""
72+ result = request .getfixturevalue (request .param )
73+ assert isinstance (result , io .BytesIO | io .BufferedRandom )
74+ return result
0 commit comments