MCPcopy Create free account
hub / github.com/aio-libs/aiohttp / test_data_stream

Function test_data_stream

tests/test_client_request.py:1116–1141  ·  view source on GitHub ↗
(loop, buf, conn)

Source from the content-addressed store, hash-verified

1114
1115
1116async def test_data_stream(loop, buf, conn) -> None:
1117 async def gen():
1118 yield b"binary data"
1119 yield b" result"
1120
1121 req = ClientRequest("POST", URL("http://python.org/"), data=gen(), loop=loop)
1122 assert req.chunked
1123 assert req.headers["TRANSFER-ENCODING"] == "chunked"
1124 original_write_bytes = req.write_bytes
1125
1126 async def _mock_write_bytes(
1127 writer: AbstractStreamWriter, conn: mock.Mock, content_length: int | None
1128 ) -> None:
1129 # Ensure the task is scheduled
1130 await asyncio.sleep(0)
1131 await original_write_bytes(writer, conn, content_length)
1132
1133 with mock.patch.object(req, "write_bytes", _mock_write_bytes):
1134 resp = await req.send(conn)
1135 assert asyncio.isfuture(req._writer)
1136 await resp.wait_for_close()
1137 assert req._writer is None
1138 assert (
1139 buf.split(b"\r\n\r\n", 1)[1] == b"b\r\nbinary data\r\n7\r\n result\r\n0\r\n\r\n"
1140 )
1141 await req.close()
1142
1143
1144async def test_data_stream_deprecated(loop, buf, conn) -> None:

Callers

nothing calls this directly

Calls 5

sendMethod · 0.95
closeMethod · 0.95
ClientRequestClass · 0.90
wait_for_closeMethod · 0.80
genFunction · 0.70

Tested by

no test coverage detected