Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions admin/create_secrets_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
driver = webdriver.Chrome()
file = files_to_create[-1]
sys.stdout.write(f"Creating database {file.name}\n")
time = datetime.datetime.now(tz=datetime.UTC).strftime("%Y-%m-%d-%H-%M-%S")
time = datetime.datetime.now(tz=datetime.UTC).strftime(
format="%Y-%m-%d-%H-%M-%S",
)
license_name = f"my-license-{time}"
database_name = f"my-database-{time}"

Expand Down Expand Up @@ -85,7 +87,7 @@
driver = None

file_contents = textwrap.dedent(
f"""\
text=f"""\
VUFORIA_TARGET_MANAGER_DATABASE_NAME={database_details["database_name"]}
VUFORIA_SERVER_ACCESS_KEY={database_details["server_access_key"]}
VUFORIA_SERVER_SECRET_KEY={database_details["server_secret_key"]}
Expand Down
2 changes: 1 addition & 1 deletion ci/custom_linters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def _ci_patterns(*, repository_root: Path) -> set[str]:
Return the CI patterns given in the CI configuration file.
"""
ci_file = repository_root / ".github" / "workflows" / "ci.yml"
github_workflow_config = yaml.safe_load(ci_file.read_text())
github_workflow_config = yaml.safe_load(stream=ci_file.read_text())
matrix = github_workflow_config["jobs"]["build"]["strategy"]["matrix"]
ci_pattern_list = matrix["ci_pattern"]
ci_patterns = set(ci_pattern_list)
Expand Down
6 changes: 3 additions & 3 deletions src/mock_vws/_query_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_query_match_response_text(
parser = MultiPartParser()
fields, files = parser.parse(
stream=io.BytesIO(initial_bytes=request_body),
boundary=boundary.encode("utf-8"),
boundary=boundary.encode(encoding="utf-8"),
content_length=len(request_body),
)

Expand Down Expand Up @@ -103,8 +103,8 @@ def get_query_match_response_text(
application_metadata = None
else:
application_metadata = base64.b64encode(
decode_base64(encoded_data=target.application_metadata),
).decode("ascii")
s=decode_base64(encoded_data=target.application_metadata),
).decode(encoding="ascii")
target_data = {
"target_timestamp": int(target_timestamp),
"name": target.name,
Expand Down
2 changes: 1 addition & 1 deletion src/mock_vws/_query_validators/fields_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def validate_extra_fields(
parser = MultiPartParser()
fields, files = parser.parse(
stream=io.BytesIO(initial_bytes=request_body),
boundary=boundary.encode("utf-8"),
boundary=boundary.encode(encoding="utf-8"),
content_length=len(request_body),
)
parsed_keys = fields.keys() | files.keys()
Expand Down
10 changes: 5 additions & 5 deletions src/mock_vws/_query_validators/image_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def validate_image_field_given(
parser = MultiPartParser()
_, files = parser.parse(
stream=io.BytesIO(initial_bytes=request_body),
boundary=boundary.encode("utf-8"),
boundary=boundary.encode(encoding="utf-8"),
content_length=len(request_body),
)
if files.get("image") is not None:
Expand Down Expand Up @@ -74,7 +74,7 @@ def validate_image_file_size(
parser = MultiPartParser()
_, files = parser.parse(
stream=io.BytesIO(initial_bytes=request_body),
boundary=boundary.encode("utf-8"),
boundary=boundary.encode(encoding="utf-8"),
content_length=len(request_body),
)
image_part = files["image"]
Expand Down Expand Up @@ -116,7 +116,7 @@ def validate_image_dimensions(
parser = MultiPartParser()
_, files = parser.parse(
stream=io.BytesIO(initial_bytes=request_body),
boundary=boundary.encode("utf-8"),
boundary=boundary.encode(encoding="utf-8"),
content_length=len(request_body),
)
image_part = files["image"]
Expand Down Expand Up @@ -154,7 +154,7 @@ def validate_image_format(
parser = MultiPartParser()
_, files = parser.parse(
stream=io.BytesIO(initial_bytes=request_body),
boundary=boundary.encode("utf-8"),
boundary=boundary.encode(encoding="utf-8"),
content_length=len(request_body),
)
image_part = files["image"]
Expand Down Expand Up @@ -188,7 +188,7 @@ def validate_image_is_image(
parser = MultiPartParser()
_, files = parser.parse(
stream=io.BytesIO(initial_bytes=request_body),
boundary=boundary.encode("utf-8"),
boundary=boundary.encode(encoding="utf-8"),
content_length=len(request_body),
)
image_part = files["image"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def validate_include_target_data(
parser = MultiPartParser()
fields, _ = parser.parse(
stream=io.BytesIO(initial_bytes=request_body),
boundary=boundary.encode("utf-8"),
boundary=boundary.encode(encoding="utf-8"),
content_length=len(request_body),
)
include_target_data = fields.get("include_target_data", "top")
Expand Down
2 changes: 1 addition & 1 deletion src/mock_vws/_query_validators/num_results_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def validate_max_num_results(
parser = MultiPartParser()
fields, _ = parser.parse(
stream=io.BytesIO(initial_bytes=request_body),
boundary=boundary.encode("utf-8"),
boundary=boundary.encode(encoding="utf-8"),
content_length=len(request_body),
)
max_num_results = fields.get("max_num_results", "1")
Expand Down
2 changes: 1 addition & 1 deletion src/mock_vws/_services_validators/key_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def validate_keys(
route
for route in routes
if re.match(
pattern=re.compile(f"{route.path_pattern}$"),
pattern=re.compile(pattern=f"{route.path_pattern}$"),
string=request_path,
)
and request_method in route.http_methods
Expand Down
4 changes: 2 additions & 2 deletions src/mock_vws/image_matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ def __call__(
2,
0,
1,
).unsqueeze(0)
).unsqueeze(dim=0)
second_image_tensor_batch_dimension = second_image_tensor.permute(
2,
0,
1,
).unsqueeze(0)
).unsqueeze(dim=0)

ssim = StructuralSimilarityIndexMeasure(data_range=1.0)
ssim_value = ssim(
Expand Down
2 changes: 1 addition & 1 deletion src/mock_vws/target_raters.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _get_brisque_target_tracking_rating(*, image_content: bytes) -> int:
image.size[0],
len(image.getbands()),
)
image_tensor = image_tensor.permute(2, 0, 1).unsqueeze(0)
image_tensor = image_tensor.permute(2, 0, 1).unsqueeze(dim=0)
try:
brisque_score = piq.brisque(x=image_tensor, data_range=255)
except (AssertionError, IndexError):
Expand Down
2 changes: 1 addition & 1 deletion tests/mock_vws/test_content_length.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_too_large(endpoint: Endpoint) -> None: # pragma: no cover
An error is given if the given content length is too large.
"""
if not endpoint.prepared_request.headers.get("Content-Type"):
pytest.skip("No Content-Type header for this request")
pytest.skip(reason="No Content-Type header for this request")

url = endpoint.prepared_request.url or ""
netloc = urlparse(url=url).netloc
Expand Down
8 changes: 4 additions & 4 deletions tests/mock_vws/test_flask_app_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def test_exact_match(

pil_image = Image.open(fp=high_quality_image)
re_exported_image = io.BytesIO()
pil_image.save(re_exported_image, format="PNG")
pil_image.save(fp=re_exported_image, format="PNG")

databases_url = _EXAMPLE_URL_FOR_TARGET_MANAGER + "/databases"
requests.post(url=databases_url, json=database.to_dict(), timeout=30)
Expand Down Expand Up @@ -311,7 +311,7 @@ def test_structural_similarity_matcher(

pil_image = Image.open(fp=high_quality_image)
re_exported_image = io.BytesIO()
pil_image.save(re_exported_image, format="PNG")
pil_image.save(fp=re_exported_image, format="PNG")
databases_url = _EXAMPLE_URL_FOR_TARGET_MANAGER + "/databases"
requests.post(url=databases_url, json=database.to_dict(), timeout=30)

Expand Down Expand Up @@ -358,7 +358,7 @@ def test_exact_match(

pil_image = Image.open(fp=high_quality_image)
re_exported_image = io.BytesIO()
pil_image.save(re_exported_image, format="PNG")
pil_image.save(fp=re_exported_image, format="PNG")

databases_url = _EXAMPLE_URL_FOR_TARGET_MANAGER + "/databases"
requests.post(url=databases_url, json=database.to_dict(), timeout=30)
Expand Down Expand Up @@ -410,7 +410,7 @@ def test_structural_similarity_matcher(

pil_image = Image.open(fp=high_quality_image)
re_exported_image = io.BytesIO()
pil_image.save(re_exported_image, format="PNG")
pil_image.save(fp=re_exported_image, format="PNG")

databases_url = _EXAMPLE_URL_FOR_TARGET_MANAGER + "/databases"
requests.post(url=databases_url, json=database.to_dict(), timeout=30)
Expand Down
2 changes: 1 addition & 1 deletion tests/mock_vws/test_get_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_duplicates_not_same(
Target IDs of similar targets are returned.
"""
image_data = high_quality_image
similar_image_data = copy.copy(image_data)
similar_image_data = copy.copy(x=image_data)
similar_image_buffer = io.BytesIO()
pil_similar_image = Image.open(fp=similar_image_data)
# Re-save means similar but not identical.
Expand Down
8 changes: 4 additions & 4 deletions tests/mock_vws/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def test_match_similar(
vws_client.wait_for_target_processed(target_id=target_id_not_matching)

similar_image_buffer = io.BytesIO()
similar_image_data = copy.copy(high_quality_image)
similar_image_data = copy.copy(x=high_quality_image)
pil_similar_image = Image.open(fp=similar_image_data)
# Re-save means similar but not identical.
pil_similar_image.save(similar_image_buffer, format="JPEG")
Expand Down Expand Up @@ -658,7 +658,7 @@ def test_not_base64_encoded_processable(
len(not_base64_encoded_processable) % 4
]
expected_metadata = base64.b64encode(
base64.b64decode(s=expected_metadata_original),
s=base64.b64decode(s=expected_metadata_original),
)
assert query_metadata == expected_metadata.decode()

Expand Down Expand Up @@ -1613,7 +1613,7 @@ def test_supported(
"""
image_buffer = io.BytesIO()
pil_image = Image.open(fp=high_quality_image)
pil_image.save(image_buffer, file_format)
pil_image.save(fp=image_buffer, format=file_format)
image_content = image_buffer.getvalue()
results = cloud_reco_client.query(
image=io.BytesIO(initial_bytes=image_content)
Expand All @@ -1631,7 +1631,7 @@ def test_unsupported(
file_format = "tiff"
image_buffer = io.BytesIO()
pil_image = Image.open(fp=high_quality_image)
pil_image.save(image_buffer, file_format)
pil_image.save(fp=image_buffer, format=file_format)
image_content = image_buffer.getvalue()

with pytest.raises(expected_exception=BadImage) as exc_info:
Expand Down
12 changes: 6 additions & 6 deletions tests/mock_vws/test_requests_mock_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def test_exact_match(high_quality_image: io.BytesIO) -> None:

pil_image = Image.open(fp=high_quality_image)
re_exported_image = io.BytesIO()
pil_image.save(re_exported_image, format="PNG")
pil_image.save(fp=re_exported_image, format="PNG")

with MockVWS(query_match_checker=ExactMatcher()) as mock:
mock.add_database(database=database)
Expand Down Expand Up @@ -505,7 +505,7 @@ def test_custom_matcher(high_quality_image: io.BytesIO) -> None:

pil_image = Image.open(fp=high_quality_image)
re_exported_image = io.BytesIO()
pil_image.save(re_exported_image, format="PNG")
pil_image.save(fp=re_exported_image, format="PNG")

with MockVWS(query_match_checker=_not_exact_matcher) as mock:
mock.add_database(database=database)
Expand Down Expand Up @@ -544,7 +544,7 @@ def test_structural_similarity_matcher(

pil_image = Image.open(fp=high_quality_image)
re_exported_image = io.BytesIO()
pil_image.save(re_exported_image, format="PNG")
pil_image.save(fp=re_exported_image, format="PNG")

with MockVWS(
query_match_checker=StructuralSimilarityMatcher(),
Expand Down Expand Up @@ -587,7 +587,7 @@ def test_exact_match(high_quality_image: io.BytesIO) -> None:

pil_image = Image.open(fp=high_quality_image)
re_exported_image = io.BytesIO()
pil_image.save(re_exported_image, format="PNG")
pil_image.save(fp=re_exported_image, format="PNG")

with MockVWS(duplicate_match_checker=ExactMatcher()) as mock:
mock.add_database(database=database)
Expand Down Expand Up @@ -631,7 +631,7 @@ def test_custom_matcher(high_quality_image: io.BytesIO) -> None:

pil_image = Image.open(fp=high_quality_image)
re_exported_image = io.BytesIO()
pil_image.save(re_exported_image, format="PNG")
pil_image.save(fp=re_exported_image, format="PNG")

with MockVWS(duplicate_match_checker=_not_exact_matcher) as mock:
mock.add_database(database=database)
Expand Down Expand Up @@ -677,7 +677,7 @@ def test_structural_similarity_matcher(

pil_image = Image.open(fp=high_quality_image)
re_exported_image = io.BytesIO()
pil_image.save(re_exported_image, format="PNG")
pil_image.save(fp=re_exported_image, format="PNG")

with MockVWS(
duplicate_match_checker=StructuralSimilarityMatcher(),
Expand Down
2 changes: 1 addition & 1 deletion tests/mock_vws/test_update_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _update_target(

response = requests.request(
method=HTTPMethod.PUT,
url=urljoin("https://vws.vuforia.com/", request_path),
url=urljoin(base="https://vws.vuforia.com/", url=request_path),
headers=headers,
data=content,
timeout=30,
Expand Down
4 changes: 2 additions & 2 deletions tests/mock_vws/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def make_image_file(
An image file in the given format and color space.
"""
image_buffer = io.BytesIO()
image = Image.new(color_space, (width, height))
image = Image.new(mode=color_space, size=(width, height))
for row_index in range(height):
for column_index in range(width):
red = secrets.choice(seq=range(255))
Expand All @@ -97,6 +97,6 @@ def make_image_file(
value=(red, green, blue),
)

image.save(image_buffer, file_format)
image.save(fp=image_buffer, format=file_format)
image_buffer.seek(0)
return image_buffer
2 changes: 1 addition & 1 deletion tests/mock_vws/utils/assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def assert_vwq_failure(

# Sometimes the "transfer-encoding" is given.
# It is not given by the mock.
response_header_keys_chunked = copy.copy(response_header_keys)
response_header_keys_chunked = copy.copy(x=response_header_keys)
response_header_keys_chunked.remove("Content-Length")
response_header_keys_chunked.add("transfer-encoding")

Expand Down