ForcePilot/backend/test/unit/channels/test_twitch_markdown.py
Kris 3264900bc9 test: 新增多渠道单元测试用例并配置测试环境变量
新增了Twitch、Telegram、Discord、Slack、Mattermost、WeChat、Zalo等多渠道的单元测试用例,覆盖了令牌处理、速率限制、消息去重、会话解析、格式转换、安全策略等模块
同时在测试配置中添加了测试用的OpenAI API密钥环境变量
2026-05-12 00:56:47 +08:00

79 lines
3.0 KiB
Python

from __future__ import annotations
from yuxi.channels.adapters.twitch.markdown_utils import strip_twitch_markdown
class TestStripTwitchMarkdown:
def test_plain_text_passthrough(self):
assert strip_twitch_markdown("Hello world") == "Hello world"
def test_empty_string(self):
assert strip_twitch_markdown("") == ""
def test_remove_images(self):
assert strip_twitch_markdown("See ![alt](https://img.png) here") == "See here"
def test_strip_links_keep_text(self):
result = strip_twitch_markdown("Click [here](https://example.com) now")
assert result == "Click here now"
def test_remove_bold_markers(self):
assert strip_twitch_markdown("**bold text** here") == "bold text here"
def test_remove_bold_underscore(self):
assert strip_twitch_markdown("__bold__ here") == "bold here"
def test_remove_italic_markers(self):
assert strip_twitch_markdown("*italic text* here") == "italic text here"
def test_remove_italic_underscore(self):
assert strip_twitch_markdown("_italic_ here") == "italic here"
def test_remove_strikethrough(self):
assert strip_twitch_markdown("~~strikethrough~~ here") == "strikethrough here"
def test_remove_fenced_code_block(self):
result = strip_twitch_markdown("```python\nprint('hello')\n```")
assert result == "print('hello')"
def test_remove_inline_code(self):
assert strip_twitch_markdown("Use `code()` here") == "Use code() here"
def test_remove_heading_markers(self):
assert strip_twitch_markdown("# Heading 1") == "Heading 1"
assert strip_twitch_markdown("## Heading 2") == "Heading 2"
assert strip_twitch_markdown("### Heading 3") == "Heading 3"
def test_remove_unordered_list_markers(self):
assert strip_twitch_markdown("- item 1") == "item 1"
assert strip_twitch_markdown("* item 2") == "item 2"
def test_remove_ordered_list_markers(self):
assert strip_twitch_markdown("1. first") == "first"
assert strip_twitch_markdown("10. tenth") == "tenth"
def test_remove_blockquote(self):
assert strip_twitch_markdown("> quoted text") == "quoted text"
def test_remove_horizontal_rules(self):
assert strip_twitch_markdown("before\n---\nafter") == "before\n\nafter"
assert strip_twitch_markdown("before\n***\nafter") == "before\n\nafter"
def test_compress_multiple_spaces(self):
assert strip_twitch_markdown("a b c") == "a b c"
def test_compress_multiple_newlines(self):
result = strip_twitch_markdown("line1\n\n\n\nline2")
assert result == "line1\n\nline2"
def test_complex_markdown(self):
text = "**Bold** and *italic* with [a link](http://x.com) and `code`"
result = strip_twitch_markdown(text)
assert result == "Bold and italic with a link and code"
def test_nested_formatting(self):
text = "**bold *and italic* together**"
result = strip_twitch_markdown(text)
assert "**" not in result
assert "*" not in result