- Introduced a new `.coverage` file for tracking test coverage metrics. - Added `pytest.ini` configuration for streamlined testing setup, including coverage reporting and logging options. - Created `requirements-test.txt` to manage testing dependencies, ensuring a consistent testing environment. - Implemented a `run_tests.py` script to facilitate running tests with various options, including unit and integration tests. - Established a structured testing directory with unit and integration tests, enhancing code reliability and maintainability. - Updated documentation to reflect new testing procedures and configurations.
100 lines
2.9 KiB
Python
100 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
|
|
|