Skip to content

Commit da5ed1c

Browse files
lesnik512claude
andcommitted
test: overload selection + public-API surface assertions
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ae5a742 commit da5ed1c

2 files changed

Lines changed: 109 additions & 0 deletions

File tree

‎tests/test_client_typing.py‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""Static-typing tests for AsyncClient overloads.
2+
3+
These assert overload selection at runtime via isinstance checks. ty/mypy
4+
catches the static-typing variant during `just lint`.
5+
"""
6+
7+
from http import HTTPStatus
8+
9+
import httpx2
10+
import pydantic
11+
12+
from httpware import AsyncClient
13+
14+
15+
class _User(pydantic.BaseModel):
16+
id: int
17+
name: str
18+
19+
20+
async def test_get_without_response_model_returns_response() -> None:
21+
transport = httpx2.MockTransport(
22+
lambda req: httpx2.Response(HTTPStatus.OK, request=req, json={"id": 1, "name": "a"})
23+
)
24+
client = AsyncClient(httpx2_client=httpx2.AsyncClient(transport=transport))
25+
result = await client.get("https://example.test/x")
26+
assert isinstance(result, httpx2.Response)
27+
28+
29+
async def test_get_with_response_model_returns_typed() -> None:
30+
transport = httpx2.MockTransport(
31+
lambda req: httpx2.Response(HTTPStatus.OK, request=req, json={"id": 1, "name": "a"})
32+
)
33+
client = AsyncClient(httpx2_client=httpx2.AsyncClient(transport=transport))
34+
result = await client.get("https://example.test/x", response_model=_User)
35+
assert isinstance(result, _User)
36+
37+
38+
async def test_send_without_response_model_returns_response() -> None:
39+
transport = httpx2.MockTransport(
40+
lambda req: httpx2.Response(HTTPStatus.OK, request=req, json={"id": 1, "name": "a"})
41+
)
42+
client = AsyncClient(httpx2_client=httpx2.AsyncClient(transport=transport))
43+
result = await client.send(httpx2.Request("GET", "https://example.test/x"))
44+
assert isinstance(result, httpx2.Response)
45+
46+
47+
async def test_send_with_response_model_returns_typed() -> None:
48+
transport = httpx2.MockTransport(
49+
lambda req: httpx2.Response(HTTPStatus.OK, request=req, json={"id": 1, "name": "a"})
50+
)
51+
client = AsyncClient(httpx2_client=httpx2.AsyncClient(transport=transport))
52+
result = await client.send(httpx2.Request("GET", "https://example.test/x"), response_model=_User)
53+
assert isinstance(result, _User)

‎tests/test_public_api.py‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""Public API surface — what `from httpware import ...` exposes."""
2+
3+
import httpware
4+
5+
6+
def test_all_exports_resolve() -> None:
7+
for symbol in httpware.__all__:
8+
assert hasattr(httpware, symbol), f"{symbol} declared in __all__ but missing"
9+
10+
11+
def test_no_removed_symbols_leaked() -> None:
12+
removed = {
13+
"Request",
14+
"Response",
15+
"StreamResponse",
16+
"Timeout",
17+
"Limits",
18+
"ClientConfig",
19+
"Transport",
20+
"Httpx2Transport",
21+
"RecordedTransport",
22+
"AuthValue",
23+
}
24+
leaked = removed & set(dir(httpware))
25+
assert not leaked, f"removed 0.1 symbols still exposed: {leaked}"
26+
27+
28+
def test_expected_exports() -> None:
29+
expected = {
30+
"AsyncClient",
31+
"Middleware",
32+
"Next",
33+
"ResponseDecoder",
34+
"PydanticDecoder",
35+
"ClientError",
36+
"TransportError",
37+
"TimeoutError",
38+
"StatusError",
39+
"ClientStatusError",
40+
"ServerStatusError",
41+
"BadRequestError",
42+
"UnauthorizedError",
43+
"ForbiddenError",
44+
"NotFoundError",
45+
"ConflictError",
46+
"UnprocessableEntityError",
47+
"RateLimitedError",
48+
"InternalServerError",
49+
"ServiceUnavailableError",
50+
"STATUS_TO_EXCEPTION",
51+
"before_request",
52+
"after_response",
53+
"on_error",
54+
}
55+
missing = expected - set(httpware.__all__)
56+
assert not missing, f"expected exports missing from __all__: {missing}"

0 commit comments

Comments
 (0)