From 1d5173cd9538f409972206987893823e6ef5de18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Wed, 2 Jul 2025 13:39:08 +0300 Subject: [PATCH] Fixed missing coverage --- tests/test_content.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/test_content.py b/tests/test_content.py index b43b65a6..196551a6 100644 --- a/tests/test_content.py +++ b/tests/test_content.py @@ -65,10 +65,20 @@ async def test_bytesio_content(): @pytest.mark.anyio async def test_async_bytesio_content(): - async def fixed_stream(content: bytes) -> AsyncGenerator[bytes]: - yield content + class AsyncBytesIO: + def __init__(self, content: bytes) -> None: + self._idx = 0 + self._content = content - request = httpx.Request(method, url, content=fixed_stream(b"Hello, world!")) + async def aread(self, chunk_size: int) -> bytes: + chunk = self._content[self._idx : self._idx + chunk_size] + self._idx = self._idx + chunk_size + return chunk + + async def __aiter__(self): + yield self._content # pragma: no cover + + request = httpx.Request(method, url, content=AsyncBytesIO(b"Hello, world!")) assert not isinstance(request.stream, typing.Iterable) assert isinstance(request.stream, typing.AsyncIterable)