ForcePilot/backend/test/unit/channels/test_telegram_format.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

74 lines
2.2 KiB
Python

from __future__ import annotations
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from yuxi.channels.adapters.telegram.format import (
markdown_to_html,
strip_all_tags,
_convert_bold,
_convert_italic,
_convert_links,
_sanitize_html,
)
class TestMarkdownToHTML:
def test_bold_conversion(self):
result = markdown_to_html("**hello**")
assert result == "<b>hello</b>"
def test_italic_conversion(self):
result = markdown_to_html("*hello*")
assert "<i>hello</i>" in result
def test_italic_underscore(self):
result = markdown_to_html("_hello_")
assert "<i>hello</i>" in result
def test_bold_and_italic(self):
result = markdown_to_html("**bold** and *italic*")
assert "<b>bold</b>" in result
assert "<i>italic</i>" in result
def test_strikethrough(self):
result = markdown_to_html("~~deleted~~")
assert "<s>deleted</s>" in result
def test_inline_code(self):
result = markdown_to_html("use `print()`")
assert "<code>print()</code>" in result
def test_code_block(self):
result = markdown_to_html("```python\nprint('hello')\n```")
assert "<pre>" in result
assert "print" in result
def test_link_conversion(self):
result = markdown_to_html("[click here](https://example.com)")
assert '<a href="https://example.com">click here</a>' in result
def test_spoiler_conversion(self):
result = markdown_to_html("||secret||")
assert "<tg-spoiler>secret</tg-spoiler>" in result
def test_plain_text_passthrough(self):
result = markdown_to_html("hello world")
assert "hello world" in result
def test_escape_special_chars(self):
result = markdown_to_html("price &amp; 5")
assert "&amp;" in result
def test_sanitize_html_input(self):
result = markdown_to_html("<b>clean</b>")
assert "clean" in result
def test_strip_all_tags(self):
result = strip_all_tags("<b>hello</b> <i>world</i>")
assert result == "hello world"
def test_strip_all_tags_no_tags(self):
result = strip_all_tags("plain text")
assert result == "plain text"