Skip to content

Commit c483b46

Browse files
Merge pull request #2257 from VWS-Python/beartype
Run beartype instead of typeguard
2 parents e40a74f + 02fe369 commit c483b46

24 files changed

+53
-153
lines changed

conftest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from doctest import ELLIPSIS
44

55
import pytest
6+
from beartype import beartype
67
from sybil import Sybil
78
from sybil.parsers.rest import (
89
DocTestParser,
@@ -11,6 +12,16 @@
1112

1213
from tests.mock_vws.utils.retries import RETRY_EXCEPTIONS
1314

15+
16+
def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:
17+
"""
18+
Apply the beartype decorator to all collected test functions.
19+
"""
20+
for item in items:
21+
if isinstance(item, pytest.Function):
22+
item.obj = beartype(obj=item.obj)
23+
24+
1425
pytest_collect_file = Sybil(
1526
parsers=[
1627
DocTestParser(optionflags=ELLIPSIS),

pyproject.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ dependencies = [
5353
]
5454
optional-dependencies.dev = [
5555
"actionlint-py==1.7.1.15",
56+
"beartype==0.18.5",
5657
"check-manifest==0.49",
5758
"check-wheel-contents==0.6.0",
5859
"deptry==0.20.0",
@@ -88,7 +89,6 @@ optional-dependencies.dev = [
8889
"sphinxcontrib-spelling==8",
8990
"sybil==6.1.1",
9091
"tenacity==9.0.0",
91-
"typeguard==4.3.0",
9292
"types-docker==7.1.0.20240827",
9393
"types-pillow==10.2.0.20240822",
9494
"types-pyyaml==6.0.12.20240808",
@@ -323,9 +323,6 @@ keep_full_version = true
323323

324324
xfail_strict = true
325325
log_cli = true
326-
typeguard-packages = """
327-
tests
328-
"""
329326
addopts = [
330327
"--strict-markers",
331328
]

spelling_private_dict.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ascii
1111
auth
1212
backend
1313
backends
14+
beartype
1415
binascii
1516
bool
1617
boolean

tests/conftest.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,16 @@
22
Configuration, plugins and fixtures for `pytest`.
33
"""
44

5-
from __future__ import annotations
6-
75
import base64
86
import binascii
7+
import io
98
import uuid
10-
from typing import TYPE_CHECKING
119

1210
import pytest
1311
from vws import VWS, CloudRecoService
1412

15-
if TYPE_CHECKING:
16-
import io
17-
18-
from mock_vws.database import VuforiaDatabase
19-
from tests.mock_vws.utils import Endpoint
13+
from mock_vws.database import VuforiaDatabase
14+
from tests.mock_vws.utils import Endpoint
2015

2116
pytest_plugins = [
2217
"tests.mock_vws.fixtures.prepared_requests",

tests/mock_vws/fixtures/vuforia_backends.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
Choose which backends to use for the tests.
33
"""
44

5-
from __future__ import annotations
6-
75
import contextlib
86
import logging
7+
from collections.abc import Generator
98
from enum import Enum
10-
from typing import TYPE_CHECKING
119

1210
import pytest
1311
import requests
@@ -26,10 +24,6 @@
2624
from mock_vws.states import States
2725
from tests.mock_vws.utils.retries import RETRY_ON_TOO_MANY_REQUESTS
2826

29-
if TYPE_CHECKING:
30-
from collections.abc import Generator
31-
32-
3327
LOGGER = logging.getLogger(name=__name__)
3428
LOGGER.setLevel(level=logging.DEBUG)
3529

tests/mock_vws/test_add_target.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
Tests for the mock of the add target endpoint.
33
"""
44

5-
from __future__ import annotations
6-
75
import base64
86
import io
97
import json
108
from http import HTTPMethod, HTTPStatus
119
from string import hexdigits
12-
from typing import TYPE_CHECKING, Any, Final
10+
from typing import Any, Final
1311
from urllib.parse import urljoin
1412

1513
import pytest
1614
import requests
1715
from dirty_equals import IsInstance
1816
from requests.structures import CaseInsensitiveDict
17+
from vws import VWS
1918
from vws.exceptions.custom_exceptions import OopsAnErrorOccurredPossiblyBadName
19+
from vws.exceptions.response import Response
2020
from vws.exceptions.vws_exceptions import (
2121
BadImage,
2222
Fail,
@@ -28,6 +28,7 @@
2828
from vws_auth_tools import authorization_header, rfc_1123_date
2929

3030
from mock_vws._constants import ResultCodes
31+
from mock_vws.database import VuforiaDatabase
3132
from tests.mock_vws.utils import make_image_file
3233
from tests.mock_vws.utils.assertions import (
3334
assert_valid_date_header,
@@ -36,12 +37,6 @@
3637
)
3738
from tests.mock_vws.utils.too_many_requests import handle_server_errors
3839

39-
if TYPE_CHECKING:
40-
from vws import VWS
41-
from vws.exceptions.response import Response
42-
43-
from mock_vws.database import VuforiaDatabase
44-
4540
_MAX_METADATA_BYTES: Final[int] = 1024 * 1024 - 1
4641

4742

tests/mock_vws/test_authorization_header.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
Tests for the `Authorization` header.
33
"""
44

5-
from __future__ import annotations
6-
5+
import io
76
import json
87
import uuid
98
from http import HTTPStatus
10-
from typing import TYPE_CHECKING
119
from urllib.parse import urlparse
1210

1311
import pytest
@@ -18,19 +16,15 @@
1816
from vws_auth_tools import rfc_1123_date
1917

2018
from mock_vws._constants import ResultCodes
19+
from mock_vws.database import VuforiaDatabase
20+
from tests.mock_vws.utils import Endpoint
2121
from tests.mock_vws.utils.assertions import (
2222
assert_valid_transaction_id,
2323
assert_vwq_failure,
2424
assert_vws_failure,
2525
)
2626
from tests.mock_vws.utils.too_many_requests import handle_server_errors
2727

28-
if TYPE_CHECKING:
29-
import io
30-
31-
from mock_vws.database import VuforiaDatabase
32-
from tests.mock_vws.utils import Endpoint
33-
3428

3529
@pytest.mark.usefixtures("verify_mock_vuforia")
3630
class TestAuthorizationHeader:

tests/mock_vws/test_content_length.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,23 @@
22
Tests for the ``Content-Length`` header.
33
"""
44

5-
from __future__ import annotations
6-
75
import textwrap
86
from http import HTTPStatus
9-
from typing import TYPE_CHECKING
107
from urllib.parse import urlparse
118

129
import pytest
1310
import requests
1411
from requests.structures import CaseInsensitiveDict
1512

1613
from mock_vws._constants import ResultCodes
14+
from tests.mock_vws.utils import Endpoint
1715
from tests.mock_vws.utils.assertions import (
1816
assert_valid_date_header,
1917
assert_vwq_failure,
2018
assert_vws_failure,
2119
)
2220
from tests.mock_vws.utils.too_many_requests import handle_server_errors
2321

24-
if TYPE_CHECKING:
25-
from tests.mock_vws.utils import Endpoint
26-
2722

2823
@pytest.mark.usefixtures("verify_mock_vuforia")
2924
class TestIncorrect:

tests/mock_vws/test_database_summary.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
Tests for the mock of the database summary endpoint.
33
"""
44

5-
from __future__ import annotations
6-
5+
import io
76
import logging
87
import uuid
98
from http import HTTPStatus
10-
from typing import TYPE_CHECKING
119

1210
import pytest
1311
from tenacity import RetryCallState, retry
@@ -20,9 +18,6 @@
2018
from mock_vws import MockVWS
2119
from mock_vws.database import VuforiaDatabase
2220

23-
if TYPE_CHECKING:
24-
import io
25-
2621
LOGGER = logging.getLogger(name=__name__)
2722
LOGGER.setLevel(level=logging.DEBUG)
2823

tests/mock_vws/test_date_header.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
Tests for the `Date` header.
33
"""
44

5-
from __future__ import annotations
6-
75
from datetime import datetime, timedelta
86
from http import HTTPStatus
9-
from typing import TYPE_CHECKING
107
from urllib.parse import urlparse
118
from zoneinfo import ZoneInfo
129

@@ -16,6 +13,7 @@
1613
from vws_auth_tools import authorization_header, rfc_1123_date
1714

1815
from mock_vws._constants import ResultCodes
16+
from tests.mock_vws.utils import Endpoint
1917
from tests.mock_vws.utils.assertions import (
2018
assert_query_success,
2119
assert_valid_transaction_id,
@@ -25,9 +23,6 @@
2523
)
2624
from tests.mock_vws.utils.too_many_requests import handle_server_errors
2725

28-
if TYPE_CHECKING:
29-
from tests.mock_vws.utils import Endpoint
30-
3126
_VWS_MAX_TIME_SKEW = timedelta(minutes=5)
3227
_VWQ_MAX_TIME_SKEW = timedelta(minutes=65)
3328
_LEEWAY = timedelta(seconds=10)

0 commit comments

Comments
 (0)