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
4 changes: 1 addition & 3 deletions src/vws/async_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ def __init__(

async def aclose(self) -> None:
"""Close the underlying transport if it supports closing."""
close = getattr(self._transport, "aclose", None)
if close is not None:
await close()
await self._transport.aclose()

async def __aenter__(self) -> Self:
"""Enter the async context manager."""
Expand Down
4 changes: 1 addition & 3 deletions src/vws/async_vumark_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def __init__(

async def aclose(self) -> None:
"""Close the underlying transport if it supports closing."""
close = getattr(self._transport, "aclose", None)
if close is not None:
await close()
await self._transport.aclose()

async def __aenter__(self) -> Self:
"""Enter the async context manager."""
Expand Down
4 changes: 1 addition & 3 deletions src/vws/async_vws.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ def __init__(

async def aclose(self) -> None:
"""Close the underlying transport if it supports closing."""
close = getattr(self._transport, "aclose", None)
if close is not None:
await close()
await self._transport.aclose()

async def __aenter__(self) -> Self:
"""Enter the async context manager."""
Expand Down
4 changes: 4 additions & 0 deletions src/vws/transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ class AsyncTransport(Protocol):
and returns a ``Response``.
"""

async def aclose(self) -> None:
"""Close the transport and release resources."""
... # pylint: disable=unnecessary-ellipsis

def __call__(
self,
*,
Expand Down
65 changes: 0 additions & 65 deletions tests/test_transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pytest
import respx

from vws import AsyncCloudRecoService, AsyncVuMarkService, AsyncVWS
from vws.response import Response
from vws.transports import AsyncHTTPXTransport, HTTPXTransport

Expand Down Expand Up @@ -140,67 +139,3 @@ async def test_context_manager() -> None:
assert route.called
assert isinstance(response, Response)
assert response.status_code == HTTPStatus.OK


class _NoCloseTransport:
"""A minimal async transport without ``aclose``."""

async def __call__( # pragma: no cover
self,
*,
method: str,
url: str,
headers: dict[str, str],
data: bytes,
request_timeout: float | tuple[float, float],
) -> Response:
"""Not implemented."""
raise NotImplementedError


_DUMMY_KEY = "x"


class TestAsyncClientAclose:
"""Tests for ``aclose`` on async clients with transports that
lack ``aclose``.
"""

@staticmethod
@pytest.mark.asyncio
async def test_vws_aclose_no_transport_aclose() -> None:
"""``AsyncVWS.aclose`` works when the transport has no
``aclose``.
"""
client = AsyncVWS(
server_access_key=_DUMMY_KEY,
server_secret_key=_DUMMY_KEY,
transport=_NoCloseTransport(),
)
await client.aclose()

@staticmethod
@pytest.mark.asyncio
async def test_cloud_reco_aclose_no_transport_aclose() -> None:
"""``AsyncCloudRecoService.aclose`` works when the transport
has no ``aclose``.
"""
client = AsyncCloudRecoService(
client_access_key=_DUMMY_KEY,
client_secret_key=_DUMMY_KEY,
transport=_NoCloseTransport(),
)
await client.aclose()

@staticmethod
@pytest.mark.asyncio
async def test_vumark_aclose_no_transport_aclose() -> None:
"""``AsyncVuMarkService.aclose`` works when the transport
has no ``aclose``.
"""
client = AsyncVuMarkService(
server_access_key=_DUMMY_KEY,
server_secret_key=_DUMMY_KEY,
transport=_NoCloseTransport(),
)
await client.aclose()
Loading