新增 tests/ 下 10 个测试文件,把已拆出的子包从"被外部测试间接覆盖"提升到 "独立可测": - test_web_gui_pkg (52) 覆盖 logger / ansi / adb_compat / nested / stats_helpers 含 _wg_log/_LOGGER 日志、ANSI 清理、点号路径、_parse_countdown_seconds 等 - test_underlying_operations_pkg (35) 覆盖 adb_helpers / bounds / countdown / ocr_content / pic_path 含 _adb_path 环境变量覆盖、check_countdown 多种格式、OCR 字符纠错 - test_reservation_logic_helpers (21) 覆盖 helpers.py 5 个纯函数(_now_ts / _normalize_room_title / _calculate_string_similarity / _extract_content_core / _sort_reservations_inplace 排序稳定性) - test_screenshot_manager_pkg (47) 覆盖 paths.get_category_for_picname(5 类关键词分类)+ get_latest_attempt_path / get_last_success_path(按 operation_type 路径推断) + 异步计数器 - test_gui_core_pkg (13) 覆盖 RunParams dataclass 28 字段构造 + adb 函数 + read_config / write_config roundtrip - test_fudai_core_pkg (17) 覆盖 _FudaiOcrExecutorState 单例 + _get_fudai_ocr_executor 缓存复用 + 11 个 thin_wrappers 与原实现等价行为 - test_handler_shells (8) 覆盖 ReservationHandler / StageHandler / LoggingWrapper 三个薄壳类的 staticmethod forwarding 完整性 - test_yanghao_pkg (14) 覆盖 _yanghao_log(_log_kv 优先 + logger fallback + broken analyser 兜底 + 未知 level 不抛)+ yanghao_get_recommend_seconds 默认值 - test_pixel_common (6) 覆盖 _safe_open_screenshot_rgb 用 tmp_path 构造合法/损坏/截断/RGBA PNG - test_fudai_finder_pkg (13) 覆盖 5 个类(FudaiImageAcquirer / FudaiDetector / FudaiClickExecutor / FudaiDetailVerifier / FudaiFinder)实例化与组合关系,verify detect_by_template 类方法签名仍兼容(拆出后) 回归: - 全套测试 355 → 581(+226 用例) - 全部 581 passed / 1 skipped in 27s - 新拆出的 12 个子包现在都有专门的单元测试覆盖 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
126 lines
4.4 KiB
Python
126 lines
4.4 KiB
Python
"""薄壳类 forwarding 单元测试。
|
|
|
|
覆盖三个"类内部 staticmethod 全部 forwarding 到 module-level"的薄壳:
|
|
- douyin_reservation_handler_pkg.handler.ReservationHandler
|
|
- douyin_stage_handler_pkg.handler.StageHandler
|
|
- douyin_logging_wrapper_pkg.wrapper.LoggingWrapper
|
|
|
|
只验证:类与 module-level 函数返回同一对象 / 调用不抛 / 转发正确。
|
|
不测业务逻辑(业务行为由各子模块的功能测试覆盖)。
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Dict
|
|
|
|
import pytest
|
|
|
|
|
|
# ============================================================
|
|
# ReservationHandler
|
|
# ============================================================
|
|
|
|
class TestReservationHandlerForwarding:
|
|
def test_class_methods_callable(self):
|
|
from douyin.reservation.douyin_reservation_handler import ReservationHandler
|
|
|
|
for method in [
|
|
"find_room_pos_by_title",
|
|
"record_room_title_and_pos",
|
|
"seek_reservation_room",
|
|
"handle_reservation_direct_attend",
|
|
]:
|
|
fn = getattr(ReservationHandler, method, None)
|
|
assert callable(fn), f"ReservationHandler.{method} 不可调用"
|
|
|
|
def test_find_room_pos_by_title_empty_returns_none(self):
|
|
from douyin.reservation.douyin_reservation_handler import ReservationHandler
|
|
|
|
class M:
|
|
_room_pos_to_title_map: Dict[int, Any] = {}
|
|
|
|
# 空映射应返回 None
|
|
assert ReservationHandler.find_room_pos_by_title(M(), "", "") is None
|
|
|
|
def test_module_level_and_class_same_function(self):
|
|
"""类的 staticmethod 和 module-level 函数应返回相同行为。"""
|
|
from douyin.reservation.douyin_reservation_handler import (
|
|
ReservationHandler, find_room_pos_by_title,
|
|
)
|
|
|
|
class M:
|
|
_room_pos_to_title_map: Dict[int, Any] = {}
|
|
|
|
assert (
|
|
ReservationHandler.find_room_pos_by_title(M(), "x", "")
|
|
== find_room_pos_by_title(M(), "x", "")
|
|
)
|
|
|
|
|
|
# ============================================================
|
|
# StageHandler
|
|
# ============================================================
|
|
|
|
class TestStageHandlerForwarding:
|
|
def test_class_methods_callable(self):
|
|
from douyin.stage.douyin_stage_handler import StageHandler
|
|
|
|
for method in [
|
|
"diagnose_stage_from_current_screen",
|
|
"check_in_live_room_by_icon",
|
|
"handle_in_fudai_detail",
|
|
"handle_live_room_has_or_not_fudai",
|
|
]:
|
|
fn = getattr(StageHandler, method, None)
|
|
assert callable(fn), f"StageHandler.{method} 不可调用"
|
|
|
|
def test_module_level_exposed(self):
|
|
from douyin.stage.douyin_stage_handler import (
|
|
StageHandler,
|
|
diagnose_stage_from_current_screen,
|
|
check_in_live_room_by_icon,
|
|
handle_in_fudai_detail,
|
|
handle_live_room_has_or_not_fudai,
|
|
)
|
|
# 都可访问
|
|
assert all(callable(f) for f in [
|
|
diagnose_stage_from_current_screen,
|
|
check_in_live_room_by_icon,
|
|
handle_in_fudai_detail,
|
|
handle_live_room_has_or_not_fudai,
|
|
])
|
|
|
|
|
|
# ============================================================
|
|
# LoggingWrapper
|
|
# ============================================================
|
|
|
|
class TestLoggingWrapperForwarding:
|
|
def test_class_methods_callable(self):
|
|
from douyin.logging.douyin_logging_wrapper import LoggingWrapper
|
|
|
|
for method in [
|
|
"enhanced_log_kv",
|
|
"_enhanced_log_kv_simple",
|
|
"_enhanced_log_kv_detailed",
|
|
"log_step_time",
|
|
"log_error_with_context",
|
|
"log_performance_step",
|
|
"log_debug_info",
|
|
"get_performance_stats",
|
|
]:
|
|
fn = getattr(LoggingWrapper, method, None)
|
|
assert callable(fn), f"LoggingWrapper.{method} 不可调用"
|
|
|
|
def test_get_performance_stats_returns_dict(self):
|
|
"""无副作用的方法可直接调用。"""
|
|
from douyin.logging.douyin_logging_wrapper import LoggingWrapper
|
|
|
|
result = LoggingWrapper.get_performance_stats()
|
|
assert isinstance(result, dict)
|
|
|
|
def test_module_level_get_performance_stats(self):
|
|
from douyin.logging.douyin_logging_wrapper import (
|
|
LoggingWrapper, get_performance_stats,
|
|
)
|
|
assert LoggingWrapper.get_performance_stats() == get_performance_stats()
|