MCPcopy
hub / github.com/encode/starlette / test_request_stream_called_twice

Function test_request_stream_called_twice

tests/test_requests.py:595–630  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

593
594@pytest.mark.anyio
595async def test_request_stream_called_twice() -> None:
596 messages: list[Message] = [
597 {"type": "http.request", "body": b"1", "more_body": True},
598 {"type": "http.request", "body": b"2", "more_body": True},
599 {"type": "http.request", "body": b"3"},
600 ]
601
602 async def rcv() -> Message:
603 return messages.pop(0)
604
605 request = Request({"type": "http"}, rcv)
606
607 s1 = request.stream()
608 s2 = request.stream()
609
610 msg = await s1.__anext__()
611 assert msg == b"1"
612
613 msg = await s2.__anext__()
614 assert msg == b"2"
615
616 msg = await s1.__anext__()
617 assert msg == b"3"
618
619 # at this point we've consumed the entire body
620 # so we should not wait for more body (which would hang us forever)
621 msg = await s1.__anext__()
622 assert msg == b""
623 msg = await s2.__anext__()
624 assert msg == b""
625
626 # and now both streams are exhausted
627 with pytest.raises(StopAsyncIteration):
628 assert await s2.__anext__()
629 with pytest.raises(StopAsyncIteration):
630 await s1.__anext__()
631
632
633def test_request_url_outside_starlette_context(test_client_factory: TestClientFactory) -> None:

Callers

nothing calls this directly

Calls 3

streamMethod · 0.95
RequestClass · 0.90
__anext__Method · 0.80

Tested by

no test coverage detected