Files
EvoScientist/tests/test_slack_channel.py
dinos 690b903f85 test: standardize async tests on pytest-asyncio auto mode (#338)
* 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).
2026-07-08 18:37:48 +00:00

78 lines
2.6 KiB
Python

"""Tests for Slack channel implementation."""
import pytest
from EvoScientist.channels.base import ChannelError
from EvoScientist.channels.slack.channel import SlackChannel, SlackConfig
class TestSlackConfig:
def test_default_values(self):
config = SlackConfig()
assert config.bot_token == ""
assert config.app_token == ""
assert config.allowed_senders is None
assert config.allowed_channels is None
assert config.text_chunk_limit == 4096
def test_custom_values(self):
config = SlackConfig(
bot_token="xoxb-test",
app_token="xapp-test",
allowed_senders={"U123"},
allowed_channels={"C456"},
text_chunk_limit=2000,
)
assert config.bot_token == "xoxb-test"
assert config.app_token == "xapp-test"
assert config.allowed_senders == {"U123"}
assert config.allowed_channels == {"C456"}
assert config.text_chunk_limit == 2000
class TestSlackChannel:
def test_init(self):
config = SlackConfig(bot_token="xoxb-test", app_token="xapp-test")
channel = SlackChannel(config)
assert channel.config is config
assert channel._running is False
async def test_start_raises_without_bot_token(self):
config = SlackConfig(bot_token="", app_token="xapp-test")
channel = SlackChannel(config)
with pytest.raises(ChannelError, match="bot token"):
await channel.start()
async def test_start_raises_without_app_token(self):
config = SlackConfig(bot_token="xoxb-test", app_token="")
channel = SlackChannel(config)
with pytest.raises(ChannelError, match="app token"):
await channel.start()
async def test_stop_when_not_running(self):
config = SlackConfig(bot_token="xoxb-test", app_token="xapp-test")
channel = SlackChannel(config)
await channel.stop()
async def test_send_returns_false_without_client(self):
from EvoScientist.channels.base import OutboundMessage
config = SlackConfig(bot_token="xoxb-test", app_token="xapp-test")
channel = SlackChannel(config)
msg = OutboundMessage(
channel="slack",
chat_id="C123",
content="hello",
metadata={"chat_id": "C123"},
)
result = await channel.send(msg)
assert result is False
class TestSlackChannelRegistration:
def test_slack_registered(self):
from EvoScientist.channels.channel_manager import available_channels
channels = available_channels()
assert "slack" in channels