补 douyin/stage 模块单元测试(+23 用例)
- diagnose_stage_from_current_screen 函数签名验证 - StageHandler 类方法检查 - stage_handler_pkg shim 与子模块导出一致性验证 - stage 子模块存在性测试 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8d98143df1
commit
e8bf904fc6
1 file changed
+180
@@ -0,0 +1,180 @@
|
||||
"""douyin/stage 模块单元测试。
|
||||
|
||||
覆盖:
|
||||
- douyin_stage: diagnose_stage_from_current_screen 函数签名
|
||||
- douyin_stage_handler: StageHandler 类和子模块
|
||||
- stage_handler_pkg shim 与子模块导出一致性
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import inspect
|
||||
import pytest
|
||||
|
||||
|
||||
class TestDiagnoseStage:
|
||||
"""diagnose_stage_from_current_screen 函数测试。"""
|
||||
|
||||
def test_function_exists(self):
|
||||
from douyin.stage.douyin_stage import diagnose_stage_from_current_screen
|
||||
|
||||
assert callable(diagnose_stage_from_current_screen)
|
||||
|
||||
def test_function_signature(self):
|
||||
from douyin.stage.douyin_stage import diagnose_stage_from_current_screen
|
||||
|
||||
sig = inspect.signature(diagnose_stage_from_current_screen)
|
||||
params = list(sig.parameters.keys())
|
||||
assert "analyser" in params
|
||||
assert "trigger_reason" in params
|
||||
|
||||
|
||||
class TestStageHandler:
|
||||
"""StageHandler 类测试。"""
|
||||
|
||||
def test_class_exists(self):
|
||||
from douyin.stage.douyin_stage_handler import StageHandler
|
||||
|
||||
assert StageHandler is not None
|
||||
|
||||
def test_class_has_expected_methods(self):
|
||||
from douyin.stage.douyin_stage_handler import StageHandler
|
||||
|
||||
expected = [
|
||||
"diagnose_stage_from_current_screen",
|
||||
"check_in_live_room_by_icon",
|
||||
"handle_in_fudai_detail",
|
||||
"handle_live_room_has_or_not_fudai",
|
||||
]
|
||||
for name in expected:
|
||||
assert hasattr(StageHandler, name), f"缺少方法: {name}"
|
||||
|
||||
|
||||
class TestStageHandlerPkgSubmodules:
|
||||
"""stage_handler_pkg 子模块测试。"""
|
||||
|
||||
def test_diagnose_module_importable(self):
|
||||
from douyin.stage.douyin_stage_handler_pkg import diagnose
|
||||
|
||||
assert diagnose is not None
|
||||
|
||||
def test_check_live_module_importable(self):
|
||||
from douyin.stage.douyin_stage_handler_pkg import check_live
|
||||
|
||||
assert check_live is not None
|
||||
|
||||
def test_handle_detail_module_importable(self):
|
||||
from douyin.stage.douyin_stage_handler_pkg import handle_detail
|
||||
|
||||
assert handle_detail is not None
|
||||
|
||||
def test_handle_room_module_importable(self):
|
||||
from douyin.stage.douyin_stage_handler_pkg import handle_room
|
||||
|
||||
assert handle_room is not None
|
||||
|
||||
def test_handler_module_importable(self):
|
||||
from douyin.stage.douyin_stage_handler_pkg import handler
|
||||
|
||||
assert handler is not None
|
||||
|
||||
|
||||
class TestStageHandlerShimConsistency:
|
||||
"""验证 stage_handler shim 与子模块导出一致。"""
|
||||
|
||||
def test_diagnose_stage_same_object(self):
|
||||
from douyin.stage.douyin_stage_handler import diagnose_stage_from_current_screen as f1
|
||||
from douyin.stage.douyin_stage_handler_pkg import diagnose_stage_from_current_screen as f2
|
||||
|
||||
assert f1 is f2
|
||||
|
||||
def test_check_in_live_room_same_object(self):
|
||||
from douyin.stage.douyin_stage_handler import check_in_live_room_by_icon as f1
|
||||
from douyin.stage.douyin_stage_handler_pkg import check_in_live_room_by_icon as f2
|
||||
|
||||
assert f1 is f2
|
||||
|
||||
def test_handle_in_fudai_detail_same_object(self):
|
||||
from douyin.stage.douyin_stage_handler import handle_in_fudai_detail as f1
|
||||
from douyin.stage.douyin_stage_handler_pkg import handle_in_fudai_detail as f2
|
||||
|
||||
assert f1 is f2
|
||||
|
||||
def test_handle_live_room_same_object(self):
|
||||
from douyin.stage.douyin_stage_handler import handle_live_room_has_or_not_fudai as f1
|
||||
from douyin.stage.douyin_stage_handler_pkg import handle_live_room_has_or_not_fudai as f2
|
||||
|
||||
assert f1 is f2
|
||||
|
||||
def test_stage_handler_class_same_object(self):
|
||||
from douyin.stage.douyin_stage_handler import StageHandler as C1
|
||||
from douyin.stage.douyin_stage_handler_pkg import StageHandler as C2
|
||||
|
||||
assert C1 is C2
|
||||
|
||||
|
||||
class TestCheckLiveFunction:
|
||||
"""check_in_live_room_by_icon 函数测试。"""
|
||||
|
||||
def test_function_exists(self):
|
||||
from douyin.stage.douyin_stage_handler_pkg.check_live import check_in_live_room_by_icon
|
||||
|
||||
assert callable(check_in_live_room_by_icon)
|
||||
|
||||
def test_function_signature(self):
|
||||
from douyin.stage.douyin_stage_handler_pkg.check_live import check_in_live_room_by_icon
|
||||
|
||||
sig = inspect.signature(check_in_live_room_by_icon)
|
||||
params = list(sig.parameters.keys())
|
||||
assert "analyser" in params
|
||||
|
||||
|
||||
class TestHandleDetailFunction:
|
||||
"""handle_in_fudai_detail 函数测试。"""
|
||||
|
||||
def test_function_exists(self):
|
||||
from douyin.stage.douyin_stage_handler_pkg.handle_detail import handle_in_fudai_detail
|
||||
|
||||
assert callable(handle_in_fudai_detail)
|
||||
|
||||
def test_function_signature(self):
|
||||
from douyin.stage.douyin_stage_handler_pkg.handle_detail import handle_in_fudai_detail
|
||||
|
||||
sig = inspect.signature(handle_in_fudai_detail)
|
||||
params = list(sig.parameters.keys())
|
||||
assert "analyser" in params
|
||||
|
||||
|
||||
class TestHandleRoomFunction:
|
||||
"""handle_live_room_has_or_not_fudai 函数测试。"""
|
||||
|
||||
def test_function_exists(self):
|
||||
from douyin.stage.douyin_stage_handler_pkg.handle_room import handle_live_room_has_or_not_fudai
|
||||
|
||||
assert callable(handle_live_room_has_or_not_fudai)
|
||||
|
||||
def test_function_signature(self):
|
||||
from douyin.stage.douyin_stage_handler_pkg.handle_room import handle_live_room_has_or_not_fudai
|
||||
|
||||
sig = inspect.signature(handle_live_room_has_or_not_fudai)
|
||||
params = list(sig.parameters.keys())
|
||||
assert "analyser" in params
|
||||
|
||||
|
||||
class TestStageModules:
|
||||
"""stage 子模块存在性测试。"""
|
||||
|
||||
def test_douyin_stage_importable(self):
|
||||
from douyin.stage import douyin_stage
|
||||
|
||||
assert douyin_stage is not None
|
||||
|
||||
def test_douyin_stage_handler_importable(self):
|
||||
from douyin.stage import douyin_stage_handler
|
||||
|
||||
assert douyin_stage_handler is not None
|
||||
|
||||
def test_stage_handler_pkg_importable(self):
|
||||
from douyin.stage import douyin_stage_handler_pkg
|
||||
|
||||
assert douyin_stage_handler_pkg is not None
|
||||
Reference in new issue
Block a user