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:
chengyongru 2026-05-06 23:38:09 +08:00 committed by Xubin Ren
parent 98c2f7cc27
commit 49c07aa45a
2 changed files with 4 additions and 4 deletions

View File

@ -951,7 +951,7 @@ class WeixinChannel(BaseChannel):
ctx_token = self._context_tokens.get(msg.chat_id, "") ctx_token = self._context_tokens.get(msg.chat_id, "")
if not ctx_token: if not ctx_token:
raise RuntimeError( 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 = "" typing_ticket = ""

View File

@ -325,7 +325,7 @@ async def test_send_without_context_token_raises() -> None:
channel._token = "token" channel._token = "token"
channel._send_text = AsyncMock() channel._send_text = AsyncMock()
with pytest.raises(RuntimeError, match="No context_token"): with pytest.raises(RuntimeError, match="context_token missing"):
await channel.send( await channel.send(
type("Msg", (), {"chat_id": "unknown-user", "content": "pong", "media": [], "metadata": {}})() 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, """_send_text must raise RuntimeError when the API returns a non-zero errcode,
matching _send_media_file behavior. This ensures ChannelManager can retry.""" matching _send_media_file behavior. This ensures ChannelManager can retry."""
channel, _bus = _make_channel() channel, _bus = _make_channel()
channel._client = httpx.AsyncClient() channel._client = object()
channel._token = "token" channel._token = "token"
channel._api_post = AsyncMock( channel._api_post = AsyncMock(
return_value={"errcode": -14, "errmsg": "session expired"} 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: async def test_send_text_succeeds_on_zero_errcode() -> None:
"""_send_text must NOT raise when errcode is 0.""" """_send_text must NOT raise when errcode is 0."""
channel, _bus = _make_channel() channel, _bus = _make_channel()
channel._client = httpx.AsyncClient() channel._client = object()
channel._token = "token" channel._token = "token"
channel._api_post = AsyncMock(return_value={"errcode": 0}) channel._api_post = AsyncMock(return_value={"errcode": 0})