- 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.
96 lines
2.6 KiB
Python
96 lines
2.6 KiB
Python
"""
|
|
douyin_utils模块测试
|
|
"""
|
|
|
|
import pytest # type: ignore
|
|
from douyin_utils import normalize_countdown_text, parse_countdown_seconds
|
|
|
|
|
|
class TestNormalizeCountdownText:
|
|
"""倒计时文本标准化测试"""
|
|
|
|
def test_normalize_minutes_seconds(self):
|
|
"""测试分钟+秒格式"""
|
|
assert normalize_countdown_text("5分30秒") == "5:30"
|
|
assert normalize_countdown_text("10分5秒") == "10:05"
|
|
assert normalize_countdown_text("0分45秒") == "0:45"
|
|
|
|
def test_normalize_only_seconds(self):
|
|
"""测试只有秒的格式"""
|
|
assert normalize_countdown_text("30秒") == "0:30"
|
|
assert normalize_countdown_text("5秒") == "0:05"
|
|
|
|
def test_normalize_only_minutes(self):
|
|
"""测试只有分钟的格式"""
|
|
assert normalize_countdown_text("5分钟") == "5:00"
|
|
assert normalize_countdown_text("10分钟") == "10:00"
|
|
|
|
def test_normalize_colon_format(self):
|
|
"""测试已经是冒号格式的文本"""
|
|
assert normalize_countdown_text("5:30") == "5:30"
|
|
assert normalize_countdown_text("10:05") == "10:05"
|
|
|
|
def test_normalize_empty_string(self):
|
|
"""测试空字符串"""
|
|
assert normalize_countdown_text("") == ""
|
|
|
|
def test_normalize_invalid_format(self):
|
|
"""测试无效格式(应该返回原文本)"""
|
|
assert normalize_countdown_text("无效文本") == "无效文本"
|
|
assert normalize_countdown_text("abc") == "abc"
|
|
|
|
|
|
class TestParseCountdownSeconds:
|
|
"""倒计时秒数解析测试"""
|
|
|
|
def test_parse_minutes_seconds(self):
|
|
"""测试解析分钟+秒格式"""
|
|
assert parse_countdown_seconds("5:30") == 330
|
|
assert parse_countdown_seconds("10:05") == 605
|
|
assert parse_countdown_seconds("0:45") == 45
|
|
|
|
def test_parse_only_seconds(self):
|
|
"""测试解析只有秒的格式"""
|
|
assert parse_countdown_seconds("0:30") == 30
|
|
assert parse_countdown_seconds("0:05") == 5
|
|
|
|
def test_parse_only_minutes(self):
|
|
"""测试解析只有分钟的格式"""
|
|
assert parse_countdown_seconds("5:00") == 300
|
|
assert parse_countdown_seconds("10:00") == 600
|
|
|
|
def test_parse_invalid_format(self):
|
|
"""测试无效格式(应该返回0或抛出异常)"""
|
|
# 根据实际实现调整
|
|
try:
|
|
result = parse_countdown_seconds("无效")
|
|
assert result == 0 or result is None
|
|
except (ValueError, AttributeError):
|
|
pass # 如果抛出异常也是可以接受的
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|