补 reservation_handler_pkg / stage_handler_pkg 单元测试(+12 用例)
- 验证 shim 与 pkg 导出一致性 - Handler 类方法签名检查 - 子模块导入测试 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6bdf7b2527
commit
9f7e8da57a
1 file changed
+169
@@ -0,0 +1,169 @@
|
||||
"""douyin_reservation_handler_pkg + douyin_stage_handler_pkg 单元测试。
|
||||
|
||||
覆盖:
|
||||
- 子包导入一致性(shim vs pkg)
|
||||
- 类/函数签名验证
|
||||
- find_room_pos_by_title 纯逻辑测试
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import inspect
|
||||
import pytest
|
||||
|
||||
|
||||
class TestReservationHandlerPkgImports:
|
||||
"""验证 reservation_handler shim 与 pkg 导出一致。"""
|
||||
|
||||
def test_shim_vs_pkg_same_objects(self):
|
||||
from douyin.reservation.douyin_reservation_handler import (
|
||||
ReservationHandler as H1,
|
||||
find_room_pos_by_title as f1,
|
||||
record_room_title_and_pos as f2,
|
||||
seek_reservation_room as f3,
|
||||
handle_reservation_direct_attend as f4,
|
||||
)
|
||||
from douyin.reservation.douyin_reservation_handler_pkg import (
|
||||
ReservationHandler as H2,
|
||||
find_room_pos_by_title as g1,
|
||||
record_room_title_and_pos as g2,
|
||||
seek_reservation_room as g3,
|
||||
handle_reservation_direct_attend as g4,
|
||||
)
|
||||
assert H1 is H2
|
||||
assert f1 is g1
|
||||
assert f2 is g2
|
||||
assert f3 is g3
|
||||
assert f4 is g4
|
||||
|
||||
def test_handler_class_has_expected_methods(self):
|
||||
from douyin.reservation.douyin_reservation_handler_pkg import ReservationHandler
|
||||
|
||||
expected = [
|
||||
"find_room_pos_by_title",
|
||||
"record_room_title_and_pos",
|
||||
"seek_reservation_room",
|
||||
"handle_reservation_direct_attend",
|
||||
]
|
||||
for name in expected:
|
||||
assert hasattr(ReservationHandler, name), f"缺少方法: {name}"
|
||||
method = getattr(ReservationHandler, name)
|
||||
assert callable(method)
|
||||
|
||||
|
||||
class TestStageHandlerPkgImports:
|
||||
"""验证 stage_handler shim 与 pkg 导出一致。"""
|
||||
|
||||
def test_shim_vs_pkg_same_objects(self):
|
||||
from douyin.stage.douyin_stage_handler import (
|
||||
StageHandler as H1,
|
||||
diagnose_stage_from_current_screen as f1,
|
||||
check_in_live_room_by_icon as f2,
|
||||
handle_in_fudai_detail as f3,
|
||||
handle_live_room_has_or_not_fudai as f4,
|
||||
)
|
||||
from douyin.stage.douyin_stage_handler_pkg import (
|
||||
StageHandler as H2,
|
||||
diagnose_stage_from_current_screen as g1,
|
||||
check_in_live_room_by_icon as g2,
|
||||
handle_in_fudai_detail as g3,
|
||||
handle_live_room_has_or_not_fudai as g4,
|
||||
)
|
||||
assert H1 is H2
|
||||
assert f1 is g1
|
||||
assert f2 is g2
|
||||
assert f3 is g3
|
||||
assert f4 is g4
|
||||
|
||||
def test_handler_class_has_expected_methods(self):
|
||||
from douyin.stage.douyin_stage_handler_pkg 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 TestFindRoomPosLogic:
|
||||
"""find_room_pos_by_title 纯逻辑测试(不依赖 analyser)。"""
|
||||
|
||||
def test_function_signature(self):
|
||||
from douyin.reservation.douyin_reservation_handler_pkg import find_room_pos_by_title
|
||||
|
||||
sig = inspect.signature(find_room_pos_by_title)
|
||||
params = list(sig.parameters.keys())
|
||||
assert "analyser" in params
|
||||
assert "target_title" in params
|
||||
|
||||
def test_submodule_imports(self):
|
||||
from douyin.reservation.douyin_reservation_handler_pkg.find_room import (
|
||||
find_room_pos_by_title,
|
||||
)
|
||||
from douyin.reservation.douyin_reservation_handler_pkg.record_title import (
|
||||
record_room_title_and_pos,
|
||||
)
|
||||
from douyin.reservation.douyin_reservation_handler_pkg.seek_room import (
|
||||
seek_reservation_room,
|
||||
)
|
||||
from douyin.reservation.douyin_reservation_handler_pkg.direct_attend import (
|
||||
handle_reservation_direct_attend,
|
||||
)
|
||||
from douyin.reservation.douyin_reservation_handler_pkg.dump_state import (
|
||||
_dump_room_pos_map_to_state,
|
||||
)
|
||||
|
||||
assert callable(find_room_pos_by_title)
|
||||
assert callable(record_room_title_and_pos)
|
||||
assert callable(seek_reservation_room)
|
||||
assert callable(handle_reservation_direct_attend)
|
||||
assert callable(_dump_room_pos_map_to_state)
|
||||
|
||||
|
||||
class TestStageSubmoduleImports:
|
||||
"""stage_handler_pkg 子模块导入测试。"""
|
||||
|
||||
def test_diagnose_import(self):
|
||||
from douyin.stage.douyin_stage_handler_pkg.diagnose import (
|
||||
diagnose_stage_from_current_screen,
|
||||
)
|
||||
assert callable(diagnose_stage_from_current_screen)
|
||||
|
||||
def test_check_live_import(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_handle_detail_import(self):
|
||||
from douyin.stage.douyin_stage_handler_pkg.handle_detail import (
|
||||
handle_in_fudai_detail,
|
||||
)
|
||||
assert callable(handle_in_fudai_detail)
|
||||
|
||||
def test_handle_room_import(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)
|
||||
|
||||
|
||||
class TestDiagnoseSignature:
|
||||
"""diagnose_stage_from_current_screen 签名验证。"""
|
||||
|
||||
def test_signature_has_analyser(self):
|
||||
from douyin.stage.douyin_stage_handler_pkg import diagnose_stage_from_current_screen
|
||||
|
||||
sig = inspect.signature(diagnose_stage_from_current_screen)
|
||||
params = list(sig.parameters.keys())
|
||||
assert "analyser" in params
|
||||
|
||||
def test_check_live_returns_tuple(self):
|
||||
from douyin.stage.douyin_stage_handler_pkg 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
|
||||
Reference in new issue
Block a user