Files
douyin_guaji-main/tests/test_detection_pixel.py
CodexandClaude Opus 4.5 85d7bb2525 补 douyin/detection/pixel 模块单元测试(+14 用例)
- pixel/popups 弹窗检测函数签名验证
- pixel/buttons 按钮检测函数签名验证
- pixel/stage 阶段检测函数签名验证
- shim 与子模块导出一致性验证

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-05-21 22:03:35 +08:00

153 lines
5.0 KiB
Python

"""douyin/detection/pixel 模块单元测试。
覆盖:
- pixel/popups: 弹窗检测函数签名验证
- pixel/buttons: 按钮检测函数签名验证
- pixel/stage: 阶段检测函数签名验证
"""
from __future__ import annotations
import inspect
import pytest
class TestPixelPopups:
"""pixel/popups 模块测试。"""
def test_detect_coupon_popup_exists(self):
from douyin.detection.pixel.popups import detect_coupon_popup_background
assert callable(detect_coupon_popup_background)
def test_detect_coupon_popup_signature(self):
from douyin.detection.pixel.popups import detect_coupon_popup_background
sig = inspect.signature(detect_coupon_popup_background)
params = list(sig.parameters.keys())
assert "pic_rgb" in params or len(params) >= 1
def test_detect_redpacket_popup_exists(self):
from douyin.detection.pixel.popups import detect_redpacket_popup_background
assert callable(detect_redpacket_popup_background)
def test_detect_lucky_draw_result_exists(self):
from douyin.detection.pixel.popups import detect_lucky_draw_result_popup
assert callable(detect_lucky_draw_result_popup)
class TestPixelButtons:
"""pixel/buttons 模块测试。"""
def test_detect_attend_button_exists(self):
from douyin.detection.pixel.buttons import detect_attend_button_red_area
assert callable(detect_attend_button_red_area)
def test_detect_attend_button_signature(self):
from douyin.detection.pixel.buttons import detect_attend_button_red_area
sig = inspect.signature(detect_attend_button_red_area)
params = list(sig.parameters.keys())
assert "pic_rgb" in params or len(params) >= 1
def test_detect_fansclub_join_exists(self):
from douyin.detection.pixel.buttons import detect_fansclub_join_red_area
assert callable(detect_fansclub_join_red_area)
class TestPixelStage:
"""pixel/stage 模块测试。"""
def test_detect_live_room_icons_exists(self):
from douyin.detection.pixel.stage import detect_live_room_icons_by_pixel
assert callable(detect_live_room_icons_by_pixel)
def test_detect_live_room_icons_signature(self):
from douyin.detection.pixel.stage import detect_live_room_icons_by_pixel
sig = inspect.signature(detect_live_room_icons_by_pixel)
params = list(sig.parameters.keys())
assert "pic_rgb" in params
def test_detect_fudai_detail_page_exists(self):
from douyin.detection.pixel.stage import detect_fudai_detail_page
assert callable(detect_fudai_detail_page)
def test_read_pixel_stage_state_exists(self):
from douyin.detection.pixel.stage import read_pixel_stage_state_from_screenshot
assert callable(read_pixel_stage_state_from_screenshot)
class TestPixelCommon:
"""pixel/_common 模块测试。"""
def test_safe_open_screenshot_rgb_exists(self):
from douyin.detection.pixel._common import _safe_open_screenshot_rgb
assert callable(_safe_open_screenshot_rgb)
class TestPixelShimConsistency:
"""验证 pixel shim 与子模块导出一致。"""
def test_douyin_pixel_exports_match_submodules(self):
from douyin.detection.douyin_pixel import (
detect_coupon_popup_background as f1,
detect_redpacket_popup_background as f2,
detect_lucky_draw_result_popup as f3,
detect_attend_button_red_area as f4,
detect_fansclub_join_red_area as f5,
detect_live_room_icons_by_pixel as f6,
detect_fudai_detail_page as f7,
read_pixel_stage_state_from_screenshot as f8,
)
from douyin.detection.pixel import (
detect_coupon_popup_background as g1,
detect_redpacket_popup_background as g2,
detect_lucky_draw_result_popup as g3,
detect_attend_button_red_area as g4,
detect_fansclub_join_red_area as g5,
detect_live_room_icons_by_pixel as g6,
detect_fudai_detail_page as g7,
read_pixel_stage_state_from_screenshot as g8,
)
assert f1 is g1
assert f2 is g2
assert f3 is g3
assert f4 is g4
assert f5 is g5
assert f6 is g6
assert f7 is g7
assert f8 is g8
class TestDetectionShimConsistency:
"""验证 detection shim 与子模块导出一致。"""
def test_douyin_detection_exports_match_submodules(self):
from douyin.detection.douyin_detection import (
_ensure_detection_cache as f1,
check_detail_height as f2,
check_have_fudai_with_ready_screenshot as f3,
check_in_fudai_detail as f4,
)
from douyin.detection.detection_pkg import (
_ensure_detection_cache as g1,
check_detail_height as g2,
check_have_fudai_with_ready_screenshot as g3,
check_in_fudai_detail as g4,
)
assert f1 is g1
assert f2 is g2
assert f3 is g3
assert f4 is g4