ForcePilot/backend/test/unit/channels/test_wechat_chunker.py
Kris 69fe97a90d test: 批量修复并新增单元测试用例
1. 移除Telegram格式化测试中未使用的导入项
2. 修复Teams测试用例,添加monkeypatch参数并配置通配符开关
3. 更新钉钉适配器测试,替换弃用的流属性检查
4. 修正Twitch规范化测试,更新ROOMSTATE测试逻辑
5. 重构会话映射测试,完善数据库执行结果模拟
6. 格式化Slack块构建测试的长参数调用
7. 修复LINE适配器测试,更新能力断言和异步锁使用
8. 修正Slack会话解析测试,修复聊天类型判断错误
9. 更新能力测试,补充缺失的字段检查
10. 修复Matrix适配器测试,修正位置参数和配置校验逻辑
11. 为飞书分析模块测试添加跳过标记
12. 新增微信能力、限流、链接格式、会话路由等模块的单元测试
13. 修复Twitch适配器导入路径和测试断言
14. 新增Discord Webhook、Nextcloud Talk、Signal多账户等模块的单元测试
15. 修复Manager阶段测试的导入路径
16. 新增iMessage异常和命令处理的单元测试
17. 新增Nostr健康检查和相关模块的单元测试
18. 新增Signal守护进程和SSE重连相关测试
2026-05-13 16:43:01 +08:00

93 lines
3.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from __future__ import annotations
import pytest
from yuxi.channels.adapters.wechat.chunker import WeChatChunker
class TestWeChatChunker:
def setup_method(self):
self.chunker = WeChatChunker()
def test_chunk_text_within_limit(self):
result = self.chunker.chunk_text("hello world", 2048)
assert result == ["hello world"]
def test_chunk_text_empty(self):
result = self.chunker.chunk_text("", 100)
assert result == [""]
def test_chunk_text_exact_limit(self):
text = "a" * 100
result = self.chunker.chunk_text(text, 100)
assert result == [text]
def test_chunk_text_splits_at_newline_double(self):
para1 = "A" * 2000
para2 = "B" * 2000
text = f"{para1}\n\n{para2}"
result = self.chunker.chunk_text(text, 3000)
assert len(result) == 2
assert para1 in result[0]
def test_chunk_text_splits_at_period(self):
text = ("A" * 1000 + "") * 5
result = self.chunker.chunk_text(text, 2500)
assert len(result) >= 2
def test_chunk_text_no_boundary_found_falls_back_to_limit(self):
text = "A" * 3000
result = self.chunker.chunk_text(text, 1000)
assert len(result) == 3
for chunk in result:
assert len(chunk) <= 1000
def test_chunk_text_all_chunks_within_limit(self):
text = "B" * 5000
limit = 2048
for chunk in self.chunker.chunk_text(text, limit):
assert len(chunk) <= limit
def test_chunk_markdown_within_limit(self):
result = self.chunker.chunk_markdown("hello world", 2048)
assert result == ["hello world"]
def test_chunk_markdown_preserves_code_block(self):
text = f"{'A' * 3000}```\ncode block\n```\n{'B' * 3000}"
result = self.chunker.chunk_markdown(text, 2000)
combined = "".join(result)
assert "```" in combined
assert "code block" in combined
def test_chunk_markdown_code_block_partial(self):
text = f"{'A' * 1500}```\n{'C' * 1500}\n```\n{'B' * 1500}"
result = self.chunker.chunk_markdown(text, 2000)
combined = "".join(result)
assert combined == text
def test_chunk_dispatch_text_mode(self):
text = "hello"
assert self.chunker.chunk(text, 100, "text") == ["hello"]
def test_chunk_dispatch_markdown_mode(self):
text = "hello"
assert self.chunker.chunk(text, 100, "markdown") == ["hello"]
def test_chunk_default_mode_is_text(self):
text = "default_mode"
assert self.chunker.chunk(text, 100) == ["default_mode"]
def test_find_boundary_prefers_largest_match(self):
text = "hello\nworld。test"
boundary = WeChatChunker._find_boundary(text, len(text))
assert boundary > 0
def test_find_boundary_no_match(self):
text = "a" * 100
boundary = WeChatChunker._find_boundary(text, 50)
assert boundary >= 0
def test_find_boundary_at_start(self):
text = "\n\nhello"
boundary = WeChatChunker._find_boundary(text, 5)
assert boundary >= 0