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
7 changes: 2 additions & 5 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

from __future__ import annotations

import io
import uuid
from collections.abc import Generator
from doctest import ELLIPSIS
from pathlib import Path
from typing import TYPE_CHECKING

import pytest
from mock_vws import MockVWS
Expand All @@ -17,10 +18,6 @@
PythonCodeBlockParser,
)

if TYPE_CHECKING:
import io
from collections.abc import Generator


@pytest.fixture(name="make_image_file")
def fixture_make_image_file(
Expand Down
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,12 @@ lint.flake8-tidy-imports.banned-api."operator.attrgetter".msg = "operator.attrge
lint.flake8-tidy-imports.banned-api."typing.cast".msg = """\
typing.cast is banned: use explicit type narrowing or a typed variable instead.\
"""
lint.flake8-type-checking.runtime-evaluated-decorators = [ "beartype.beartype" ]
# pytest-beartype evaluates fixture annotations at runtime.
lint.flake8-type-checking.runtime-evaluated-decorators = [
"beartype.beartype",
"pytest.fixture",
"pytest_asyncio.fixture",
]
lint.pydocstyle.convention = "google"
lint.preview = true

Expand Down
13 changes: 11 additions & 2 deletions tests/async_vws/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,34 @@

from __future__ import annotations

from typing import TYPE_CHECKING, BinaryIO
from typing import TYPE_CHECKING, BinaryIO, Literal

import pytest
from mock_vws import MockVWS
from mock_vws.database import CloudDatabase

from tests.image_factory import IMAGE_CASES, ImageFactory
from vws import AsyncVWS

if TYPE_CHECKING:
import io


@pytest.mark.asyncio
@pytest.mark.parametrize(
argnames=("image_source", "image_mode"), argvalues=IMAGE_CASES
)
async def test_custom_base_url(
image: io.BytesIO | BinaryIO,
image_factory: ImageFactory,
image_source: Literal["high_quality_image", "image_file"],
image_mode: Literal["r+b", "rb"],
) -> None:
"""It is possible to add a target to a database under a
custom VWS URL.
"""
image: io.BytesIO | BinaryIO = image_factory.create(
source=image_source, mode=image_mode
)
base_vws_url = "http://example.com"
with MockVWS(base_vws_url=base_vws_url) as mock:
database = CloudDatabase()
Expand Down
23 changes: 20 additions & 3 deletions tests/async_vws/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

from __future__ import annotations

from typing import TYPE_CHECKING, BinaryIO
from typing import TYPE_CHECKING, BinaryIO, Literal

import pytest
from mock_vws import MockVWS
from mock_vws.database import CloudDatabase

from tests.image_factory import IMAGE_CASES, ImageFactory
from vws import AsyncVWS
from vws.exceptions.custom_exceptions import (
TargetProcessingTimeoutError,
Expand All @@ -21,12 +22,20 @@


@pytest.mark.asyncio
@pytest.mark.parametrize(
argnames=("image_source", "image_mode"), argvalues=IMAGE_CASES
)
async def test_wait_for_target_processed(
*,
async_vws_client: AsyncVWS,
image: io.BytesIO | BinaryIO,
image_factory: ImageFactory,
image_source: Literal["high_quality_image", "image_file"],
image_mode: Literal["r+b", "rb"],
) -> None:
"""It is possible to wait until a target is processed."""
image: io.BytesIO | BinaryIO = image_factory.create(
source=image_source, mode=image_mode
)
target_id = await async_vws_client.add_target(
name="x",
width=1,
Expand All @@ -48,10 +57,18 @@ async def test_wait_for_target_processed(


@pytest.mark.asyncio
@pytest.mark.parametrize(
argnames=("image_source", "image_mode"), argvalues=IMAGE_CASES
)
async def test_custom_timeout(
image: io.BytesIO | BinaryIO,
image_factory: ImageFactory,
image_source: Literal["high_quality_image", "image_file"],
image_mode: Literal["r+b", "rb"],
) -> None:
"""It is possible to set a maximum timeout."""
image: io.BytesIO | BinaryIO = image_factory.create(
source=image_source, mode=image_mode
)
with MockVWS(processing_time_seconds=0.5) as mock:
database = CloudDatabase()
mock.add_cloud_database(cloud_database=database)
Expand Down
26 changes: 22 additions & 4 deletions tests/async_vws/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
from __future__ import annotations

import calendar
import datetime
import time
import uuid
from http import HTTPStatus
from typing import TYPE_CHECKING, BinaryIO
from typing import TYPE_CHECKING, BinaryIO, Literal

import pytest
from mock_vws import MockVWS
from mock_vws.database import CloudDatabase

from tests.image_factory import IMAGE_CASES, ImageFactory
from vws import AsyncVWS
from vws.exceptions.custom_exceptions import (
DatabaseIdNotSetError,
Expand All @@ -29,7 +31,6 @@
from vws.response import Response

if TYPE_CHECKING:
import datetime
import io


Expand Down Expand Up @@ -65,14 +66,22 @@ async def __call__(


@pytest.mark.asyncio
@pytest.mark.parametrize(
argnames=("image_source", "image_mode"), argvalues=IMAGE_CASES
)
async def test_get_target_summary_report(
*,
async_vws_client: AsyncVWS,
image: io.BytesIO | BinaryIO,
image_factory: ImageFactory,
image_source: Literal["high_quality_image", "image_file"],
image_mode: Literal["r+b", "rb"],
) -> None:
"""Details of a target are returned by
``get_target_summary_report``.
"""
image: io.BytesIO | BinaryIO = image_factory.create(
source=image_source, mode=image_mode
)
target_name = uuid.uuid4().hex
target_id = await async_vws_client.add_target(
name=target_name,
Expand Down Expand Up @@ -105,12 +114,21 @@ async def test_get_target(


@pytest.mark.asyncio
@pytest.mark.parametrize(
argnames="report_period", argvalues=["current", "previous"]
)
async def test_reco_counts_report(
*,
async_vws_client: AsyncVWS,
report_month: datetime.date,
current_month: datetime.date,
report_period: Literal["current", "previous"],
) -> None:
"""A report can be requested, waited for and downloaded."""
report_month = (
current_month
if report_period == "current"
else current_month - datetime.timedelta(days=1)
)
client = async_vws_client
report_request = await client.request_database_reco_counts_report(
year=report_month.year,
Expand Down
Loading
Loading