Skip to content

Commit 7c89dbd

Browse files
committed
tests: prove DecodeError wrap is decoder-agnostic via msgspec
Seam-level test wires MsgspecDecoder into AsyncClient and asserts a malformed-JSON response still surfaces as httpware.DecodeError with exc.original carrying the underlying msgspec exception.
1 parent 15770b1 commit 7c89dbd

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎tests/test_decoders_msgspec.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
"""Unit tests for httpware.decoders.msgspec.MsgspecDecoder."""
22

3+
from http import HTTPStatus
4+
5+
import httpx2
36
import msgspec
47
import pytest
58

9+
from httpware import AsyncClient, DecodeError
610
from httpware._internal import import_checker
711
from httpware.decoders import ResponseDecoder
812
from httpware.decoders.msgspec import MsgspecDecoder
@@ -48,3 +52,21 @@ def test_construction_raises_without_extra_via_monkeypatch(
4852
monkeypatch.setattr(import_checker, "is_msgspec_installed", False)
4953
with pytest.raises(ImportError, match="MsgspecDecoder requires the 'msgspec' extra"):
5054
MsgspecDecoder()
55+
56+
57+
async def test_msgspec_decoder_failures_wrap_as_decode_error_at_seam() -> None:
58+
"""Proves wrapping is decoder-agnostic: switching to MsgspecDecoder still yields DecodeError."""
59+
60+
def handler(request: httpx2.Request) -> httpx2.Response:
61+
return httpx2.Response(HTTPStatus.OK, content=b"{not json", request=request)
62+
63+
transport = httpx2.MockTransport(handler)
64+
client = AsyncClient(
65+
httpx2_client=httpx2.AsyncClient(transport=transport),
66+
decoder=MsgspecDecoder(),
67+
)
68+
with pytest.raises(DecodeError) as exc_info:
69+
await client.get("https://example.test/x", response_model=_Item)
70+
exc = exc_info.value
71+
assert exc.model is _Item
72+
assert isinstance(exc.original, (msgspec.DecodeError, msgspec.ValidationError))

0 commit comments

Comments
 (0)