Skip to content

Commit 2133d63

Browse files
committed
Merge remote-tracking branch 'origin/master' into fewer-preps
2 parents 1b38a64 + 12b88a6 commit 2133d63

15 files changed

+101
-78
lines changed

ci/run_script.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def run_test(test_filename: str) -> None:
2222
str(path),
2323
'--cov=src',
2424
'--cov=tests',
25-
]
25+
],
2626
)
2727
sys.exit(result)
2828

dev-requirements.txt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
autoflake==1.1
22
check-manifest==0.36
3-
codecov==2.0.13 # Upload coverage data
3+
codecov==2.0.15 # Upload coverage data
44
dodgy==0.1.9 # Look for uploaded secrets
55
flake8==3.5.0 # Lint
6-
flake8-quotes==0.13.0 # Require single quotes
7-
freezegun==0.3.9 # Freeze time in tests
8-
hypothesis==3.44.16 # Generate test cases
9-
isort==4.2.15 # Lint imports
10-
mypy==0.560 # Type checking
6+
flake8-commas==2.0.0 # Require silicon valley commas
7+
flake8-quotes==0.14.0 # Require single quotes
8+
freezegun==0.3.10 # Freeze time in tests
9+
hypothesis==3.50.2 # Generate test cases
10+
isort==4.3.4 # Lint imports
11+
mypy==0.570 # Type checking
1112
pip_check_reqs==2.0.1
1213
pydocstyle==2.1.1 # Lint docstrings
1314
pyenchant==2.0.0 # Bindings for a spellchecking sytem
14-
pylint==1.8.1 # Lint
15+
pylint==1.8.3 # Lint
1516
pyroma==2.3 # Packaging best practices checker
1617
pytest-cov==2.5.1 # Measure code coverage
1718
pytest-envfiles==0.1.0 # Use files for environment variables for tests
18-
pytest==3.3.2 # Test runners
19+
pytest==3.4.2 # Test runners
1920
timeout-decorator==0.4.0 # Decorate functions to time out.
2021
vulture==0.26
21-
yapf==0.20.1 # Automatic formatting for Python
22+
yapf==0.21.0 # Automatic formatting for Python

pylintrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ confidence=
5555
# either give multiple identifier separated by comma (,) or put this option
5656
# multiple time (only on the command line, not in the configuration file where
5757
# it should appear only once). See also the "--disable" option for examples.
58-
enable=spelling
58+
enable=
59+
spelling,
60+
useless-suppression,
5961

6062
# Disable the message, report, category or checker with the given id(s). You
6163
# can either give multiple identifiers separated by comma (,) or put this

src/mock_vws/_mock_web_query_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def decorator(method: Callable[..., str]) -> Callable[..., str]:
4848
route_name=method.__name__,
4949
path_pattern=path_pattern,
5050
http_methods=http_methods,
51-
)
51+
),
5252
)
5353

5454
return method

src/mock_vws/_mock_web_services_api.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def set_content_length_header(
9797
wrapped: Callable[..., str],
9898
instance: 'MockVuforiaWebServicesAPI', # pylint: disable=unused-argument
9999
args: Tuple[_RequestObjectProxy, _Context],
100-
kwargs: Dict
100+
kwargs: Dict,
101101
) -> str:
102102
"""
103103
Set the `Content-Length` header.
@@ -155,7 +155,7 @@ def decorator(method: Callable[..., str]) -> Callable[..., str]:
155155
route_name=method.__name__,
156156
path_pattern=path_pattern,
157157
http_methods=http_methods,
158-
)
158+
),
159159
)
160160

161161
key_validator = validate_keys(
@@ -287,7 +287,7 @@ def status(self) -> str:
287287
target is for detection.
288288
"""
289289
processing_time = datetime.timedelta(
290-
seconds=self._processing_time_seconds
290+
seconds=self._processing_time_seconds,
291291
)
292292

293293
time_since_change = datetime.datetime.now() - self.last_modified_date
@@ -312,7 +312,7 @@ def tracking_rating(self) -> int:
312312
pre_rating_time = datetime.timedelta(
313313
# That this is half of the total processing time is unrealistic.
314314
# In VWS it is not a constant percentage.
315-
seconds=self._processing_time_seconds / 2
315+
seconds=self._processing_time_seconds / 2,
316316
)
317317

318318
time_since_upload = datetime.datetime.now() - self.upload_date
@@ -474,29 +474,29 @@ def database_summary(
474474
target for target in self.targets
475475
if target.status == TargetStatuses.SUCCESS.value
476476
and target.active_flag
477-
]
477+
],
478478
)
479479

480480
failed_images = len(
481481
[
482482
target for target in self.targets
483483
if target.status == TargetStatuses.FAILED.value
484-
]
484+
],
485485
)
486486

487487
inactive_images = len(
488488
[
489489
target for target in self.targets
490490
if target.status == TargetStatuses.SUCCESS.value
491491
and not target.active_flag
492-
]
492+
],
493493
)
494494

