From 2c8a3d425d1d8ac014db1114b95b7c92f87064d7 Mon Sep 17 00:00:00 2001 From: Adam Dangoor Date: Mon, 7 Sep 2026 19:05:50 +0100 Subject: [PATCH] Use vws-python's own HTTPX2 transports in the tests vws-python 2026.09.07 ships HTTPX2Transport and AsyncHTTPX2Transport, so the stand-in transports which lived in tests/mock_vws/utils are no longer needed. The HTTPX2 mock usage tests now drive the vws-python clients through the released transports. Closes #3546 Co-Authored-By: Claude Fable 5.1 --- pyproject.toml | 2 +- tests/mock_vws/test_httpx2_mock_usage.py | 5 +- tests/mock_vws/utils/httpx2_transports.py | 156 ---------------------- uv.lock | 9 +- 4 files changed, 7 insertions(+), 165 deletions(-) delete mode 100644 tests/mock_vws/utils/httpx2_transports.py diff --git a/pyproject.toml b/pyproject.toml index 7e4ee5a9c..dcd4c3a2c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -118,7 +118,7 @@ optional-dependencies.dev = [ "urllib3==2.7.0", "vale==3.20.0.0", "vulture==2.16", - "vws-python==2026.8.26", + "vws-python==2026.9.7", "vws-test-fixtures==2026.8.26", "vws-web-tools==2026.8.27", "yamlfix==1.19.1", diff --git a/tests/mock_vws/test_httpx2_mock_usage.py b/tests/mock_vws/test_httpx2_mock_usage.py index b0771065e..dae0ce549 100644 --- a/tests/mock_vws/test_httpx2_mock_usage.py +++ b/tests/mock_vws/test_httpx2_mock_usage.py @@ -23,16 +23,13 @@ UnknownTargetError, ) from vws.reports import TargetStatuses +from vws.transports import AsyncHTTPX2Transport, HTTPX2Transport from vws.vumark_accept import VuMarkAccept from mock_vws import MockVWS from mock_vws.database import CloudDatabase, VuMarkDatabase from mock_vws.image_matchers import ExactMatcher from mock_vws.target import VuMarkTarget -from tests.mock_vws.utils.httpx2_transports import ( - AsyncHTTPX2Transport, - HTTPX2Transport, -) _MODEL_TARGET_AUTHORIZATION = ( "Bearer eyJhbGciOiJtb2NrIn0." diff --git a/tests/mock_vws/utils/httpx2_transports.py b/tests/mock_vws/utils/httpx2_transports.py deleted file mode 100644 index f2e1c0593..000000000 --- a/tests/mock_vws/utils/httpx2_transports.py +++ /dev/null @@ -1,156 +0,0 @@ -"""``vws-python`` transports which use ``httpx2``. - -``vws-python`` ships ``requests`` and ``httpx`` transports. Its ``httpx2`` -transports are not released yet, so these stand in for them, and they are -what the tests use to show that ``vws-python`` clients work against the -mock over ``httpx2``. - -These go away once the released transports can be used instead. See -https://github.com/VWS-Python/vws-python-mock/issues/3546. -""" - -import httpx2 -from beartype import BeartypeConf, beartype -from vws.response import Response - - -@beartype -def _httpx2_timeout( - *, - request_timeout: float | tuple[float, float], -) -> httpx2.Timeout: - """The ``httpx2`` timeout for a ``vws-python`` request timeout. - - Args: - request_timeout: The timeout for the request. A float sets both the - connect and read timeouts. A ``(connect, read)`` tuple sets them - individually. - - Returns: - The equivalent ``httpx2`` timeout. - """ - match request_timeout: - case tuple() as timeout: - connect_timeout, read_timeout = timeout - case timeout: - connect_timeout = timeout - read_timeout = timeout - - return httpx2.Timeout( - connect=connect_timeout, - read=read_timeout, - write=None, - pool=None, - ) - - -@beartype -def _to_vws_response(*, httpx2_response: httpx2.Response) -> Response: - """Convert an ``httpx2`` response to a ``vws-python`` response. - - Args: - httpx2_response: The response to convert. - - Returns: - The equivalent ``vws-python`` response. - """ - content = bytes(httpx2_response.content) - request_content = httpx2_response.request.content - - return Response( - text=httpx2_response.text, - url=str(object=httpx2_response.url), - status_code=httpx2_response.status_code, - headers=dict(httpx2_response.headers), - request_body=bytes(request_content) or None, - tell_position=len(content), - content=content, - ) - - -@beartype(conf=BeartypeConf(is_pep484_tower=True)) -class HTTPX2Transport: - """A synchronous ``vws-python`` transport which uses ``httpx2``.""" - - def __init__(self) -> None: - """Create an ``HTTPX2Transport``.""" - self._client = httpx2.Client() - - def close(self) -> None: - """Close the underlying ``httpx2.Client``.""" - self._client.close() - - def __call__( - self, - *, - method: str, - url: str, - headers: dict[str, str], - data: bytes, - request_timeout: float | tuple[float, float], - ) -> Response: - """Make an HTTP request using ``httpx2``. - - Args: - method: The HTTP method. - url: The full URL. - headers: Request headers. - data: The request body. - request_timeout: The request timeout. - - Returns: - A response populated from the ``httpx2`` response. - """ - httpx2_response = self._client.request( - method=method, - url=url, - headers=headers, - content=data, - timeout=_httpx2_timeout(request_timeout=request_timeout), - follow_redirects=True, - ) - return _to_vws_response(httpx2_response=httpx2_response) - - -@beartype(conf=BeartypeConf(is_pep484_tower=True)) -class AsyncHTTPX2Transport: - """An asynchronous ``vws-python`` transport which uses ``httpx2``.""" - - def __init__(self) -> None: - """Create an ``AsyncHTTPX2Transport``.""" - self._client = httpx2.AsyncClient() - - async def aclose(self) -> None: - """Close the underlying ``httpx2.AsyncClient``.""" - await self._client.aclose() - - async def __call__( - self, - *, - method: str, - url: str, - headers: dict[str, str], - data: bytes, - request_timeout: float | tuple[float, float], - ) -> Response: - """Make an asynchronous HTTP request using ``httpx2``. - - Args: - method: The HTTP method. - url: The full URL. - headers: Request headers. - data: The request body. - request_timeout: The request timeout. - - Returns: - A response populated from the ``httpx2`` response. - """ - httpx2_response = await self._client.request( - method=method, - url=url, - headers=headers, - content=data, - timeout=_httpx2_timeout(request_timeout=request_timeout), - follow_redirects=True, - ) - return _to_vws_response(httpx2_response=httpx2_response) diff --git a/uv.lock b/uv.lock index 2acfcb7a7..9caf61c3d 100644 --- a/uv.lock +++ b/uv.lock @@ -2784,18 +2784,19 @@ wheels = [ [[package]] name = "vws-python" -version = "2026.8.26" +version = "2026.9.7" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "beartype" }, { name = "httpx" }, + { name = "httpx2" }, { name = "requests" }, { name = "urllib3" }, { name = "vws-auth-tools" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/0d/6b/89de512a99ab736c288d98181e6309419f51db5b5238209575c2612ac0e4/vws_python-2026.8.26.tar.gz", hash = "sha256:a02898c776537992fd83b11eda0df8ccf7e7341d399ca8250b99eb53c4225635", size = 81481, upload-time = "2026-08-26T10:41:23.5Z" } +sdist = { url = "https://files.pythonhosted.org/packages/5e/39/41f1093f268965d8081ad58d6eb313d0412eb45ca5f12f6ddd2e966ff80a/vws_python-2026.9.7.tar.gz", hash = "sha256:eb72367ebc301acfcbd73c0c745f164947fd717ff1880d65716b6086ae66048b", size = 86076, upload-time = "2026-09-07T17:59:19.762Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/40/21/22384bc956aa2da75f10246fd74e5333bcbc9aeac2874f18439b9fad23a8/vws_python-2026.8.26-py3-none-any.whl", hash = "sha256:066428c51411256e9fb34e4ffcfbd5049b95b86ce1f060f36263e88c48168dd3", size = 47342, upload-time = "2026-08-26T10:41:21.847Z" }, + { url = "https://files.pythonhosted.org/packages/18/3c/4633ca5f52d3a8a257034108173ab71c5bec5bf8c9bb097157326154dc71/vws_python-2026.9.7-py3-none-any.whl", hash = "sha256:2c47500a8ceb044995e7f3c29359ce846da152e166e720b46f41900fd502d159", size = 47986, upload-time = "2026-09-07T17:59:18.473Z" }, ] [[package]] @@ -2968,7 +2969,7 @@ requires-dist = [ { name = "vale", marker = "extra == 'dev'", specifier = "==3.20.0.0" }, { name = "vulture", marker = "extra == 'dev'", specifier = "==2.16" }, { name = "vws-auth-tools", specifier = ">=2024.7.12" }, - { name = "vws-python", marker = "extra == 'dev'", specifier = "==2026.8.26" }, + { name = "vws-python", marker = "extra == 'dev'", specifier = "==2026.9.7" }, { name = "vws-test-fixtures", marker = "extra == 'dev'", specifier = "==2026.8.26" }, { name = "vws-web-tools", marker = "extra == 'dev'", specifier = "==2026.8.27" }, { name = "werkzeug", specifier = ">=3.1.2" },