Skip to content

Commit bdaacd8

Browse files
committed
Bump mock-vws and use sleep_fn in timeout tests
1 parent 80c214b commit bdaacd8

File tree

3 files changed

+16
-66
lines changed

3 files changed

+16
-66
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ optional-dependencies.dev = [
7777
"ty==0.0.16",
7878
"types-requests==2.32.4.20260107",
7979
"vulture==2.14",
80-
"vws-python-mock==2026.2.15",
80+
"vws-python-mock==2026.2.15.4",
8181
"vws-test-fixtures==2023.3.5",
8282
"yamlfix==1.19.1",
8383
"zizmor==1.22.0",

tests/test_query.py

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for the ``CloudRecoService`` querying functionality."""
22

3+
import datetime
34
import io
45
import uuid
56
from typing import BinaryIO
@@ -63,8 +64,13 @@ def test_default_timeout(
6364
timeout.
6465
"""
6566
with (
66-
freeze_time(auto_tick_seconds=1),
67-
MockVWS(response_delay_seconds=response_delay_seconds) as mock,
67+
freeze_time() as frozen_datetime,
68+
MockVWS(
69+
response_delay_seconds=response_delay_seconds,
70+
sleep_fn=lambda seconds: frozen_datetime.tick(
71+
delta=datetime.timedelta(seconds=seconds),
72+
),
73+
) as mock,
6874
):
6975
database = VuforiaDatabase()
7076
mock.add_database(database=database)
@@ -82,40 +88,6 @@ def test_default_timeout(
8288
matches = cloud_reco_client.query(image=image)
8389
assert not matches
8490

85-
@staticmethod
86-
@pytest.mark.parametrize(
87-
argnames="custom_timeout",
88-
argvalues=[60.5, 60.0, (5.0, 30.0)],
89-
)
90-
def test_custom_timeout(
91-
image: io.BytesIO | BinaryIO,
92-
custom_timeout: float | tuple[float, float],
93-
) -> None:
94-
"""It is possible to set a custom request timeout."""
95-
with MockVWS() as mock:
96-
database = VuforiaDatabase()
97-
mock.add_database(database=database)
98-
vws_client = VWS(
99-
server_access_key=database.server_access_key,
100-
server_secret_key=database.server_secret_key,
101-
)
102-
cloud_reco_client = CloudRecoService(
103-
client_access_key=database.client_access_key,
104-
client_secret_key=database.client_secret_key,
105-
request_timeout_seconds=custom_timeout,
106-
)
107-
108-
target_id = vws_client.add_target(
109-
name="x",
110-
width=1,
111-
image=image,
112-
active_flag=True,
113-
application_metadata=None,
114-
)
115-
vws_client.wait_for_target_processed(target_id=target_id)
116-
matches = cloud_reco_client.query(image=image)
117-
assert len(matches) == 1
118-
11991
@staticmethod
12092
def test_timeout_raises_on_slow_response(
12193
image: io.BytesIO | BinaryIO,

tests/test_vws.py

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,13 @@ def test_default_timeout(
111111
timeout.
112112
"""
113113
with (
114-
freeze_time(auto_tick_seconds=1),
115-
MockVWS(response_delay_seconds=response_delay_seconds) as mock,
114+
freeze_time() as frozen_datetime,
115+
MockVWS(
116+
response_delay_seconds=response_delay_seconds,
117+
sleep_fn=lambda seconds: frozen_datetime.tick(
118+
delta=datetime.timedelta(seconds=seconds),
119+
),
120+
) as mock,
116121
):
117122
database = VuforiaDatabase()
118123
mock.add_database(database=database)
@@ -141,33 +146,6 @@ def test_default_timeout(
141146
application_metadata=None,
142147
)
143148

144-
@staticmethod
145-
@pytest.mark.parametrize(
146-
argnames="custom_timeout",
147-
argvalues=[60.5, 60.0, (5.0, 30.0)],
148-
)
149-
def test_custom_timeout(
150-
image: io.BytesIO | BinaryIO,
151-
custom_timeout: float | tuple[float, float],
152-
) -> None:
153-
"""It is possible to set a custom request timeout."""
154-
with MockVWS() as mock:
155-
database = VuforiaDatabase()
156-
mock.add_database(database=database)
157-
vws_client = VWS(
158-
server_access_key=database.server_access_key,
159-
server_secret_key=database.server_secret_key,
160-
request_timeout_seconds=custom_timeout,
161-
)
162-
163-
vws_client.add_target(
164-
name="x",
165-
width=1,
166-
image=image,
167-
active_flag=True,
168-
application_metadata=None,
169-
)
170-
171149
@staticmethod
172150
def test_timeout_raises_on_slow_response(
173151
image: io.BytesIO | BinaryIO,

0 commit comments

Comments
 (0)