Skip to content

Commit 58b3182

Browse files
committed
Update tests
1 parent 7753344 commit 58b3182

File tree

3 files changed

+52
-42
lines changed

3 files changed

+52
-42
lines changed

tests/core/__init__.py

Whitespace-only changes.

tests/core/conftest.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from typing import Callable, Awaitable, AsyncIterator
2+
3+
import pytest
4+
5+
from coagent.core.types import Address, RawMessage, Channel, Subscription
6+
7+
8+
class TestChannel(Channel):
9+
async def connect(self) -> None:
10+
pass
11+
12+
async def close(self) -> None:
13+
pass
14+
15+
async def publish(
16+
self,
17+
addr: Address,
18+
msg: RawMessage,
19+
request: bool = False,
20+
reply: str = "",
21+
timeout: float = 0.5,
22+
probe: bool = True,
23+
) -> RawMessage | None:
24+
pass
25+
26+
async def publish_multi(
27+
self,
28+
addr: Address,
29+
msg: RawMessage,
30+
probe: bool = True,
31+
) -> AsyncIterator[RawMessage]:
32+
pass
33+
34+
async def subscribe(
35+
self,
36+
addr: Address,
37+
handler: Callable[[RawMessage], Awaitable[None]],
38+
queue: str = "",
39+
) -> Subscription:
40+
pass
41+
42+
async def new_reply_topic(self) -> str:
43+
pass
44+
45+
46+
@pytest.fixture
47+
def test_channel() -> TestChannel:
48+
return TestChannel()

tests/core/test_agent.py

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,12 @@
11
import asyncio
2+
23
import pytest
3-
from typing import Callable, Awaitable, AsyncIterator
44

5-
from coagent.core.types import Address, RawMessage, Channel, Subscription
5+
from coagent.core.types import Address
66
from coagent.core.agent import BaseAgent, Context, handler
77
from coagent.core.messages import Cancel, Message
88

99

10-
class TestChannel(Channel):
11-
async def connect(self) -> None:
12-
pass
13-
14-
async def close(self) -> None:
15-
pass
16-
17-
async def publish(
18-
self,
19-
addr: Address,
20-
msg: RawMessage,
21-
request: bool = False,
22-
reply: str = "",
23-
timeout: float = 0.5,
24-
probe: bool = True,
25-
) -> RawMessage | None:
26-
pass
27-
28-
async def publish_multi(
29-
self,
30-
addr: Address,
31-
msg: RawMessage,
32-
probe: bool = True,
33-
) -> AsyncIterator[RawMessage]:
34-
pass
35-
36-
async def subscribe(
37-
self,
38-
addr: Address,
39-
handler: Callable[[RawMessage], Awaitable[None]],
40-
queue: str = "",
41-
) -> Subscription:
42-
pass
43-
44-
async def new_reply_topic(self) -> str:
45-
pass
46-
47-
4810
class Run(Message):
4911
pass
5012

@@ -64,9 +26,9 @@ async def handle(self, msg: Run, ctx: Context) -> None:
6426

6527
class TestBlockingAgent:
6628
@pytest.mark.asyncio
67-
async def test_receive(self):
29+
async def test_receive(self, test_channel):
6830
agent = BlockingAgent()
69-
agent.init(TestChannel(), Address(name="test", id="0"))
31+
agent.init(test_channel, Address(name="test", id="0"))
7032
await agent.start()
7133

7234
await agent.receive(Run().encode())

0 commit comments

Comments
 (0)