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

Function test_uploadfile_rolling

tests/test_datastructures.py:402–423  ·  view source on GitHub ↗

Test that we can r/w to a SpooledTemporaryFile managed by UploadFile before and after it rolls to disk

(max_size: int)

Source from the content-addressed store, hash-verified

400@pytest.mark.anyio
401@pytest.mark.parametrize("max_size", [1, 1024], ids=["rolled", "unrolled"])
402async def test_uploadfile_rolling(max_size: int) -> None:
403 """Test that we can r/w to a SpooledTemporaryFile
404 managed by UploadFile before and after it rolls to disk
405 """
406 stream: BinaryIO = SpooledTemporaryFile( # type: ignore[assignment]
407 max_size=max_size
408 )
409 file = UploadFile(filename="file", file=stream, size=0)
410 assert await file.read() == b""
411 assert file.size == 0
412 await file.write(b"data")
413 assert await file.read() == b""
414 assert file.size == 4
415 await file.seek(0)
416 assert await file.read() == b"data"
417 await file.write(b" more")
418 assert await file.read() == b""
419 assert file.size == 9
420 await file.seek(0)
421 assert await file.read() == b"data more"
422 assert file.size == 9
423 await file.close()
424
425
426def test_formdata() -> None:

Callers

nothing calls this directly

Calls 5

readMethod · 0.95
writeMethod · 0.95
seekMethod · 0.95
closeMethod · 0.95
UploadFileClass · 0.90

Tested by

no test coverage detected