690b903f85
* chore: add pytest-asyncio in auto mode * test: migrate channel and stream tests to native async Convert run_async() wrapper tests to plain 'async def test_*' under pytest-asyncio auto mode. collect_events() in stream_v3_fakes becomes a coroutine awaited at every call site. * test: migrate command and model/middleware tests to native async Convert run_async() wrappers (import, alias, and fixture forms) to plain 'async def test_*'. Multi-call tests merge onto one loop as sequential awaits; none asserted on loop identity. * test: migrate TUI, notifier, gateway, and session tests to native async TUI/notifier/gateway files convert run_async wrappers to plain async tests. test_sessions.py's unittest.TestCase classes move to unittest.IsolatedAsyncioTestCase (pytest-asyncio does not await async methods on plain TestCase; converting blindly would have made ~70 tests silently vacuous). Its setUpClass keeps a one-shot asyncio.run() since IsolatedAsyncioTestCase has no async class-level hook. TestLoadingWidget in test_tui_widgets.py drops its TestCase base for the same reason. * test: replace direct asyncio.run() calls with native async tests Convert tests that called asyncio.run() (directly or via a local _run helper) to plain 'async def test_*'; delete the local helpers. * test: drop undeclared anyio markers and delete run_async helper The @pytest.mark.anyio tests relied on anyio being a transitive dep of httpx; auto-mode pytest-asyncio collects them natively. run_async() and its fixture are unreferenced after the migration, so remove them — pytest-asyncio's per-test loop teardown covers the pending-task cancellation the helper existed for (verified: full suite runs with no 'Event loop is closed' errors or destroyed-task warnings).
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
"""Tests for Discord channel implementation."""
|
|
|
|
import pytest
|
|
|
|
from EvoScientist.channels.base import ChannelError
|
|
from EvoScientist.channels.discord.channel import DiscordChannel, DiscordConfig
|
|
|
|
|
|
class TestDiscordChannel:
|
|
def test_init(self):
|
|
config = DiscordConfig(bot_token="test")
|
|
channel = DiscordChannel(config)
|
|
assert channel.config is config
|
|
assert channel._running is False
|
|
|
|
async def test_start_raises_without_token_or_library(self):
|
|
config = DiscordConfig(bot_token="")
|
|
channel = DiscordChannel(config)
|
|
with pytest.raises(ChannelError):
|
|
await channel.start()
|
|
|
|
async def test_stop_when_not_running(self):
|
|
config = DiscordConfig(bot_token="test")
|
|
channel = DiscordChannel(config)
|
|
await channel.stop()
|
|
|
|
async def test_send_returns_false_without_client(self):
|
|
from EvoScientist.channels.base import OutboundMessage
|
|
|
|
config = DiscordConfig(bot_token="test")
|
|
channel = DiscordChannel(config)
|
|
msg = OutboundMessage(
|
|
channel="discord",
|
|
chat_id="123",
|
|
content="hello",
|
|
metadata={"chat_id": "123"},
|
|
)
|
|
result = await channel.send(msg)
|
|
assert result is False
|