mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-05-19 16:12:30 +00:00
style: address code review feedback
- Consistent "WeChat" prefix in context_token error message - Use object() instead of httpx.AsyncClient() in new tests to avoid resource leak warnings
This commit is contained in:
parent
98c2f7cc27
commit
49c07aa45a
@ -951,7 +951,7 @@ class WeixinChannel(BaseChannel):
|
||||
ctx_token = self._context_tokens.get(msg.chat_id, "")
|
||||
if not ctx_token:
|
||||
raise RuntimeError(
|
||||
f"No context_token for chat_id={msg.chat_id}, cannot send"
|
||||
f"WeChat context_token missing for chat_id={msg.chat_id}, cannot send"
|
||||
)
|
||||
|
||||
typing_ticket = ""
|
||||
|
||||
@ -325,7 +325,7 @@ async def test_send_without_context_token_raises() -> None:
|
||||
channel._token = "token"
|
||||
channel._send_text = AsyncMock()
|
||||
|
||||
with pytest.raises(RuntimeError, match="No context_token"):
|
||||
with pytest.raises(RuntimeError, match="context_token missing"):
|
||||
await channel.send(
|
||||
type("Msg", (), {"chat_id": "unknown-user", "content": "pong", "media": [], "metadata": {}})()
|
||||
)
|
||||
@ -1227,7 +1227,7 @@ async def test_send_text_raises_on_api_error() -> None:
|
||||
"""_send_text must raise RuntimeError when the API returns a non-zero errcode,
|
||||
matching _send_media_file behavior. This ensures ChannelManager can retry."""
|
||||
channel, _bus = _make_channel()
|
||||
channel._client = httpx.AsyncClient()
|
||||
channel._client = object()
|
||||
channel._token = "token"
|
||||
channel._api_post = AsyncMock(
|
||||
return_value={"errcode": -14, "errmsg": "session expired"}
|
||||
@ -1243,7 +1243,7 @@ async def test_send_text_raises_on_api_error() -> None:
|
||||
async def test_send_text_succeeds_on_zero_errcode() -> None:
|
||||
"""_send_text must NOT raise when errcode is 0."""
|
||||
channel, _bus = _make_channel()
|
||||
channel._client = httpx.AsyncClient()
|
||||
channel._client = object()
|
||||
channel._token = "token"
|
||||
channel._api_post = AsyncMock(return_value={"errcode": 0})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user