-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathtest_stdio_limits.py
More file actions
41 lines (32 loc) · 1.11 KB
/
test_stdio_limits.py
File metadata and controls
41 lines (32 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import sys
import textwrap
import pytest
from acp.transports import spawn_stdio_transport
LARGE_LINE_SIZE = 70 * 1024
def _large_line_script(size: int = LARGE_LINE_SIZE) -> str:
return textwrap.dedent(
f"""
import sys
sys.stdout.write("X" * {size})
sys.stdout.write("\\n")
sys.stdout.flush()
"""
).strip()
@pytest.mark.asyncio
async def test_spawn_stdio_transport_hits_default_limit() -> None:
script = _large_line_script()
async with spawn_stdio_transport(sys.executable, "-c", script) as (reader, writer, _process):
# readline() re-raises LimitOverrunError as ValueError on CPython 3.12+.
with pytest.raises(ValueError):
await reader.readline()
@pytest.mark.asyncio
async def test_spawn_stdio_transport_custom_limit_handles_large_line() -> None:
script = _large_line_script()
async with spawn_stdio_transport(
sys.executable,
"-c",
script,
limit=LARGE_LINE_SIZE * 2,
) as (reader, writer, _process):
line = await reader.readline()
assert len(line) == LARGE_LINE_SIZE + 1