Skip to content

Commit 678ef4b

Browse files
committed
Use beartype in more places
1 parent 1e32447 commit 678ef4b

File tree

10 files changed

+34
-0
lines changed

10 files changed

+34
-0
lines changed

src/mock_vws/database.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class VuforiaDatabase:
7676
total_recos: int = 0
7777
target_quota: int = 1000
7878

79+
@beartype
7980
def to_dict(self) -> DatabaseDict:
8081
"""
8182
Dump a target to a dictionary which can be loaded as JSON.
@@ -120,13 +121,15 @@ def from_dict(cls, database_dict: DatabaseDict) -> Self:
120121
)
121122

122123
@property
124+
@beartype
123125
def not_deleted_targets(self) -> set[Target]:
124126
"""
125127
All targets which have not been deleted.
126128
"""
127129
return {target for target in self.targets if not target.delete_date}
128130

129131
@property
132+
@beartype
130133
def active_targets(self) -> set[Target]:
131134
"""
132135
All active targets.
@@ -139,6 +142,7 @@ def active_targets(self) -> set[Target]:
139142
}
140143

141144
@property
145+
@beartype
142146
def inactive_targets(self) -> set[Target]:
143147
"""
144148
All inactive targets.
@@ -151,6 +155,7 @@ def inactive_targets(self) -> set[Target]:
151155
}
152156

153157
@property
158+
@beartype
154159
def failed_targets(self) -> set[Target]:
155160
"""
156161
All failed targets.
@@ -162,6 +167,7 @@ def failed_targets(self) -> set[Target]:
162167
}
163168

164169
@property
170+
@beartype
165171
def processing_targets(self) -> set[Target]:
166172
"""
167173
All processing targets.

src/mock_vws/image_matchers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import numpy as np
77
import torch
8+
from beartype import beartype
89
from PIL import Image
910
from torchmetrics.image import (
1011
StructuralSimilarityIndexMeasure,
@@ -35,6 +36,7 @@ def __call__(
3536
class ExactMatcher:
3637
"""A matcher which returns whether two images are exactly equal."""
3738

39+
@beartype
3840
def __call__(
3941
self,
4042
first_image_content: bytes,
@@ -53,6 +55,7 @@ def __call__(
5355
class StructuralSimilarityMatcher:
5456
"""A matcher which returns whether two images are similar using SSIM."""
5557

58+
@beartype
5659
def __call__(
5760
self,
5861
first_image_content: bytes,

src/mock_vws/target.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from typing import Self, TypedDict
1212
from zoneinfo import ZoneInfo
1313

14+
from beartype import beartype
1415
from PIL import Image, ImageStat
1516

1617
from mock_vws._constants import TargetStatuses
@@ -77,6 +78,7 @@ class Target:
7778
upload_date: datetime.datetime = field(default_factory=_time_now)
7879

7980
@property
81+
@beartype
8082
def _post_processing_status(self) -> TargetStatuses:
8183
"""
8284
Return the status of the target, or what it will be when processing is
@@ -100,6 +102,7 @@ def _post_processing_status(self) -> TargetStatuses:
100102
return TargetStatuses.FAILED
101103

102104
@property
105+
@beartype
103106
def status(self) -> str:
104107
"""
105108
Return the status of the target.
@@ -125,11 +128,13 @@ def status(self) -> str:
125128
return self._post_processing_status.value
126129

127130
@property
131+
@beartype
128132
def _post_processing_target_rating(self) -> int:
129133
"""The rating of the target after processing."""
130134
return self.target_tracking_rater(image_content=self.image_value)
131135

132136
@property
137+
@beartype
133138
def tracking_rating(self) -> int:
134139
"""
135140
Return the tracking rating of the target recognition image.

src/mock_vws/target_manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def add_database(self, database: VuforiaDatabase) -> None:
8585

8686
@property
8787
@beartype
88+
@beartype
8889
def databases(self) -> set[VuforiaDatabase]:
8990
"""
9091
All cloud databases.

src/mock_vws/target_raters.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
import numpy as np
1010
import piq # type: ignore[import-untyped]
1111
import torch
12+
from beartype import beartype
1213
from PIL import Image
1314

1415

1516
@functools.cache
17+
@beartype
1618
def _get_brisque_target_tracking_rating(*, image_content: bytes) -> int:
1719
"""
1820
Get a target tracking rating based on a BRISQUE score.

tests/mock_vws/fixtures/credentials.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pathlib import Path
66

77
import pytest
8+
from beartype import beartype
89
from pydantic_settings import BaseSettings, SettingsConfigDict
910

