Files
douyin_guaji-main/tests/unit/test_douyin_text_utils.py
T
Your Name e68f1dd3de feat: Refactor coverage management and enhance logging functionality
- Removed the `.coverage` file from the repository to streamline coverage management.
- Updated `.gitignore` to exclude coverage-related files and directories, ensuring a cleaner project structure.
- Introduced new scripts for checking GPU availability and detecting GUI parameter conflicts, enhancing the overall functionality of the application.
- Improved logging mechanisms across various modules to support better debugging and monitoring.
- Added comprehensive documentation for new features and updated existing markdown files for clarity.
2025-12-23 02:38:51 +08:00

116 lines
2.9 KiB
Python

"""
douyin_text_utils模块测试
"""
import pytest
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