MCPcopy Create free account
hub / github.com/encode/starlette / test_uploadfile_rolling

Function test_uploadfile_rolling

tests/test_datastructures.py:454–475  ·  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

452@pytest.mark.anyio
453@pytest.mark.parametrize("max_size", [1, 1024], ids=["rolled", "unrolled"])
454async def test_uploadfile_rolling(max_size: int) -> None:
455 """Test that we can r/w to a SpooledTemporaryFile
456 managed by UploadFile before and after it rolls to disk
457 """
458 stream: BinaryIO = SpooledTemporaryFile( # type: ignore[assignment]
459 max_size=max_size
460 )
461 file = UploadFile(filename="file", file=stream, size=0)
462 assert await file.read() == b""
463 assert file.size == 0
464 await file.write(b"data")
465 assert await file.read() == b""
466 assert file.size == 4
467 await file.seek(0)
468 assert await file.read() == b"data"
469 await file.write(b" more")
470 assert await file.read() == b""
471 assert file.size == 9
472 await file.seek(0)
473 assert await file.read() == b"data more"
474 assert file.size == 9
475 await file.close()
476
477
478def 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