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

Class MockStreamWriter

tests/test_payload.py:186–217  ·  view source on GitHub ↗

Mock stream writer for testing payload writes.

Source from the content-addressed store, hash-verified

184
185
186class MockStreamWriter(AbstractStreamWriter):
187 """Mock stream writer for testing payload writes."""
188
189 def __init__(self) -> None:
190 self.written: list[bytes] = []
191
192 async def write(
193 self, chunk: Union[bytes, bytearray, "memoryview[int]", "memoryview[bytes]"]
194 ) -> None:
195 """Store the chunk in the written list."""
196 self.written.append(bytes(chunk))
197
198 async def write_eof(self, chunk: bytes | None = None) -> None:
199 """write_eof implementation - no-op for tests."""
200
201 async def drain(self) -> None:
202 """Drain implementation - no-op for tests."""
203
204 def enable_compression(
205 self, encoding: str = "deflate", strategy: int | None = None
206 ) -> None:
207 """Enable compression - no-op for tests."""
208
209 def enable_chunking(self) -> None:
210 """Enable chunking - no-op for tests."""
211
212 async def write_headers(self, status_line: str, headers: CIMultiDict[str]) -> None:
213 """Write headers - no-op for tests."""
214
215 def get_written_bytes(self) -> bytes:
216 """Return all written bytes as a single bytes object."""
217 return b"".join(self.written)
218
219
220async def test_bytes_payload_write_with_length_no_limit() -> None:

Calls

no outgoing calls