Skip to content

Commit 5d0a729

Browse files
adamtheturtleclaude
andcommitted
Use vws-python-mock response_delay_seconds for timeout tests
Upgrade vws-python-mock to 2026.2.15 which adds response_delay_seconds parameter. Replace unittest.mock.patch-based timeout simulation with MockVWS(response_delay_seconds=0.5), testing the real timeout mechanism end-to-end. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7123758 commit 5d0a729

File tree

3 files changed

+7
-39
lines changed

3 files changed

+7
-39
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.14",
7878
"types-requests==2.32.4.20260107",
7979
"vulture==2.14",
80-
"vws-python-mock==2025.3.10.1",
80+
"vws-python-mock==2026.2.15",
8181
"vws-test-fixtures==2023.3.5",
8282
"yamlfix==1.19.1",
8383
"zizmor==1.22.0",

tests/test_query.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import io
44
import uuid
55
from typing import BinaryIO
6-
from unittest.mock import patch
76

87
import pytest
98
import requests
@@ -155,8 +154,7 @@ def test_timeout_raises_on_slow_response(
155154
image: io.BytesIO | BinaryIO,
156155
) -> None:
157156
"""A short timeout raises an error when the server is slow."""
158-
custom_timeout = 0.1
159-
with MockVWS() as mock:
157+
with MockVWS(response_delay_seconds=0.5) as mock:
160158
database = VuforiaDatabase()
161159
mock.add_database(database=database)
162160
vws_client = VWS(
@@ -166,7 +164,7 @@ def test_timeout_raises_on_slow_response(
166164
cloud_reco_client = CloudRecoService(
167165
client_access_key=database.client_access_key,
168166
client_secret_key=database.client_secret_key,
169-
request_timeout_seconds=custom_timeout,
167+
request_timeout_seconds=0.1,
170168
)
171169

172170
target_id = vws_client.add_target(
@@ -178,21 +176,7 @@ def test_timeout_raises_on_slow_response(
178176
)
179177
vws_client.wait_for_target_processed(target_id=target_id)
180178

181-
def slow_request(
182-
**kwargs: float | None,
183-
) -> requests.Response:
184-
"""Simulate a server that is too slow to respond."""
185-
assert kwargs["timeout"] == custom_timeout
186-
raise requests.exceptions.Timeout
187-
188-
with (
189-
patch.object(
190-
target=requests,
191-
attribute="request",
192-
side_effect=slow_request,
193-
),
194-
pytest.raises(expected_exception=requests.exceptions.Timeout),
195-
):
179+
with pytest.raises(expected_exception=requests.exceptions.Timeout):
196180
cloud_reco_client.query(image=image)
197181

198182

tests/test_vws.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import secrets
77
import uuid
88
from typing import BinaryIO
9-
from unittest.mock import patch
109

1110
import pytest
1211
import requests
@@ -183,31 +182,16 @@ def test_timeout_raises_on_slow_response(
183182
image: io.BytesIO | BinaryIO,
184183
) -> None:
185184
"""A short timeout raises an error when the server is slow."""
186-
custom_timeout = 0.1
187-
with MockVWS() as mock:
185+
with MockVWS(response_delay_seconds=0.5) as mock:
188186
database = VuforiaDatabase()
189187
mock.add_database(database=database)
190188
vws_client = VWS(
191189
server_access_key=database.server_access_key,
192190
server_secret_key=database.server_secret_key,
193-
request_timeout_seconds=custom_timeout,
191+
request_timeout_seconds=0.1,
194192
)
195193

196-
def slow_request(
197-
**kwargs: float | None,
198-
) -> requests.Response:
199-
"""Simulate a server that is too slow to respond."""
200-
assert kwargs["timeout"] == custom_timeout
201-
raise requests.exceptions.Timeout
202-
203-
with (
204-
patch.object(
205-
target=requests,
206-
attribute="request",
207-
side_effect=slow_request,
208-
),
209-
pytest.raises(expected_exception=requests.exceptions.Timeout),
210-
):
194+
with pytest.raises(expected_exception=requests.exceptions.Timeout):
211195
vws_client.add_target(
212196
name="x",
213197
width=1,

0 commit comments

Comments
 (0)