Skip to content

Commit 88e1d77

Browse files
adamtheturtleclaude
andcommitted
Parametrize custom timeout tests
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 90c8285 commit 88e1d77

File tree

2 files changed

+22
-112
lines changed

2 files changed

+22
-112
lines changed

tests/test_query.py

Lines changed: 11 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -62,81 +62,29 @@ def test_default_timeout() -> None:
6262
assert cloud_reco_client.request_timeout_seconds == expected
6363

6464
@staticmethod
65-
def test_custom_timeout(image: io.BytesIO | BinaryIO) -> None:
66-
"""It is possible to set a custom request timeout as a float."""
67-
with MockVWS() as mock:
68-
database = VuforiaDatabase()
69-
mock.add_database(database=database)
70-
vws_client = VWS(
71-
server_access_key=database.server_access_key,
72-
server_secret_key=database.server_secret_key,
73-
)
74-
custom_timeout = 60.5
75-
cloud_reco_client = CloudRecoService(
76-
client_access_key=database.client_access_key,
77-
client_secret_key=database.client_secret_key,
78-
request_timeout_seconds=custom_timeout,
79-
)
80-
assert cloud_reco_client.request_timeout_seconds == custom_timeout
81-
82-
# Verify requests work with the custom timeout
83-
target_id = vws_client.add_target(
84-
name="x",
85-
width=1,
86-
image=image,
87-
active_flag=True,
88-
application_metadata=None,
89-
)
90-
vws_client.wait_for_target_processed(target_id=target_id)
91-
matches = cloud_reco_client.query(image=image)
92-
assert len(matches) == 1
93-
94-
@staticmethod
95-
def test_custom_timeout_int(image: io.BytesIO | BinaryIO) -> None:
96-
"""It is possible to set a custom request timeout as an int."""
97-
with MockVWS() as mock:
98-
database = VuforiaDatabase()
99-
mock.add_database(database=database)
100-
vws_client = VWS(
101-
server_access_key=database.server_access_key,
102-
server_secret_key=database.server_secret_key,
103-
)
104-
custom_timeout = 60
105-
cloud_reco_client = CloudRecoService(
106-
client_access_key=database.client_access_key,
107-
client_secret_key=database.client_secret_key,
108-
request_timeout_seconds=custom_timeout,
109-
)
110-
assert cloud_reco_client.request_timeout_seconds == custom_timeout
111-
112-
target_id = vws_client.add_target(
113-
name="x",
114-
width=1,
115-
image=image,
116-
active_flag=True,
117-
application_metadata=None,
118-
)
119-
vws_client.wait_for_target_processed(target_id=target_id)
120-
matches = cloud_reco_client.query(image=image)
121-
assert len(matches) == 1
122-
123-
@staticmethod
124-
def test_custom_timeout_tuple(image: io.BytesIO | BinaryIO) -> None:
125-
"""It is possible to set separate connect and read timeouts."""
65+
@pytest.mark.parametrize(
66+
argnames="custom_timeout",
67+
argvalues=[60.5, 60, (5.0, 30.0)],
68+
)
69+
def test_custom_timeout(
70+
image: io.BytesIO | BinaryIO,
71+
custom_timeout: int | float | tuple[float, float], # noqa: PYI041
72+
) -> None:
73+
"""It is possible to set a custom request timeout."""
12674
with MockVWS() as mock:
12775
database = VuforiaDatabase()
12876
mock.add_database(database=database)
12977
vws_client = VWS(
13078
server_access_key=database.server_access_key,
13179
server_secret_key=database.server_secret_key,
13280
)
133-
custom_timeout = (5.0, 30.0)
13481
cloud_reco_client = CloudRecoService(
13582
client_access_key=database.client_access_key,
13683
client_secret_key=database.client_secret_key,
13784
request_timeout_seconds=custom_timeout,
13885
)
139-
assert cloud_reco_client.request_timeout_seconds == custom_timeout
86+
expected = custom_timeout
87+
assert cloud_reco_client.request_timeout_seconds == expected
14088

14189
target_id = vws_client.add_target(
14290
name="x",

tests/test_vws.py

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -111,63 +111,25 @@ def test_default_timeout() -> None:
111111
assert vws_client.request_timeout_seconds == expected
112112

113113
@staticmethod
114-
def test_custom_timeout(image: io.BytesIO | BinaryIO) -> None:
115-
"""It is possible to set a custom request timeout as a float."""
116-
with MockVWS() as mock:
117-
database = VuforiaDatabase()
118-
mock.add_database(database=database)
119-
custom_timeout = 60.5
120-
vws_client = VWS(
121-
server_access_key=database.server_access_key,
122-
server_secret_key=database.server_secret_key,
123-
request_timeout_seconds=custom_timeout,
124-
)
125-
assert vws_client.request_timeout_seconds == custom_timeout
126-
127-
# Verify requests work with the custom timeout
128-
vws_client.add_target(
129-
name="x",
130-
width=1,
131-
image=image,
132-
active_flag=True,
133-
application_metadata=None,
134-
)
135-
136-
@staticmethod
137-
def test_custom_timeout_int(image: io.BytesIO | BinaryIO) -> None:
138-
"""It is possible to set a custom request timeout as an int."""
139-
with MockVWS() as mock:
140-
database = VuforiaDatabase()
141-
mock.add_database(database=database)
142-
custom_timeout = 60
143-
vws_client = VWS(
144-
server_access_key=database.server_access_key,
145-
server_secret_key=database.server_secret_key,
146-
request_timeout_seconds=custom_timeout,
147-
)
148-
assert vws_client.request_timeout_seconds == custom_timeout
149-
150-
vws_client.add_target(
151-
name="x",
152-
width=1,
153-
image=image,
154-
active_flag=True,
155-
application_metadata=None,
156-
)
157-
158-
@staticmethod
159-
def test_custom_timeout_tuple(image: io.BytesIO | BinaryIO) -> None:
160-
"""It is possible to set separate connect and read timeouts."""
114+
@pytest.mark.parametrize(
115+
argnames="custom_timeout",
116+
argvalues=[60.5, 60, (5.0, 30.0)],
117+
)
118+
def test_custom_timeout(
119+
image: io.BytesIO | BinaryIO,
120+
custom_timeout: int | float | tuple[float, float], # noqa: PYI041
121+
) -> None:
122+
"""It is possible to set a custom request timeout."""
161123
with MockVWS() as mock:
162124
database = VuforiaDatabase()
163125
mock.add_database(database=database)
164-
custom_timeout = (5.0, 30.0)
165126
vws_client = VWS(
166127
server_access_key=database.server_access_key,
167128
server_secret_key=database.server_secret_key,
168129
request_timeout_seconds=custom_timeout,
169130
)
170-
assert vws_client.request_timeout_seconds == custom_timeout
131+
expected = custom_timeout
132+
assert vws_client.request_timeout_seconds == expected
171133

172134
vws_client.add_target(
173135
name="x",

0 commit comments

Comments
 (0)