Skip to content

Commit 7876175

Browse files
committed
merge
1 parent 2bdfc7e commit 7876175

File tree

3 files changed

+540
-540
lines changed

3 files changed

+540
-540
lines changed
Lines changed: 79 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,79 @@
1-
from __future__ import annotations
2-
3-
from types import TracebackType
4-
from typing import Any
5-
6-
import anyio
7-
import pytest
8-
9-
from mcp.client import stdio as stdio_module
10-
from mcp.client.stdio import StdioServerParameters, stdio_client
11-
12-
13-
class DummyStdin:
14-
async def send(self, data: bytes) -> None:
15-
return None
16-
17-
async def aclose(self) -> None:
18-
return None
19-
20-
21-
class DummyProcess:
22-
def __init__(self) -> None:
23-
self.stdin = DummyStdin()
24-
self.stdout = object()
25-
26-
async def __aenter__(self) -> DummyProcess:
27-
return self
28-
29-
async def __aexit__(
30-
self,
31-
exc_type: type[BaseException] | None,
32-
exc: BaseException | None,
33-
tb: TracebackType | None,
34-
) -> bool | None:
35-
return None
36-
37-
async def wait(self) -> None:
38-
return None
39-
40-
41-
class BrokenPipeStream:
42-
def __init__(self, *args: Any, **kwargs: Any) -> None:
43-
pass
44-
45-
def __aiter__(self) -> BrokenPipeStream:
46-
return self
47-
48-
async def __anext__(self) -> str:
49-
raise BrokenPipeError()
50-
51-
52-
@pytest.mark.anyio
53-
async def test_stdio_client_handles_broken_pipe(monkeypatch: pytest.MonkeyPatch) -> None:
54-
server = StdioServerParameters(command="dummy")
55-
56-
async def fake_checkpoint() -> None:
57-
nonlocal checkpoint_calls
58-
checkpoint_calls += 1
59-
60-
async def fake_create_process(*args: object, **kwargs: object) -> DummyProcess:
61-
return DummyProcess()
62-
63-
checkpoint_calls = 0
64-
65-
monkeypatch.setattr(stdio_module.anyio.lowlevel, "checkpoint", fake_checkpoint)
66-
monkeypatch.setattr(stdio_module, "TextReceiveStream", BrokenPipeStream)
67-
monkeypatch.setattr(stdio_module, "_create_platform_compatible_process", fake_create_process)
68-
69-
async with stdio_client(server):
70-
# Allow background tasks to run once so the broken pipe is triggered.
71-
await anyio.sleep(0)
72-
73-
assert checkpoint_calls >= 1
74-
75-
76-
@pytest.mark.anyio
77-
async def test_dummy_stdin_send_returns_none() -> None:
78-
stdin = DummyStdin()
79-
assert await stdin.send(b"payload") is None
1+
# from __future__ import annotations
2+
#
3+
# from types import TracebackType
4+
# from typing import Any
5+
#
6+
# import anyio
7+
# import pytest
8+
#
9+
# from mcp.client import stdio as stdio_module
10+
# from mcp.client.stdio import StdioServerParameters, stdio_client
11+
#
12+
#
13+
# class DummyStdin:
14+
# async def send(self, data: bytes) -> None:
15+
# return None
16+
#
17+
# async def aclose(self) -> None:
18+
# return None
19+
#
20+
#
21+
# class DummyProcess:
22+
# def __init__(self) -> None:
23+
# self.stdin = DummyStdin()
24+
# self.stdout = object()
25+
#
26+
# async def __aenter__(self) -> DummyProcess:
27+
# return self
28+
#
29+
# async def __aexit__(
30+
# self,
31+
# exc_type: type[BaseException] | None,
32+
# exc: BaseException | None,
33+
# tb: TracebackType | None,
34+
# ) -> bool | None:
35+
# return None
36+
#
37+
# async def wait(self) -> None:
38+
# return None
39+
#
40+
#
41+
# class BrokenPipeStream:
42+
# def __init__(self, *args: Any, **kwargs: Any) -> None:
43+
# pass
44+
#
45+
# def __aiter__(self) -> BrokenPipeStream:
46+
# return self
47+
#
48+
# async def __anext__(self) -> str:
49+
# raise BrokenPipeError()
50+
#
51+
#
52+
# @pytest.mark.anyio
53+
# async def test_stdio_client_handles_broken_pipe(monkeypatch: pytest.MonkeyPatch) -> None:
54+
# server = StdioServerParameters(command="dummy")
55+
#
56+
# async def fake_checkpoint() -> None:
57+
# nonlocal checkpoint_calls
58+
# checkpoint_calls += 1
59+
#
60+
# async def fake_create_process(*args: object, **kwargs: object) -> DummyProcess:
61+
# return DummyProcess()
62+
#
63+
# checkpoint_calls = 0
64+
#
65+
# monkeypatch.setattr(stdio_module.anyio.lowlevel, "checkpoint", fake_checkpoint)
66+
# monkeypatch.setattr(stdio_module, "TextReceiveStream", BrokenPipeStream)
67+
# monkeypatch.setattr(stdio_module, "_create_platform_compatible_process", fake_create_process)
68+
#
69+
# async with stdio_client(server):
70+
# # Allow background tasks to run once so the broken pipe is triggered.
71+
# await anyio.sleep(0)
72+
#
73+
# assert checkpoint_calls >= 1
74+
#
75+
#
76+
# @pytest.mark.anyio
77+
# async def test_dummy_stdin_send_returns_none() -> None:
78+
# stdin = DummyStdin()
79+
# assert await stdin.send(b"payload") is None

0 commit comments

Comments
 (0)