|
1 | 1 | """Unit tests for httpware.decoders.msgspec.MsgspecDecoder.""" |
2 | 2 |
|
| 3 | +from http import HTTPStatus |
| 4 | + |
| 5 | +import httpx2 |
3 | 6 | import msgspec |
4 | 7 | import pytest |
5 | 8 |
|
| 9 | +from httpware import AsyncClient, DecodeError |
6 | 10 | from httpware._internal import import_checker |
7 | 11 | from httpware.decoders import ResponseDecoder |
8 | 12 | from httpware.decoders.msgspec import MsgspecDecoder |
@@ -48,3 +52,21 @@ def test_construction_raises_without_extra_via_monkeypatch( |
48 | 52 | monkeypatch.setattr(import_checker, "is_msgspec_installed", False) |
49 | 53 | with pytest.raises(ImportError, match="MsgspecDecoder requires the 'msgspec' extra"): |
50 | 54 | 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