Skip to content

Commit 0c50ef3

Browse files
Merge pull request #3299 from VWS-Python/replace-request-param
Replace request.param fixture selection with typed parameters
2 parents 27eeac2 + ceba342 commit 0c50ef3

14 files changed

Lines changed: 575 additions & 117 deletions

‎conftest.py‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
from __future__ import annotations
44

5+
import io
56
import uuid
7+
from collections.abc import Generator
68
from doctest import ELLIPSIS
79
from pathlib import Path
8-
from typing import TYPE_CHECKING
910

1011
import pytest
1112
from mock_vws import MockVWS
@@ -17,10 +18,6 @@
1718
PythonCodeBlockParser,
1819
)
1920

20-
if TYPE_CHECKING:
21-
import io
22-
from collections.abc import Generator
23-
2421

2522
@pytest.fixture(name="make_image_file")
2623
def fixture_make_image_file(

‎pyproject.toml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,12 @@ lint.flake8-tidy-imports.banned-api."operator.attrgetter".msg = "operator.attrge
165165
lint.flake8-tidy-imports.banned-api."typing.cast".msg = """\
166166
typing.cast is banned: use explicit type narrowing or a typed variable instead.\
167167
"""
168-
lint.flake8-type-checking.runtime-evaluated-decorators = [ "beartype.beartype" ]
168+
# pytest-beartype evaluates fixture annotations at runtime.
169+
lint.flake8-type-checking.runtime-evaluated-decorators = [
170+
"beartype.beartype",
171+
"pytest.fixture",
172+
"pytest_asyncio.fixture",
173+
]
169174
lint.pydocstyle.convention = "google"
170175
lint.preview = true
171176

‎tests/async_vws/test_configuration.py‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,34 @@
22

33
from __future__ import annotations
44

5-
from typing import TYPE_CHECKING, BinaryIO
5+
from typing import TYPE_CHECKING, BinaryIO, Literal
66

77
import pytest
88
from mock_vws import MockVWS
99
from mock_vws.database import CloudDatabase
1010

11+
from tests.image_factory import IMAGE_CASES, ImageFactory
1112
from vws import AsyncVWS
1213

1314
if TYPE_CHECKING:
1415
import io
1516

1617

1718
@pytest.mark.asyncio
19+
@pytest.mark.parametrize(
20+
argnames=("image_source", "image_mode"), argvalues=IMAGE_CASES
21+
)
1822
async def test_custom_base_url(
19-
image: io.BytesIO | BinaryIO,
23+
image_factory: ImageFactory,
24+
image_source: Literal["high_quality_image", "image_file"],
25+
image_mode: Literal["r+b", "rb"],
2026
) -> None:
2127
"""It is possible to add a target to a database under a
2228
custom VWS URL.
2329
"""
30+
image: io.BytesIO | BinaryIO = image_factory.create(
31+
source=image_source, mode=image_mode
32+
)
2433
base_vws_url = "http://example.com"
2534
with MockVWS(base_vws_url=base_vws_url) as mock:
2635
database = CloudDatabase()

‎tests/async_vws/test_processing.py‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
from __future__ import annotations
44

5-
from typing import TYPE_CHECKING, BinaryIO
5+
from typing import TYPE_CHECKING, BinaryIO, Literal
66

77
import pytest
88
from mock_vws import MockVWS
99
from mock_vws.database import CloudDatabase
1010

11+
from tests.image_factory import IMAGE_CASES, ImageFactory
1112
from vws import AsyncVWS
1213
from vws.exceptions.custom_exceptions import (
1314
TargetProcessingTimeoutError,
@@ -21,12 +22,20 @@
2122

2223

2324
@pytest.mark.asyncio
25+
@pytest.mark.parametrize(
26+
argnames=("image_source", "image_mode"), argvalues=IMAGE_CASES
27+
)
2428
async def test_wait_for_target_processed(
2529
*,
2630
async_vws_client: AsyncVWS,
27-
image: io.BytesIO | BinaryIO,
31+
image_factory: ImageFactory,
32+
image_source: Literal["high_quality_image", "image_file"],
33+
image_mode: Literal["r+b", "rb"],
2834
) -> None:
2935
"""It is possible to wait until a target is processed."""
36+
image: io.BytesIO | BinaryIO = image_factory.create(
37+
source=image_source, mode=image_mode
38+
)
3039
target_id = await async_vws_client.add_target(
3140
name="x",
3241
width=1,
@@ -48,10 +57,18 @@ async def test_wait_for_target_processed(
4857

4958

5059
@pytest.mark.asyncio
60+
@pytest.mark.parametrize(
61+
argnames=("image_source", "image_mode"), argvalues=IMAGE_CASES
62+
)
5163
async def test_custom_timeout(
52-
image: io.BytesIO | BinaryIO,
64+
image_factory: ImageFactory,
65+
image_source: Literal["high_quality_image", "image_file"],
66+
image_mode: Literal["r+b", "rb"],
5367
) -> None:
5468
"""It is possible to set a maximum timeout."""
69+
image: io.BytesIO | BinaryIO = image_factory.create(
70+
source=image_source, mode=image_mode
71+
)
5572
with MockVWS(processing_time_seconds=0.5) as mock:
5673
database = CloudDatabase()
5774
mock.add_cloud_database(cloud_database=database)

‎tests/async_vws/test_reports.py‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
from __future__ import annotations
44

55
import calendar
6+
import datetime
67
import time
78
import uuid
89
from http import HTTPStatus
9-
from typing import TYPE_CHECKING, BinaryIO
10+
from typing import TYPE_CHECKING, BinaryIO, Literal
1011

1112
import pytest
1213
from mock_vws import MockVWS
1314
from mock_vws.database import CloudDatabase
1415

16+
from tests.image_factory import IMAGE_CASES, ImageFactory
1517
from vws import AsyncVWS
1618
from vws.exceptions.custom_exceptions import (
1719
DatabaseIdNotSetError,
@@ -29,7 +31,6 @@
2931
from vws.response import Response
3032

3133
if TYPE_CHECKING:
32-
import datetime
3334
import io
3435

3536

@@ -65,14 +66,22 @@ async def __call__(
6566

6667

6768
@pytest.mark.asyncio
69+
@pytest.mark.parametrize(
70+
argnames=("image_source", "image_mode"), argvalues=IMAGE_CASES
71+
)
6872
async def test_get_target_summary_report(
6973
*,
7074
async_vws_client: AsyncVWS,
71-
image: io.BytesIO | BinaryIO,
75+
image_factory: ImageFactory,
76+
image_source: Literal["high_quality_image", "image_file"],
77+
image_mode: Literal["r+b", "rb"],
7278
) -> None:
7379
"""Details of a target are returned by
7480
``get_target_summary_report``.
7581
"""
82+
image: io.BytesIO | BinaryIO = image_factory.create(
83+
source=image_source, mode=image_mode
84+
)
7685
target_name = uuid.uuid4().hex
7786
target_id = await async_vws_client.add_target(
7887
name=target_name,
@@ -105,12 +114,21 @@ async def test_get_target(
105114

106115

107116
@pytest.mark.asyncio
117+
@pytest.mark.parametrize(
118+
argnames="report_period", argvalues=["current", "previous"]
119+
)
108120
async def test_reco_counts_report(
109121
*,
110122
async_vws_client: AsyncVWS,
111-
report_month: datetime.date,
123+
current_month: datetime.date,
124+
report_period: Literal["current", "previous"],
112125
) -> None:
113126
"""A report can be requested, waited for and downloaded."""
127+
report_month = (
128+
current_month
129+
if report_period == "current"
130+
else current_month - datetime.timedelta(days=1)
131+
)
114132
client = async_vws_client
115133
report_request = await client.request_database_reco_counts_report(
116134
year=report_month.year,

0 commit comments

Comments
 (0)