MCPcopy
hub / github.com/nonebot/nonebot2 / test_aiohttp_stream_request_skip_empty_chunk

Function test_aiohttp_stream_request_skip_empty_chunk

tests/test_driver.py:602–638  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

600
601@pytest.mark.anyio
602async def test_aiohttp_stream_request_skip_empty_chunk() -> None:
603 class _FakeContent:
604 async def iter_chunked(self, _: int):
605 for chunk in (b"ab", b"", b"cd", b"e"):
606 yield chunk
607
608 class _FakeResponse:
609 def __init__(self) -> None:
610 self.status = 200
611 self.headers = {"x-test": "1"}
612 self.content = _FakeContent()
613
614 class _FakeRequestContext:
615 async def __aenter__(self) -> _FakeResponse:
616 return _FakeResponse()
617
618 async def __aexit__(self, *args: object) -> bool:
619 return False
620
621 class _FakeClient:
622 def request(self, *args: object, **kwargs: object) -> _FakeRequestContext:
623 return _FakeRequestContext()
624
625 session = AiohttpSession()
626 session._client = _FakeClient() # type: ignore[assignment]
627
628 chunks = []
629 async for resp in session.stream_request(
630 Request("GET", "https://example.com"), chunk_size=2
631 ):
632 assert resp.status_code == 200
633 assert resp.content
634 chunks.append(resp.content)
635
636 assert chunks == [b"ab", b"cd", b"e"]
637 assert b"".join(chunks) == b"abcde"
638 assert all(len(chunk) == 2 for chunk in chunks[:-1])
639
640
641@pytest.mark.anyio

Callers

nothing calls this directly

Calls 5

_FakeClientClass · 0.85
appendMethod · 0.80
RequestClass · 0.50
stream_requestMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected