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

Function test_uploadfile_rolling

tests/test_datastructures.py:402–423  ·  tests/test_datastructures.py::test_uploadfile_rolling

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(class="st">"max_size", [1, 1024], ids=[class="st">"rolled", class="st">"unrolled"])
402async def test_uploadfile_rolling(max_size: int) -> None:
403 class="st">"""Test that we can r/w to a SpooledTemporaryFile
404 managed by UploadFile before and after it rolls to disk
405 class="st">"""
406 stream: BinaryIO = SpooledTemporaryFile( class="cm"># type: ignore[assignment]
407 max_size=max_size
408 )
409 file = UploadFile(filename=class="st">"file", file=stream, size=0)
410 assert await file.read() == bclass="st">""
411 assert file.size == 0
412 await file.write(bclass="st">"data")
413 assert await file.read() == bclass="st">""
414 assert file.size == 4
415 await file.seek(0)
416 assert await file.read() == bclass="st">"data"
417 await file.write(bclass="st">" more")
418 assert await file.read() == bclass="st">""
419 assert file.size == 9
420 await file.seek(0)
421 assert await file.read() == bclass="st">"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