Skip to content

Commit 45e6c4b

Browse files
committed
Add NopChannel for testing purposes
1 parent 814b80d commit 45e6c4b

File tree

3 files changed

+43
-37
lines changed

3 files changed

+43
-37
lines changed

coagent/agents/mcp_server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
from coagent.core import BaseAgent, Context, handler, logger, Message
66
from coagent.core.exceptions import InternalError
7-
from mcp import ClientSession, Tool as MCPTool # ruff: noqa: F401
7+
from mcp import ClientSession, Tool as MCPTool # noqa: F401
88
from mcp.client.sse import sse_client
99
from mcp.client.stdio import stdio_client, StdioServerParameters
1010
from mcp.types import (
1111
CallToolResult as MCPCallToolResult,
1212
ListToolsResult as MCPListToolsResult,
13-
ImageContent as MCPImageContent, # ruff: noqa: F401
14-
TextContent as MCPTextContent, # ruff: noqa: F401
13+
ImageContent as MCPImageContent, # noqa: F401
14+
TextContent as MCPTextContent, # noqa: F401
1515
)
1616
from pydantic import BaseModel
1717

coagent/core/runtime.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import abc
22
import asyncio
3-
from typing import AsyncIterator
3+
from typing import AsyncIterator, Awaitable, Callable
44

55
import pydantic
66

@@ -14,6 +14,7 @@
1414
Runtime,
1515
Address,
1616
RawMessage,
17+
Subscription,
1718
)
1819

1920

@@ -179,3 +180,39 @@ async def __anext__(self) -> RawMessage:
179180

180181
def __aiter__(self):
181182
return self
183+
184+
185+
class NopChannel(Channel):
186+
"""A no-op channel mainly for testing purposes."""
187+
188+
async def connect(self) -> None:
189+
pass
190+
191+
async def close(self) -> None:
192+
pass
193+
194+
async def publish(
195+
self,
196+
addr: Address,
197+
msg: RawMessage,
198+
stream: bool = False,
199+
request: bool = False,
200+
reply: str = "",
201+
timeout: float = 0.5,
202+
probe: bool = True,
203+
) -> AsyncIterator[RawMessage] | RawMessage | None:
204+
pass
205+
206+
async def subscribe(
207+
self,
208+
addr: Address,
209+
handler: Callable[[RawMessage], Awaitable[None]],
210+
queue: str = "",
211+
) -> Subscription:
212+
pass
213+
214+
async def new_reply_topic(self) -> str:
215+
return ""
216+
217+
async def cancel(self, addr: Address) -> None:
218+
pass

tests/core/conftest.py

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,15 @@
11
import asyncio
22
import functools
33
import inspect
4-
from typing import Callable, Awaitable
54

65
import pytest
76

8-
from coagent.core.types import Address, Agent, RawMessage, Channel, Subscription
7+
from coagent.core.types import Agent
98
from coagent.core.util import idle_loop
9+
from coagent.core.runtime import NopChannel
1010
from coagent.runtimes.local_runtime import LocalChannel
1111

1212

13-
class NopChannel(Channel):
14-
async def connect(self) -> None:
15-
pass
16-
17-
async def close(self) -> None:
18-
pass
19-
20-
async def publish(
21-
self,
22-
addr: Address,
23-
msg: RawMessage,
24-
stream: bool = False,
25-
request: bool = False,
26-
reply: str = "",
27-
timeout: float = 0.5,
28-
probe: bool = True,
29-
) -> RawMessage | None:
30-
pass
31-
32-
async def subscribe(
33-
self,
34-
addr: Address,
35-
handler: Callable[[RawMessage], Awaitable[None]],
36-
queue: str = "",
37-
) -> Subscription:
38-
pass
39-
40-
async def new_reply_topic(self) -> str:
41-
pass
42-
43-
4413
@pytest.fixture
4514
def nop_channel() -> NopChannel:
4615
return NopChannel()

0 commit comments

Comments
 (0)