169 lines
5.8 KiB
Python
169 lines
5.8 KiB
Python
"""douyin/fudai 模块单元测试。
|
|
|
|
覆盖:
|
|
- fudai_detail_utils: is_abnormal_time_value 纯函数
|
|
- fudai_detail_validator: validate_fudai_detail 函数签名
|
|
- fudai shim 与子模块导出一致性
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
|
|
class TestIsAbnormalTimeValue:
|
|
"""is_abnormal_time_value 纯函数测试。"""
|
|
|
|
def test_zero_is_abnormal(self):
|
|
from douyin.fudai.core.fudai_detail_utils import is_abnormal_time_value
|
|
|
|
assert is_abnormal_time_value(0) is True
|
|
|
|
def test_negative_is_abnormal(self):
|
|
from douyin.fudai.core.fudai_detail_utils import is_abnormal_time_value
|
|
|
|
assert is_abnormal_time_value(-1) is True
|
|
assert is_abnormal_time_value(-100) is True
|
|
|
|
def test_very_large_is_abnormal(self):
|
|
from douyin.fudai.core.fudai_detail_utils import is_abnormal_time_value
|
|
|
|
# 超过 7 天的秒数
|
|
assert is_abnormal_time_value(24 * 3600 * 7 + 1) is True
|
|
assert is_abnormal_time_value(1000000) is True
|
|
|
|
def test_normal_values(self):
|
|
from douyin.fudai.core.fudai_detail_utils import is_abnormal_time_value
|
|
|
|
assert is_abnormal_time_value(1) is False
|
|
assert is_abnormal_time_value(60) is False
|
|
assert is_abnormal_time_value(3600) is False
|
|
assert is_abnormal_time_value(86400) is False # 1 天
|
|
|
|
def test_boundary_values(self):
|
|
from douyin.fudai.core.fudai_detail_utils import is_abnormal_time_value
|
|
|
|
# 刚好 7 天
|
|
assert is_abnormal_time_value(24 * 3600 * 7) is False
|
|
# 刚好超过 7 天
|
|
assert is_abnormal_time_value(24 * 3600 * 7 + 0.001) is True
|
|
|
|
|
|
class TestValidateFudaiDetail:
|
|
"""validate_fudai_detail 函数测试。"""
|
|
|
|
def test_function_exists(self):
|
|
from douyin.fudai.core.fudai_detail_validator import validate_fudai_detail
|
|
|
|
assert callable(validate_fudai_detail)
|
|
|
|
def test_invalid_tuple_returns_false(self):
|
|
from douyin.fudai.core.fudai_detail_validator import validate_fudai_detail
|
|
|
|
is_valid, reason = validate_fudai_detail(None)
|
|
assert is_valid is False
|
|
assert "invalid" in reason.lower()
|
|
|
|
def test_short_tuple_returns_false(self):
|
|
from douyin.fudai.core.fudai_detail_validator import validate_fudai_detail
|
|
|
|
is_valid, reason = validate_fudai_detail((1, 2, 3))
|
|
assert is_valid is False
|
|
|
|
def test_valid_tuple_structure(self):
|
|
from douyin.fudai.core.fudai_detail_validator import validate_fudai_detail
|
|
|
|
# 构造一个有效的 detail tuple
|
|
detail = ("福袋内容", "5:00", 100, 10, 50.0, (300, 1700000000))
|
|
is_valid, reason = validate_fudai_detail(detail)
|
|
# 可能因为其他验证规则返回 False,但至少不会因为结构问题
|
|
assert isinstance(is_valid, bool)
|
|
assert isinstance(reason, str)
|
|
|
|
def test_value_raw_accepts_zero_yuan_marketing_prefix(self):
|
|
from types import SimpleNamespace
|
|
from douyin.fudai.core.fudai_detail_validator import validate_fudai_detail
|
|
|
|
analyser = SimpleNamespace(
|
|
value_raw="0元带走¥999参考价值",
|
|
countdown_mm_raw="07",
|
|
countdown_ss_raw="59",
|
|
)
|
|
detail = ("福袋内容", "07:59", 0, 0, 999.0, (1000.0, 1479.0))
|
|
|
|
is_valid, reason = validate_fudai_detail(detail, analyser)
|
|
|
|
assert is_valid is True, reason
|
|
|
|
|
|
class TestFudaiDetailShimConsistency:
|
|
"""验证 fudai_detail shim 与子模块导出一致。"""
|
|
|
|
def test_close_fudai_detail_same_object(self):
|
|
from douyin.fudai.douyin_fudai_detail import close_fudai_detail as f1
|
|
from douyin.fudai.core.fudai_detail_operations import close_fudai_detail as f2
|
|
|
|
assert f1 is f2
|
|
|
|
def test_ensure_fudai_detail_open_same_object(self):
|
|
from douyin.fudai.douyin_fudai_detail import ensure_fudai_detail_open as f1
|
|
from douyin.fudai.core.fudai_detail_operations import ensure_fudai_detail_open as f2
|
|
|
|
assert f1 is f2
|
|
|
|
def test_read_live_room_title_core_same_object(self):
|
|
from douyin.fudai.douyin_fudai_detail import read_live_room_title_core as f1
|
|
from douyin.fudai.core.fudai_detail_room_title import read_live_room_title_core as f2
|
|
|
|
assert f1 is f2
|
|
|
|
def test_is_abnormal_time_value_same_object(self):
|
|
from douyin.fudai.douyin_fudai_detail import is_abnormal_time_value as f1
|
|
from douyin.fudai.core.fudai_detail_utils import is_abnormal_time_value as f2
|
|
|
|
assert f1 is f2
|
|
|
|
def test_validate_fudai_detail_same_object(self):
|
|
from douyin.fudai.douyin_fudai_detail import validate_fudai_detail as f1
|
|
from douyin.fudai.core.fudai_detail_validator import validate_fudai_detail as f2
|
|
|
|
assert f1 is f2
|
|
|
|
|
|
class TestFudaiFlowModule:
|
|
"""fudai_flow 模块测试。"""
|
|
|
|
def test_module_importable(self):
|
|
from douyin.fudai import douyin_fudai_flow
|
|
|
|
assert douyin_fudai_flow is not None
|
|
|
|
|
|
class TestFudaiCoreModules:
|
|
"""fudai/core 子模块存在性测试。"""
|
|
|
|
def test_fudai_detail_operations_importable(self):
|
|
from douyin.fudai.core import fudai_detail_operations
|
|
|
|
assert fudai_detail_operations is not None
|
|
|
|
def test_fudai_detail_room_title_importable(self):
|
|
from douyin.fudai.core import fudai_detail_room_title
|
|
|
|
assert fudai_detail_room_title is not None
|
|
|
|
def test_fudai_detail_orchestrator_importable(self):
|
|
from douyin.fudai.core import fudai_detail_orchestrator
|
|
|
|
assert fudai_detail_orchestrator is not None
|
|
|
|
def test_fudai_result_checker_importable(self):
|
|
from douyin.fudai.core import fudai_result_checker
|
|
|
|
assert fudai_result_checker is not None
|
|
|
|
def test_fudai_detail_coupon_detection_importable(self):
|
|
from douyin.fudai.core import fudai_detail_coupon_detection
|
|
|
|
assert fudai_detail_coupon_detection is not None
|