Files
douyi_guaji_main/tests/unit/test_douyin_text_utils.py
T
Your Name f92933641f feat: Enhance documentation and clean up code structure
- Added comprehensive documentation for the unified screenshot and score recording process in the new markdown file.
- Improved existing markdown files by adding spacing for better readability.
- Cleaned up code by removing unnecessary blank lines across various scripts, enhancing overall code clarity.
- Updated configuration settings to reflect recent changes and ensure consistency across the project.
- Enhanced logging mechanisms to support better debugging and monitoring.
2025-12-25 16:11:25 +08:00

125 lines
2.9 KiB
Python

"""
douyin_text_utils模块测试
"""
import pytest # type: ignore
from douyin_text_utils import (
extract_fudai_content,
extract_fudai_countdown,
extract_fudai_value,
extract_participants_count,
)
class TestExtractFudaiContent:
"""福袋内容提取测试"""
def test_extract_simple_content(self):
"""测试提取简单内容"""
text = "福袋内容:100元现金"
result = extract_fudai_content(text)
assert "100元" in result or "现金" in result
def test_extract_empty_text(self):
"""测试空文本"""
assert extract_fudai_content("") == ""
assert extract_fudai_content(None) == ""
def test_extract_no_content(self):
"""测试没有内容的情况"""
text = "没有相关内容"
result = extract_fudai_content(text)
assert result == "" or result == text
class TestExtractFudaiCountdown:
"""福袋倒计时提取测试"""
def test_extract_minutes_seconds(self):
"""测试提取分钟+秒格式"""
text = "倒计时:5分30秒"
result = extract_fudai_countdown(text)
assert result is not None
assert "5" in result or "30" in result
def test_extract_only_seconds(self):
"""测试提取只有秒的格式"""
text = "倒计时:30秒"
result = extract_fudai_countdown(text)
assert result is not None
def test_extract_empty_text(self):
"""测试空文本"""
assert extract_fudai_countdown("") == ""
assert extract_fudai_countdown(None) == ""
class TestExtractFudaiValue:
"""福袋价值提取测试"""
def test_extract_yuan_value(self):
"""测试提取元为单位的值"""
text = "价值:100元"
result = extract_fudai_value(text)
assert result is not None
assert result >= 0
def test_extract_no_value(self):
"""测试没有价值信息"""
text = "没有价值信息"
result = extract_fudai_value(text)
assert result == 0.0 or result is None
def test_extract_empty_text(self):
"""测试空文本"""
assert extract_fudai_value("") == 0.0
assert extract_fudai_value(None) == 0.0
class TestExtractParticipantsCount:
"""参与人数提取测试"""
def test_extract_participants(self):
"""测试提取参与人数"""
text = "已有1000人参与"
result = extract_participants_count(text)
assert result is not None
assert result >= 0
def test_extract_no_participants(self):
"""测试没有参与人数信息"""
text = "没有参与人数"
result = extract_participants_count(text)
assert result == 0 or result is None
def test_extract_empty_text(self):
"""测试空文本"""
assert extract_participants_count("") == 0
assert extract_participants_count(None) == 0