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
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# This method of getting the release from the version goes hand in hand with
# the ``post-release`` versioning scheme chosen in the ``setuptools-scm``
# configuration.
release = version.split(".post")[0]
release = version.split(sep=".post")[0]


project_metadata = importlib.metadata.metadata(distribution_name=project)
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ optional-dependencies.dev = [
"furo==2024.8.6",
"interrogate==1.7.0",
"mypy[faster-cache]==1.14.0",
"mypy-strict-kwargs==2024.12.24",
"pre-commit==4.0.1",
"pydocstyle==6.3",
"pyenchant==3.3.0rc1",
Expand Down Expand Up @@ -334,6 +335,9 @@ strict = true
files = [ "." ]
exclude = [ "build" ]
follow_untyped_imports = true
plugins = [
"mypy_strict_kwargs",
]

[tool.pyright]

Expand Down
2 changes: 1 addition & 1 deletion src/vws/exceptions/vws_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def target_name(self) -> str:
"""
response_body = self.response.request_body or b""
request_json = json.loads(s=response_body)
return str(request_json["name"])
return str(object=request_json["name"])


@beartype
Expand Down
2 changes: 1 addition & 1 deletion src/vws/vws.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def add_target(
content_type="application/json",
)

return str(json.loads(s=response.text)["target_id"])
return str(object=json.loads(s=response.text)["target_id"])

def get_target_record(self, target_id: str) -> TargetStatusAndRecord:
"""Get a given target's target record from the Target Management
Expand Down
12 changes: 7 additions & 5 deletions tests/test_cloud_reco_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_too_many_max_results(
A ``MaxNumResultsOutOfRange`` error is raised if the given
``max_num_results`` is out of range.
"""
with pytest.raises(MaxNumResultsOutOfRangeError) as exc:
with pytest.raises(expected_exception=MaxNumResultsOutOfRangeError) as exc:
cloud_reco_client.query(
image=high_quality_image,
max_num_results=51,
Expand All @@ -43,7 +43,7 @@ def test_too_many_max_results(
"Integer out of range (51) in form data part 'max_result'. "
"Accepted range is from 1 to 50 (inclusive)."
)
assert str(exc.value) == exc.value.response.text == expected_value
assert str(object=exc.value) == exc.value.response.text == expected_value


def test_image_too_large(
Expand All @@ -54,7 +54,7 @@ def test_image_too_large(
A ``RequestEntityTooLarge`` exception is raised if an image which is too
large is given.
"""
with pytest.raises(RequestEntityTooLargeError) as exc:
with pytest.raises(expected_exception=RequestEntityTooLargeError) as exc:
cloud_reco_client.query(image=png_too_large)

assert (
Expand Down Expand Up @@ -92,7 +92,9 @@ def test_authentication_failure(
with MockVWS() as mock:
mock.add_database(database=database)

with pytest.raises(AuthenticationFailureError) as exc:
with pytest.raises(
expected_exception=AuthenticationFailureError
) as exc:
cloud_reco_client.query(image=high_quality_image)

assert exc.value.response.status_code == HTTPStatus.UNAUTHORIZED
Expand All @@ -113,7 +115,7 @@ def test_inactive_project(
client_secret_key=database.client_secret_key,
)

with pytest.raises(InactiveProjectError) as exc:
with pytest.raises(expected_exception=InactiveProjectError) as exc:
cloud_reco_client.query(image=high_quality_image)

response = exc.value.response
Expand Down
13 changes: 9 additions & 4 deletions tests/test_vws.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ class TestAddTarget:
"""

@staticmethod
@pytest.mark.parametrize("application_metadata", [None, b"a"])
@pytest.mark.parametrize("active_flag", [True, False])
@pytest.mark.parametrize(
argnames="application_metadata",
argvalues=[None, b"a"],
)
@pytest.mark.parametrize(argnames="active_flag", argvalues=[True, False])
def test_add_target(
vws_client: VWS,
image: io.BytesIO | BinaryIO,
Expand Down Expand Up @@ -211,7 +214,7 @@ def test_get_target_summary_report(
status=TargetStatuses.SUCCESS,
database_name=report.database_name,
target_name=target_name,
upload_date=datetime.date(2018, 4, 25),
upload_date=datetime.date(year=2018, month=4, day=25),
active_flag=True,
tracking_rating=report.tracking_rating,
total_recos=0,
Expand Down Expand Up @@ -511,7 +514,9 @@ def test_custom_timeout(image: io.BytesIO | BinaryIO) -> None:

report = vws_client.get_target_summary_report(target_id=target_id)
assert report.status == TargetStatuses.PROCESSING
with pytest.raises(TargetProcessingTimeoutError):
with pytest.raises(
expected_exception=TargetProcessingTimeoutError
):
vws_client.wait_for_target_processed(
target_id=target_id,
timeout_seconds=0.1,
Expand Down
30 changes: 17 additions & 13 deletions tests/test_vws_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_image_too_large(
When giving an image which is too large, an ``ImageTooLarge`` exception is
raised.
"""
with pytest.raises(ImageTooLargeError) as exc:
with pytest.raises(expected_exception=ImageTooLargeError) as exc:
vws_client.add_target(
name="x",
width=1,
Expand All @@ -63,7 +63,7 @@ def test_invalid_given_id(vws_client: VWS) -> None:
causes an ``UnknownTarget`` exception to be raised.
"""
target_id = "12345abc"
with pytest.raises(UnknownTargetError) as exc:
with pytest.raises(expected_exception=UnknownTargetError) as exc:
vws_client.delete_target(target_id=target_id)
assert exc.value.response.status_code == HTTPStatus.NOT_FOUND
assert exc.value.target_id == target_id
Expand All @@ -76,7 +76,9 @@ def test_add_bad_name(vws_client: VWS, high_quality_image: io.BytesIO) -> None:
"""
max_char_value = 65535
bad_name = chr(max_char_value + 1)
with pytest.raises(OopsAnErrorOccurredPossiblyBadNameError) as exc:
with pytest.raises(
expected_exception=OopsAnErrorOccurredPossiblyBadNameError
) as exc:
vws_client.add_target(
name=bad_name,
width=1,
Expand Down Expand Up @@ -105,7 +107,7 @@ def test_fail(high_quality_image: io.BytesIO) -> None:
server_secret_key=uuid.uuid4().hex,
)

with pytest.raises(FailError) as exc:
with pytest.raises(expected_exception=FailError) as exc:
vws_client.add_target(
name="x",
width=1,
Expand All @@ -122,7 +124,7 @@ def test_bad_image(vws_client: VWS) -> None:
A ``BadImage`` exception is raised when a non-image is given.
"""
not_an_image = io.BytesIO(initial_bytes=b"Not an image")
with pytest.raises(BadImageError) as exc:
with pytest.raises(expected_exception=BadImageError) as exc:
vws_client.add_target(
name="x",
width=1,
Expand All @@ -149,7 +151,7 @@ def test_target_name_exist(
active_flag=True,
application_metadata=None,
)
with pytest.raises(TargetNameExistError) as exc:
with pytest.raises(expected_exception=TargetNameExistError) as exc:
vws_client.add_target(
name="x",
width=1,
Expand Down Expand Up @@ -177,7 +179,7 @@ def test_project_inactive(
server_secret_key=database.server_secret_key,
)

with pytest.raises(ProjectInactiveError) as exc:
with pytest.raises(expected_exception=ProjectInactiveError) as exc:
vws_client.add_target(
name="x",
width=1,
Expand Down Expand Up @@ -205,7 +207,7 @@ def test_target_status_processing(
application_metadata=None,
)

with pytest.raises(TargetStatusProcessingError) as exc:
with pytest.raises(expected_exception=TargetStatusProcessingError) as exc:
vws_client.delete_target(target_id=target_id)

assert exc.value.response.status_code == HTTPStatus.FORBIDDEN
Expand All @@ -220,7 +222,7 @@ def test_metadata_too_large(
A ``MetadataTooLarge`` exception is raised if the metadata given is too
large.
"""
with pytest.raises(MetadataTooLargeError) as exc:
with pytest.raises(expected_exception=MetadataTooLargeError) as exc:
vws_client.add_target(
name="x",
width=1,
Expand Down Expand Up @@ -260,7 +262,7 @@ def test_request_time_too_skewed(
# >= 1 ticks are acceptable.
with (
freeze_time(auto_tick_seconds=time_difference_from_now),
pytest.raises(RequestTimeTooSkewedError) as exc,
pytest.raises(expected_exception=RequestTimeTooSkewedError) as exc,
):
vws_client.get_target_record(target_id=target_id)

Expand All @@ -285,7 +287,9 @@ def test_authentication_failure(
with MockVWS() as mock:
mock.add_database(database=database)

with pytest.raises(AuthenticationFailureError) as exc:
with pytest.raises(
expected_exception=AuthenticationFailureError
) as exc:
vws_client.add_target(
name="x",
width=1,
Expand Down Expand Up @@ -313,7 +317,7 @@ def test_target_status_not_success(
application_metadata=None,
)

with pytest.raises(TargetStatusNotSuccessError) as exc:
with pytest.raises(expected_exception=TargetStatusNotSuccessError) as exc:
vws_client.update_target(target_id=target_id)

assert exc.value.response.status_code == HTTPStatus.FORBIDDEN
Expand Down Expand Up @@ -353,7 +357,7 @@ def test_base_exception(
"""
``VWSException``s has a response property.
"""
with pytest.raises(VWSError) as exc:
with pytest.raises(expected_exception=VWSError) as exc:
vws_client.get_target_record(target_id="a")

assert exc.value.response.status_code == HTTPStatus.NOT_FOUND
Expand Down
Loading