Skip to content

Commit 8aa1f86

Browse files
committed
Merge remote-tracking branch 'origin/master' into query-2
2 parents 9dd6a8f + 4ead3ad commit 8aa1f86

File tree

4 files changed

+116
-107
lines changed

4 files changed

+116
-107
lines changed

tests/conftest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ def _mock_database() -> Iterator[VuforiaDatabase]:
2424

2525

2626
@pytest.fixture()
27-
def client(_mock_database: VuforiaDatabase) -> Iterator[VWS]:
27+
def vws_client(_mock_database: VuforiaDatabase) -> Iterator[VWS]:
2828
"""
29-
# TODO rename this fixture
30-
3129
Yield a VWS client which connects to a mock.
3230
"""
3331
vws_client = VWS(

tests/test_exceptions.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _make_image_file(
6060
return image_buffer
6161

6262

63-
def test_image_too_large(client: VWS) -> None:
63+
def test_image_too_large(vws_client: VWS) -> None:
6464
"""
6565
When giving an image which is too large, an ``ImageTooLarge`` exception is
6666
raised.
@@ -75,18 +75,18 @@ def test_image_too_large(client: VWS) -> None:
7575
)
7676

7777
with pytest.raises(ImageTooLarge) as exc:
78-
client.add_target(name='x', width=1, image=png_too_large)
78+
vws_client.add_target(name='x', width=1, image=png_too_large)
7979

8080
assert exc.value.response.status_code == codes.UNPROCESSABLE_ENTITY
8181

8282

83-
def test_invalid_given_id(client: VWS) -> None:
83+
def test_invalid_given_id(vws_client: VWS) -> None:
8484
"""
8585
Giving an invalid ID to a helper which requires a target ID to be given
8686
causes an ``UnknownTarget`` exception to be raised.
8787
"""
8888
with pytest.raises(UnknownTarget) as exc:
89-
client.delete_target(target_id='x')
89+
vws_client.delete_target(target_id='x')
9090
assert exc.value.response.status_code == codes.NOT_FOUND
9191

9292

@@ -102,13 +102,13 @@ def test_fail(high_quality_image: io.BytesIO) -> None:
102102
A ``Fail`` exception is raised when the server access key does not exist.
103103
"""
104104
with MockVWS():
105-
client = VWS(
105+
vws_client = VWS(
106106
server_access_key='a',
107107
server_secret_key='a',
108108
)
109109

110110
with pytest.raises(Fail) as exc:
111-
client.add_target(
111+
vws_client.add_target(
112112
name='x',
113113
width=1,
114114
image=high_quality_image,
@@ -117,47 +117,50 @@ def test_fail(high_quality_image: io.BytesIO) -> None:
117117
assert exc.value.response.status_code == codes.BAD_REQUEST
118118

119119

120-
def test_bad_image(client: VWS) -> None:
120+
def test_bad_image(vws_client: VWS) -> None:
121121
"""
122122
A ``BadImage`` exception is raised when a non-image is given.
123123
"""
124124
not_an_image = io.BytesIO(b'Not an image')
125125
with pytest.raises(BadImage) as exc:
126-
client.add_target(name='x', width=1, image=not_an_image)
126+
vws_client.add_target(name='x', width=1, image=not_an_image)
127127

128128
assert exc.value.response.status_code == codes.UNPROCESSABLE_ENTITY
129129

130130

131131
def test_target_name_exist(
132-
client: VWS,
132+
vws_client: VWS,
133133
high_quality_image: io.BytesIO,
134134
) -> None:
135135
"""
136136
A ``TargetNameExist`` exception is raised after adding two targets with
137137
the same name.
138138
"""
139-
client.add_target(name='x', width=1, image=high_quality_image)
139+
vws_client.add_target(name='x', width=1, image=high_quality_image)
140140
with pytest.raises(TargetNameExist) as exc:
141-
client.add_target(name='x', width=1, image=high_quality_image)
141+
vws_client.add_target(name='x', width=1, image=high_quality_image)
142142

143143
assert exc.value.response.status_code == codes.FORBIDDEN
144144

145145

146-
def test_project_inactive(client: VWS, high_quality_image: io.BytesIO) -> None:
146+
def test_project_inactive(
147+
vws_client: VWS,
148+
high_quality_image: io.BytesIO,
149+
) -> None:
147150
"""
148151
A ``ProjectInactive`` exception is raised if adding a target to an
149152
inactive database.
150153
"""
151154
database = VuforiaDatabase(state=States.PROJECT_INACTIVE)
152155
with MockVWS() as mock:
153156
mock.add_database(database=database)
154-
client = VWS(
157+
vws_client = VWS(
155158
server_access_key=database.server_access_key,
156159
server_secret_key=database.server_secret_key,
157160
)
158161

159162
with pytest.raises(ProjectInactive) as exc:
160-
client.add_target(
163+
vws_client.add_target(
161164
name='x',
162165
width=1,
163166
image=high_quality_image,
@@ -167,35 +170,35 @@ def test_project_inactive(client: VWS, high_quality_image: io.BytesIO) -> None:
167170

168171

169172
def test_target_status_processing(
170-
client: VWS,
173+
vws_client: VWS,
171174
high_quality_image: io.BytesIO,
172175
) -> None:
173176
"""
174177
A ``TargetStatusProcessing`` exception is raised if trying to delete a
175178
target which is processing.
176179
"""
177-
target_id = client.add_target(
180+
target_id = vws_client.add_target(
178181
name='x',
179182
width=1,
180183
image=high_quality_image,
181184
)
182185

183186
with pytest.raises(TargetStatusProcessing) as exc:
184-
client.delete_target(target_id=target_id)
187+
vws_client.delete_target(target_id=target_id)
185188

186189
assert exc.value.response.status_code == codes.FORBIDDEN
187190

188191

189192
def test_metadata_too_large(
190-
client: VWS,
193+
vws_client: VWS,
191194
high_quality_image: io.BytesIO,
192195
) -> None:
193196
"""
194197
A ``MetadataTooLarge`` exception is raised if the metadata given is too
195198
large.
196199
"""
197200
with pytest.raises(MetadataTooLarge) as exc:
198-
client.add_target(
201+
vws_client.add_target(
199202
name='x',
200203
width=1,
201204
image=high_quality_image,
@@ -213,13 +216,13 @@ def test_authentication_failure(high_quality_image: io.BytesIO) -> None:
213216
database = VuforiaDatabase()
214217
with MockVWS() as mock:
215218
mock.add_database(database=database)
216-
client = VWS(
219+
vws_client = VWS(
217220
server_access_key=database.server_access_key,
218221
server_secret_key='a',
219222
)
220223

221224
with pytest.raises(AuthenticationFailure) as exc:
222-
client.add_target(
225+
vws_client.add_target(
223226
name='x',
224227
width=1,
225228
image=high_quality_image,
@@ -229,20 +232,20 @@ def test_authentication_failure(high_quality_image: io.BytesIO) -> None:
229232

230233

231234
def test_target_status_not_success(
232-
client: VWS,
235+
vws_client: VWS,
233236
high_quality_image: io.BytesIO,
234237
) -> None:
235238
"""
236239
A ``TargetStatusNotSuccess`` exception is raised when updating a target
237240
which has a status which is not "Success".
238241
"""
239-
target_id = client.add_target(
242+
target_id = vws_client.add_target(
240243
name='x',
241244
width=1,
242245
image=high_quality_image,
243246
)
244247

245248
with pytest.raises(TargetStatusNotSuccess) as exc:
246-
client.update_target(target_id=target_id)
249+
vws_client.update_target(target_id=target_id)
247250

248251
assert exc.value.response.status_code == codes.FORBIDDEN

tests/test_query.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ def test_no_matches(
3030

3131
def test_match(
3232
self,
33-
client: VWS,
33+
vws_client: VWS,
3434
cloud_reco_client: CloudRecoService,
3535
high_quality_image: io.BytesIO,
3636
) -> None:
3737
"""
3838
XXX
3939
"""
40-
target_id = client.add_target(
40+
target_id = vws_client.add_target(
4141
name='x',
4242
width=1,
4343
image=high_quality_image,
4444
)
45-
client.wait_for_target_processed(target_id=target_id)
45+
vws_client.wait_for_target_processed(target_id=target_id)
4646
[matching_target] = cloud_reco_client.query(image=high_quality_image)
4747
assert matching_target['target_id'] == target_id
4848

@@ -54,55 +54,55 @@ class TestMaxNumResults:
5454

5555
def test_default(
5656
self,
57-
client: VWS,
57+
vws_client: VWS,
5858
cloud_reco_client: CloudRecoService,
5959
high_quality_image: io.BytesIO,
6060
) -> None:
6161
"""
6262
XXX
6363
"""
64-
target_id = client.add_target(
64+
target_id = vws_client.add_target(
6565
name=uuid.uuid4().hex,
6666
width=1,
6767
image=high_quality_image,
6868
)
69-
target_id_2 = client.add_target(
69+
target_id_2 = vws_client.add_target(
7070
name=uuid.uuid4().hex,
7171
width=1,
7272
image=high_quality_image,
7373
)
74-
client.wait_for_target_processed(target_id=target_id)
75-
client.wait_for_target_processed(target_id=target_id_2)
74+
vws_client.wait_for_target_processed(target_id=target_id)
75+
vws_client.wait_for_target_processed(target_id=target_id_2)
7676
matches = cloud_reco_client.query(image=high_quality_image)
7777
assert len(matches) == 1
7878

7979
def test_custom(
8080
self,
81-
client: VWS,
81+
vws_client: VWS,
8282
cloud_reco_client: CloudRecoService,
8383
high_quality_image: io.BytesIO,
8484
) -> None:
8585
"""
8686
XXX
8787
"""
88-
target_id = client.add_target(
88+
target_id = vws_client.add_target(
8989
name=uuid.uuid4().hex,
9090
width=1,
9191
image=high_quality_image,
9292
)
93-
target_id_2 = client.add_target(
93+
target_id_2 = vws_client.add_target(
9494
name=uuid.uuid4().hex,
9595
width=1,
9696
image=high_quality_image,
9797
)
98-
target_id_3 = client.add_target(
98+
target_id_3 = vws_client.add_target(
9999
name=uuid.uuid4().hex,
100100
width=1,
101101
image=high_quality_image,
102102
)
103-
client.wait_for_target_processed(target_id=target_id)
104-
client.wait_for_target_processed(target_id=target_id_2)
105-
client.wait_for_target_processed(target_id=target_id_3)
103+
vws_client.wait_for_target_processed(target_id=target_id)
104+
vws_client.wait_for_target_processed(target_id=target_id_2)
105+
vws_client.wait_for_target_processed(target_id=target_id_3)
106106
matches = cloud_reco_client.query(
107107
image=high_quality_image,
108108
max_num_results=2,

0 commit comments

Comments
 (0)