1011
from mock_vws.database import VuforiaDatabase
@@ -38,6 +39,7 @@ class _InactiveVuforiaDatabaseSettings(_VuforiaDatabaseSettings):
3839

3940

4041
@pytest.fixture
42+
@beartype
4143
def vuforia_database() -> VuforiaDatabase:
4244
"""
4345
Return VWS credentials from environment variables.

tests/mock_vws/fixtures/vuforia_backends.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pytest
1111
import requests
1212
import responses
13+
from beartype import beartype
1314
from requests_mock_flask import add_flask_app_to_mock
1415
from vws import VWS
1516
from vws.exceptions.vws_exceptions import (
@@ -29,6 +30,7 @@
2930

3031

3132
@RETRY_ON_TOO_MANY_REQUESTS
33+
@beartype
3234
def _delete_all_targets(*, database_keys: VuforiaDatabase) -> None:
3335
"""
3436
Delete all targets.
@@ -59,6 +61,7 @@ def _delete_all_targets(*, database_keys: VuforiaDatabase) -> None:
5961
vws_client.delete_target(target_id=target)
6062

6163

64+
@beartype
6265
def _enable_use_real_vuforia(
6366
*,
6467
working_database: VuforiaDatabase,
@@ -72,6 +75,7 @@ def _enable_use_real_vuforia(
7275
yield
7376

7477

78+
@beartype
7579
def _enable_use_mock_vuforia(
7680
*,
7781
working_database: VuforiaDatabase,
@@ -103,6 +107,7 @@ def _enable_use_mock_vuforia(
103107
yield
104108

105109

110+
@beartype
106111
def _enable_use_docker_in_memory(
107112
*,
108113
working_database: VuforiaDatabase,
@@ -183,6 +188,7 @@ class VuforiaBackend(Enum):
183188
DOCKER_IN_MEMORY = "In Memory version of Docker application"
184189

185190

191+
@beartype
186192
def pytest_addoption(parser: pytest.Parser) -> None:
187193
"""
188194
Add options to the pytest command line for skipping tests with particular
@@ -204,6 +210,7 @@ def pytest_addoption(parser: pytest.Parser) -> None:
204210
)
205211

206212

213+
@beartype
207214
def pytest_collection_modifyitems(
208215
config: pytest.Config,
209216
items: list[pytest.Function],
@@ -270,6 +277,7 @@ def verify_mock_vuforia(
270277
]
271278
],
272279
)
280+
@beartype
273281
def mock_only_vuforia(
274282
request: pytest.FixtureRequest,
275283
vuforia_database: VuforiaDatabase,

tests/mock_vws/test_database_summary.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from http import HTTPStatus
99

1010
import pytest
11+
from beartype import beartype
1112
from tenacity import RetryCallState, retry
1213
from tenacity.retry import retry_if_exception_type
1314
from tenacity.stop import stop_after_delay
@@ -22,6 +23,7 @@
2223
LOGGER.setLevel(level=logging.DEBUG)
2324

2425

26+
@beartype
2527
def _log_attempt_number(retry_state: RetryCallState) -> None:
2628
"""
2729
Log the attempt number of a retry.

tests/mock_vws/test_requests_mock_usage.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import pytest
1313
import requests
14+
from beartype import beartype
1415
from freezegun import freeze_time
1516
from PIL import Image
1617
from requests.exceptions import MissingSchema
@@ -27,6 +28,7 @@
2728
)
2829

2930

31+
@beartype
3032
def _not_exact_matcher(
3133
first_image_content: bytes,
3234
second_image_content: bytes,
@@ -35,6 +37,7 @@ def _not_exact_matcher(
3537
return first_image_content != second_image_content
3638

3739

40+
@beartype
3841
def request_unmocked_address() -> None:
3942
"""
4043
Make a request, using `requests` to an unmocked, free local address.
@@ -53,6 +56,7 @@ def request_unmocked_address() -> None:
5356
requests.get(url=f"http://localhost:{port}", timeout=30)
5457

5558

59+
@beartype
5660
def request_mocked_address() -> None:
5761
"""
5862
Make a request, using `requests` to an address that is mocked by `MockVWS`.

tests/mock_vws/utils/assertions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def assert_valid_transaction_id(
102102
assert all(char in hexdigits for char in transaction_id)
103103

104104

105+
@beartype
105106
def assert_json_separators(*, response: requests.Response | Response) -> None:
106107
"""
107108
Assert that a JSON response is formatted correctly.

0 commit comments

Comments
 (0)