495495
processing_images = len(
496496
[
497497
target for target in self.targets
498498
if target.status == TargetStatuses.PROCESSING.value
499-
]
499+
],
500500
)
501501

502502
body = {
@@ -573,7 +573,7 @@ def get_duplicates(
573573
self,
574574
request: _RequestObjectProxy, # pylint: disable=unused-argument
575575
context: _Context, # pylint: disable=unused-argument
576-
target: Target, # pylint: disable=unused-argument
576+
target: Target,
577577
) -> str:
578578
"""
579579
Get targets which may be considered duplicates of a given target.

src/mock_vws/_validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def authorization_header( # pylint: disable=too-many-arguments
4141
content: bytes,
4242
content_type: str,
4343
date: str,
44-
request_path: str
44+
request_path: str,
4545
) -> bytes:
4646
"""
4747
Return an `Authorization` header which can be used for a request made to

tests/mock_vws/conftest.py

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
pytest_plugins = [ # pylint: disable=invalid-name
2424
'tests.mock_vws.fixtures.prepared_requests',
2525
'tests.mock_vws.fixtures.images',
26+
'tests.mock_vws.fixtures.credentials',
2627
]
2728

2829

@@ -55,8 +56,8 @@ def _delete_all_targets(database_keys: VuforiaDatabaseKeys) -> None:
5556

5657
@pytest.fixture()
5758
def target_id(
58-
png_rgb_success: io.BytesIO, # pylint: disable=redefined-outer-name
59-
vuforia_database_keys: VuforiaDatabaseKeys, # noqa: E501 pylint: disable=redefined-outer-name
59+
png_rgb_success: io.BytesIO,
60+
vuforia_database_keys: VuforiaDatabaseKeys,
6061
) -> str:
6162
"""
6263
Return the target ID of a target in the database.
@@ -84,7 +85,7 @@ def target_id(
8485
@pytest.fixture(params=[True, False], ids=['Real Vuforia', 'Mock Vuforia'])
8586
def verify_mock_vuforia(
8687
request: SubRequest,
87-
vuforia_database_keys: VuforiaDatabaseKeys, # noqa: E501 pylint: disable=redefined-outer-name
88+
vuforia_database_keys: VuforiaDatabaseKeys,
8889
) -> Generator:
8990
"""
9091
Test functions which use this fixture are run twice. Once with the real
@@ -121,7 +122,7 @@ def verify_mock_vuforia(
121122
@pytest.fixture(params=[True, False], ids=['Real Vuforia', 'Mock Vuforia'])
122123
def verify_mock_vuforia_inactive(
123124
request: SubRequest,
124-
inactive_database_keys: VuforiaDatabaseKeys, # noqa: E501 pylint: disable=redefined-outer-name
125+
inactive_database_keys: VuforiaDatabaseKeys,
125126
) -> Generator:
126127
"""
127128
Test functions which use this fixture are run twice. Once with the real
@@ -167,44 +168,13 @@ def verify_mock_vuforia_inactive(
167168
'_target_list',
168169
'_target_summary',
169170
'_update_target',
170-
]
171+
],
171172
)
172173
def endpoint(request: SubRequest) -> TargetAPIEndpoint:
173174
"""
174175
Return details of an endpoint.
175176
"""
176177
endpoint_fixture: TargetAPIEndpoint = request.getfixturevalue(
177-
request.param
178+
request.param,
178179
)
179180
return endpoint_fixture
180-
181-
182-
@pytest.fixture()
183-
def vuforia_database_keys() -> VuforiaDatabaseKeys:
184-
"""
185-
Return VWS credentials from environment variables.
186-
"""
187-
credentials: VuforiaDatabaseKeys = VuforiaDatabaseKeys(
188-
database_name=os.environ['VUFORIA_TARGET_MANAGER_DATABASE_NAME'],
189-
server_access_key=os.environ['VUFORIA_SERVER_ACCESS_KEY'],
190-
server_secret_key=os.environ['VUFORIA_SERVER_SECRET_KEY'],
191-
client_access_key=os.environ['VUFORIA_CLIENT_ACCESS_KEY'],
192-
client_secret_key=os.environ['VUFORIA_CLIENT_SECRET_KEY'],
193-
)
194-
return credentials
195-
196-
197-
@pytest.fixture()
198-
def inactive_database_keys() -> VuforiaDatabaseKeys:
199-
"""
200-
Return VWS credentials for an inactive project from environment variables.
201-
"""
202-
credentials: VuforiaDatabaseKeys = VuforiaDatabaseKeys(
203-
database_name=os.
204-
environ['INACTIVE_VUFORIA_TARGET_MANAGER_DATABASE_NAME'],
205-
server_access_key=os.environ['INACTIVE_VUFORIA_SERVER_ACCESS_KEY'],
206-
server_secret_key=os.environ['INACTIVE_VUFORIA_SERVER_SECRET_KEY'],
207-
client_access_key=os.environ['INACTIVE_VUFORIA_SERVER_ACCESS_KEY'],
208-
client_secret_key=os.environ['INACTIVE_VUFORIA_SERVER_SECRET_KEY'],
209-
)
210-
return credentials
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
Fixtures for credentials for Vuforia databases.
3+
"""
4+
5+
import os
6+
7+
import pytest
8+
9+
from tests.mock_vws.utils import VuforiaDatabaseKeys
10+
11+
12+
@pytest.fixture()
13+
def vuforia_database_keys() -> VuforiaDatabaseKeys:
14+
"""
15+
Return VWS credentials from environment variables.
16+
"""
17+
credentials: VuforiaDatabaseKeys = VuforiaDatabaseKeys(
18+
database_name=os.environ['VUFORIA_TARGET_MANAGER_DATABASE_NAME'],
19+
server_access_key=os.environ['VUFORIA_SERVER_ACCESS_KEY'],
20+
server_secret_key=os.environ['VUFORIA_SERVER_SECRET_KEY'],
21+
client_access_key=os.environ['VUFORIA_CLIENT_ACCESS_KEY'],
22+
client_secret_key=os.environ['VUFORIA_CLIENT_SECRET_KEY'],
23+
)
24+
return credentials
25+
26+
27+
@pytest.fixture()
28+
def inactive_database_keys() -> VuforiaDatabaseKeys:
29+
"""
30+
Return VWS credentials for an inactive project from environment variables.
31+
"""
32+
credentials: VuforiaDatabaseKeys = VuforiaDatabaseKeys(
33+
database_name=os.
34+
environ['INACTIVE_VUFORIA_TARGET_MANAGER_DATABASE_NAME'],
35+
server_access_key=os.environ['INACTIVE_VUFORIA_SERVER_ACCESS_KEY'],
36+
server_secret_key=os.environ['INACTIVE_VUFORIA_SERVER_SECRET_KEY'],
37+
client_access_key=os.environ['INACTIVE_VUFORIA_SERVER_ACCESS_KEY'],
38+
client_secret_key=os.environ['INACTIVE_VUFORIA_SERVER_SECRET_KEY'],
39+
)
40+
return credentials

tests/mock_vws/fixtures/prepared_requests.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Fixtures which prepare requests.
33
"""
44

5+
import base64
6+
import io
57
import json
68
from typing import Any, Dict
79
from urllib.parse import urljoin
@@ -26,12 +28,19 @@
2628
@pytest.fixture()
2729
def _add_target(
2830
vuforia_database_keys: VuforiaDatabaseKeys,
31+
png_rgb: io.BytesIO,
2932
) -> TargetAPIEndpoint:
3033
"""
3134
Return details of the endpoint for adding a target.
3235
"""
36+
image_data = png_rgb.read()
37+
image_data_encoded = base64.b64encode(image_data).decode('ascii')
3338
date = rfc_1123_date()
34-
data: Dict[str, Any] = {}
39+
data: Dict[str, Any] = {
40+
'name': 'example_name',
41+
'width': 1,
42+
'image': image_data_encoded,
43+
}
3544
request_path = '/targets'
3645
content_type = 'application/json'
3746
method = POST
@@ -66,10 +75,8 @@ def _add_target(
6675
prepared_request = request.prepare() # type: ignore
6776

6877
return TargetAPIEndpoint(
69-
# We expect a bad request error because we have not given the required
70-
# JSON body elements.
71-
successful_headers_status_code=codes.BAD_REQUEST,
72-
successful_headers_result_code=ResultCodes.FAIL,
78+
successful_headers_status_code=codes.CREATED,
79+
successful_headers_result_code=ResultCodes.TARGET_CREATED,
7380
prepared_request=prepared_request,
7481
access_key=access_key,
7582
secret_key=secret_key,
@@ -397,7 +404,7 @@ def _update_target(
397404
)
398405
data: Dict[str, Any] = {}
399406
request_path = f'/targets/{target_id}'
400-
content = bytes(str(data), encoding='utf-8')
407+
content = bytes(json.dumps(data), encoding='utf-8')
401408
content_type = 'application/json'
402409

403410
date = rfc_1123_date()

tests/mock_vws/test_add_target.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class TestContentTypes:
6060
'Documented Content-Type',
6161
'Undocumented Content-Type',
6262
'Empty',
63-
]
63+
],
6464
)
6565
def test_content_types(
6666
self,
@@ -203,7 +203,8 @@ class TestTargetName:
203203
'name', [
204204
'a',
205205
'a' * 64,
206-
], ids=['Short name', 'Long name']
206+
],
207+
ids=['Short name', 'Long name'],
207208
)
208209
def test_name_valid(
209210
self,

0 commit comments

Comments
 (0)