Skip to content
Open
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
2 changes: 1 addition & 1 deletion examples/sandbox_05_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import webbrowser

import httpx
import httpx2 as httpx
from dotenv import load_dotenv

from vercel.sandbox import AsyncSandbox as Sandbox
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dev = [
"pytest-asyncio<2",
"pytest-xdist<4",
"hypothesis>=6.0.0,<7",
"respx>=0.21.0,<1",
"respx==0.23.1",
"uvloop<1",
"mypy>=1.20.2,<2",
"build<2",
Expand Down Expand Up @@ -38,7 +38,7 @@ markers = [
[tool.mypy]
ignore_missing_imports = true
explicit_package_bases = true
mypy_path = ["src", "src/vercel-oidc", "src/vercel-headers"]
mypy_path = ["src", "src/vercel-oidc", "src/vercel-headers", "tests/stubs"]

[tool.ruff]
line-length = 100
Expand Down
2 changes: 1 addition & 1 deletion src/vercel-oidc/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ requires-python = ">=3.10"
license = "MIT"
license-files = ["LICENSE", "LICENSE.*"]
dependencies = [
"httpx>=0.27.0,<1",
"httpx2[http2]>=2",
"vercel-headers>=0.6.0",
]

Expand Down
2 changes: 1 addition & 1 deletion src/vercel-oidc/vercel/oidc/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
from collections.abc import Mapping

import httpx
import httpx2 as httpx

from vercel.headers import get_headers

Expand Down
2 changes: 1 addition & 1 deletion src/vercel/_internal/blob/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import Any, Literal, cast
from urllib.parse import parse_qs, urlencode, urlparse, urlunparse

import httpx
import httpx2 as httpx

from vercel._internal.blob import (
PutHeaders,
Expand Down
2 changes: 1 addition & 1 deletion src/vercel/_internal/http/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from collections.abc import Sequence
from typing import Any

import httpx
import httpx2 as httpx

from vercel._internal.http.config import DEFAULT_TIMEOUT
from vercel._internal.http.request_client import (
Expand Down
2 changes: 1 addition & 1 deletion src/vercel/_internal/http/request_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from dataclasses import dataclass
from typing import Any, cast

import httpx
import httpx2 as httpx

from vercel._internal.http.transport import BaseTransport, RequestBody

Expand Down
2 changes: 1 addition & 1 deletion src/vercel/_internal/http/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dataclasses import dataclass
from typing import Any

import httpx
import httpx2 as httpx


def _normalize_path(path: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/vercel/_internal/sandbox/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from importlib.metadata import version as _pkg_version
from typing import Any, TypeAlias, cast

import httpx
import httpx2 as httpx

from vercel._internal.fs import (
FileHandle,
Expand Down
2 changes: 1 addition & 1 deletion src/vercel/_internal/sandbox/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

import httpx
import httpx2 as httpx


def _normalize_retry_after(value: str | int | None) -> int | str | None:
Expand Down
2 changes: 1 addition & 1 deletion src/vercel/_internal/sandbox/pty_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pathlib import Path

import httpx
import httpx2 as httpx

from .constants import PTY_BINARY_DOWNLOAD_TIMEOUT
from .time import to_seconds_float
Expand Down
2 changes: 1 addition & 1 deletion src/vercel/_internal/telemetry/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import uuid
from typing import Any

import httpx
import httpx2 as httpx

from vercel._internal.telemetry.credentials import extract_credentials

Expand Down
2 changes: 1 addition & 1 deletion src/vercel/_internal/workflow/worlds/vercel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import Any, TypeVar

import cbor2
import httpx
import httpx2 as httpx
import pydantic

from vercel._internal.polyfills import UTC
Expand Down
2 changes: 1 addition & 1 deletion src/vercel/cache/cache_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
from collections.abc import Callable, Mapping, Sequence

import httpx
import httpx2 as httpx

from vercel._internal.telemetry.tracker import track

Expand Down
2 changes: 1 addition & 1 deletion src/vercel/deployments/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
from typing import Any

import httpx
import httpx2 as httpx

from vercel._internal.telemetry.tracker import track

Expand Down
2 changes: 1 addition & 1 deletion src/vercel/projects/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import urllib.parse
from typing import Any

import httpx
import httpx2 as httpx

from vercel._internal.telemetry.tracker import track

Expand Down
2 changes: 1 addition & 1 deletion src/vercel/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ requires-python = ">=3.10"
license = "MIT"
license-files = ["LICENSE", "LICENSE.*"]
dependencies = [
"httpx>=0.27.0,<1",
"httpx2[http2]>=2",
"pydantic>=2.7.0,<3",
"anyio>=4.0.0,<5",
"typing-extensions>=4.0.0,<5 ; python_version < '3.11'",
Expand Down
68 changes: 68 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,76 @@
import uuid
from collections.abc import Generator
from pathlib import Path
from typing import Any

import httpcore2
import httpx2
import pytest
import respx
import respx.mocks
import respx.models
import respx.router
from respx.mocks import HTTPCoreMocker


class HTTPCore2Mocker(HTTPCoreMocker):
name = "httpcore2"
targets = [
"httpcore2._sync.connection.HTTPConnection",
"httpcore2._sync.connection_pool.ConnectionPool",
"httpcore2._sync.http_proxy.HTTPProxy",
"httpcore2._async.connection.AsyncHTTPConnection",
"httpcore2._async.connection_pool.AsyncConnectionPool",
"httpcore2._async.http_proxy.AsyncHTTPProxy",
]

@classmethod
def to_httpx_request(cls, **kwargs: Any) -> httpx2.Request:
request = kwargs["request"]
method = (
request.method.decode("ascii")
if isinstance(request.method, bytes)
else request.method
)
scheme = (
request.url.scheme.decode("ascii")
if isinstance(request.url.scheme, bytes)
else request.url.scheme
)
host = (
request.url.host.decode("ascii")
if isinstance(request.url.host, bytes)
else request.url.host
)
return httpx2.Request(
method,
httpx2.URL(
scheme=scheme,
host=host,
port=request.url.port,
raw_path=request.url.target,
),
headers=request.headers,
stream=request.stream,
extensions=request.extensions,
)

@classmethod
def from_sync_httpx_response(
cls, httpx_response: httpx2.Response, target: object, **kwargs: Any
) -> httpcore2.Response:
return httpcore2.Response(
status=httpx_response.status_code,
headers=httpx_response.headers.raw,
content=httpx_response.stream,
extensions=httpx_response.extensions,
)


respx.models.httpx = httpx2
respx.mocks.httpx = httpx2
respx.router.httpx = httpx2
respx.mocks.DEFAULT_MOCKER = HTTPCore2Mocker.name


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_blob_multipart_auto_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from collections.abc import Callable
from typing import Any

import httpx
import httpx2 as httpx
import pytest
import respx

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_blob_sync_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import io

import httpx
import httpx2 as httpx
import pytest
import respx

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_http_transport_raw_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
import respx
from httpx import Response
from httpx2 import Response

from vercel._internal.http import (
AsyncTransport,
Expand Down
14 changes: 10 additions & 4 deletions tests/integration/test_http_url_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import pytest
import respx
from httpx import Response
from httpx2 import Response

from vercel._internal.http import (
AsyncTransport,
Expand Down Expand Up @@ -59,7 +59,9 @@ class TestUrlNormalization:
@respx.mock
def test_sync_normalization_consistency(self, base_url: str, path: str, expected_url: str):
"""Test that SyncTransport normalizes URLs consistently."""
route = respx.get(expected_url).mock(return_value=Response(200, json={"ok": True}))
route = respx.get(expected_url).mock(
return_value=Response(200, json={"ok": True})
)

client = create_base_client(timeout=30.0, base_url=base_url)
transport = SyncTransport(client)
Expand Down Expand Up @@ -93,7 +95,9 @@ async def test_async_normalization_consistency(
self, base_url: str, path: str, expected_url: str
):
"""Test that AsyncTransport normalizes URLs consistently."""
route = respx.get(expected_url).mock(return_value=Response(200, json={"ok": True}))
route = respx.get(expected_url).mock(
return_value=Response(200, json={"ok": True})
)

client = create_base_async_client(timeout=30.0, base_url=base_url)
transport = AsyncTransport(client)
Expand Down Expand Up @@ -136,7 +140,9 @@ class TestEdgeCases:
@respx.mock
def test_edge_cases(self, base_url: str, path: str, expected_url: str):
"""Test edge cases for URL construction."""
route = respx.get(expected_url).mock(return_value=Response(200, json={"ok": True}))
route = respx.get(expected_url).mock(
return_value=Response(200, json={"ok": True})
)

client = create_base_client(timeout=30.0, base_url=base_url)
transport = SyncTransport(client)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_sandbox_streaming_errors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Test that non-2xx streaming responses raise sandbox-specific errors."""

import httpx
import httpx2 as httpx
import pytest
import respx

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_sandbox_sync_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pathlib import Path
from unittest.mock import AsyncMock

import httpx
import httpx2 as httpx
import pytest
import respx

Expand Down
Loading
Loading