- 删除 douyin/utils/douyin_text_utils.py 及其测试 - 移除 performance_tracker.py 中未使用的 track_function 方法 - 移除 param_usage_tracer.py 中未使用的 stop_tracing / is_enabled - 清理 bin/run_cli.py 和 tests/test_imports.py 中的残留引用 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
162 lines
5.5 KiB
Python
162 lines
5.5 KiB
Python
"""核心模块导入冒烟测试。
|
||
|
||
验证 douyin/* 全树关键模块都能正常 import;任何 import-time 错误(语法 / 循环
|
||
依赖 / 顶层初始化失败)都会在这里被捕获,避免运行时才发现。
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import importlib
|
||
|
||
import pytest
|
||
|
||
|
||
# 项目核心包:这些模块顶层 import 不应失败
|
||
CORE_MODULES = [
|
||
# 入口与基础
|
||
"douyin.core.path_config",
|
||
"douyin.core.version",
|
||
"douyin.core.io_utils",
|
||
"douyin.core.underlying_operations",
|
||
"douyin.core.douyin_fudai",
|
||
"douyin.core.douyin_main_flow",
|
||
"douyin.core.douyin_flow_control",
|
||
# fudai_modules(Mixin)
|
||
"douyin.core.fudai_modules.base_interface",
|
||
"douyin.core.fudai_modules.fudai_navigation",
|
||
"douyin.core.fudai_modules.fudai_stage_detection",
|
||
"douyin.core.fudai_modules.fudai_popup_handler",
|
||
"douyin.core.fudai_modules.fudai_lottery_result",
|
||
"douyin.core.fudai_modules.fudai_room_utils",
|
||
"douyin.core.fudai_modules.fudai_main_logic",
|
||
# 检测 / 阶段
|
||
"douyin.detection.douyin_detection",
|
||
"douyin.detection.douyin_pixel",
|
||
"douyin.stage.douyin_stage",
|
||
"douyin.stage.douyin_stage_handler",
|
||
# 福袋核心
|
||
"douyin.fudai.douyin_fudai_core",
|
||
"douyin.fudai.douyin_fudai_finder",
|
||
"douyin.fudai.douyin_fudai_detail",
|
||
"douyin.fudai.douyin_fudai_flow",
|
||
"douyin.fudai.core.coords",
|
||
"douyin.fudai.core.fudai_filter",
|
||
"douyin.fudai.core.fudai_attend",
|
||
"douyin.fudai.core.fudai_debug_utils",
|
||
"douyin.fudai.core.fudai_result_checker",
|
||
# 处理器
|
||
"douyin.handlers.douyin_screenshot_handler",
|
||
"douyin.handlers.douyin_screenshot_manager",
|
||
"douyin.handlers.douyin_swipe_handler",
|
||
"douyin.handlers.douyin_swipe_ops",
|
||
"douyin.handlers.douyin_popup_handler",
|
||
# 预约
|
||
"douyin.reservation.douyin_reservation",
|
||
"douyin.reservation.douyin_reservation_handler",
|
||
"douyin.reservation.douyin_reservation_logic",
|
||
"douyin.reservation.douyin_reservation_verify",
|
||
"douyin.reservation.core", # 子包
|
||
# 日志
|
||
"douyin.logging.douyin_logging",
|
||
"douyin.logging.douyin_logging_wrapper",
|
||
"douyin.logging.unified_logger",
|
||
"douyin.logging.action_logger",
|
||
"douyin.logging.internal_loggers",
|
||
"douyin.logging.log_formatter",
|
||
"douyin.logging.performance_tracker",
|
||
# 其他业务
|
||
"douyin.other.douyin_yanghao",
|
||
"douyin.other.douyin_robot",
|
||
"douyin.other.douyin_popups",
|
||
"douyin.other.douyin_high_value_room",
|
||
"douyin.other.douyin_live_room",
|
||
"douyin.other.douyin_lottery",
|
||
# 工具
|
||
"douyin.utils.douyin_config",
|
||
"douyin.utils.douyin_helpers",
|
||
"douyin.utils.douyin_utils",
|
||
"douyin.utils.ocr_preprocess",
|
||
"douyin.utils.time_utils",
|
||
"douyin.utils.param_usage_tracer",
|
||
"douyin.utils.param_usage_tracker",
|
||
# operations 兼容包
|
||
"operations",
|
||
"operations.ocr_operations",
|
||
"operations.screenshot_operations",
|
||
"operations.screenshot_service",
|
||
# GUI(不实例化,仅 import)
|
||
"gui.gui_core",
|
||
"gui.gui_app",
|
||
"gui.web_gui",
|
||
"gui.webgui_launcher",
|
||
"gui.components.actions_log_viewer",
|
||
"gui.components.device_selector",
|
||
"gui.components.error_log_viewer",
|
||
"gui.components.log_color_config",
|
||
"gui.components.log_viewer",
|
||
"gui.components.mapping_table",
|
||
"gui.components.mapping_utils",
|
||
]
|
||
|
||
|
||
@pytest.mark.parametrize("module_name", CORE_MODULES)
|
||
def test_module_importable(module_name):
|
||
"""每个核心模块都应可以 import 而不抛异常。"""
|
||
importlib.import_module(module_name)
|
||
|
||
|
||
# ============================================================
|
||
# 关键类/函数应正确导出
|
||
# ============================================================
|
||
|
||
class TestKeyExports:
|
||
def test_fudai_analyse_class(self):
|
||
from douyin.core.douyin_fudai import fudai_analyse
|
||
|
||
assert fudai_analyse.__name__ == "fudai_analyse"
|
||
# 必有的关键方法
|
||
for method in ("fudai_choujiang", "run_once_basic", "load_config"):
|
||
assert hasattr(fudai_analyse, method), f"fudai_analyse 缺少 {method}"
|
||
|
||
def test_underlying_operations_class(self):
|
||
from douyin.core.underlying_operations import underlying_operations
|
||
|
||
assert underlying_operations.__name__ == "underlying_operations"
|
||
# 必有的关键方法
|
||
for method in ("get_screenshot", "click", "swipe", "analyse_pic_word"):
|
||
assert hasattr(underlying_operations, method), (
|
||
f"underlying_operations 缺少 {method}"
|
||
)
|
||
|
||
def test_path_config_functions(self):
|
||
from douyin.core import path_config
|
||
|
||
# 关键函数
|
||
for fn_name in (
|
||
"get_project_root",
|
||
"get_config_path",
|
||
"get_logs_dir",
|
||
"get_state_dir",
|
||
"get_reservations_path",
|
||
):
|
||
assert callable(getattr(path_config, fn_name, None)), (
|
||
f"path_config 缺少 {fn_name}"
|
||
)
|
||
|
||
def test_unified_logger_mdc(self):
|
||
from douyin.logging.unified_logger import MDC
|
||
|
||
for method in ("put", "get", "get_all", "remove", "clear"):
|
||
assert callable(getattr(MDC, method, None)), f"MDC 缺少 {method}"
|
||
|
||
def test_operations_package_exports(self):
|
||
import operations
|
||
|
||
# operations 包对外暴露的符号
|
||
for name in (
|
||
"underlying_operations",
|
||
"analyse_pic_word",
|
||
"get_screenshot",
|
||
"_safe_replace_file",
|
||
):
|
||
assert hasattr(operations, name), f"operations 包缺少导出 {name}"
|