精简像素调试图与日志
This commit is contained in:
1 parent
168ab4e1f8
commit
e51d37890a
11 files changed
+663
-297
No files matched your search
@@ -158,6 +158,54 @@ class TestPixelStage:
|
||||
assert hasattr(stage_mod, "detect_attend_button_red_area")
|
||||
assert hasattr(stage_mod, "detect_fansclub_join_red_area")
|
||||
|
||||
def test_read_pixel_stage_saves_single_overview_debug_image(self, tmp_path, monkeypatch):
|
||||
from douyin.detection.pixel.stage import read_pixel_stage_state_from_screenshot
|
||||
|
||||
img_path = tmp_path / "screen.png"
|
||||
Image.new("RGB", (1080, 2400), (20, 20, 20)).save(img_path)
|
||||
debug_dir = tmp_path / "debug"
|
||||
debug_dir.mkdir()
|
||||
(debug_dir / "20260603_像素检测_抽奖结果_检测前.png").write_bytes(b"old")
|
||||
(debug_dir / "20260603_px_attend_pre.png").write_bytes(b"old")
|
||||
|
||||
calls = []
|
||||
|
||||
def fake_save_debug_image(image, **kwargs):
|
||||
calls.append(kwargs)
|
||||
return str(debug_dir / "20260603_px_pxstage_ov_ok_0.png")
|
||||
|
||||
monkeypatch.setattr(
|
||||
"douyin.handlers.screenshot_manager.save_image_helpers.is_debug_captures_enabled",
|
||||
lambda: True,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"douyin.handlers.screenshot_manager.paths.get_debug_captures_dir",
|
||||
lambda: str(debug_dir),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"douyin.handlers.douyin_screenshot_manager.save_debug_image",
|
||||
fake_save_debug_image,
|
||||
)
|
||||
|
||||
read_pixel_stage_state_from_screenshot(
|
||||
str(img_path),
|
||||
return_details=True,
|
||||
analyser=SimpleNamespace(
|
||||
fudai_detail_ui_mode="v2_0",
|
||||
pixel_detect_coupon_popup_enabled=False,
|
||||
pixel_detect_shopping_redpacket_enabled=False,
|
||||
pixel_detect_fudai_detail_enabled=False,
|
||||
),
|
||||
)
|
||||
|
||||
assert len(calls) == 1
|
||||
assert calls[0]["operation_type"] == "pixel_detect"
|
||||
assert calls[0]["picname"] == "pixel_stage"
|
||||
assert calls[0]["step"] == "overview"
|
||||
assert calls[0]["annotate"] is False
|
||||
assert not (debug_dir / "20260603_像素检测_抽奖结果_检测前.png").exists()
|
||||
assert not (debug_dir / "20260603_px_attend_pre.png").exists()
|
||||
|
||||
|
||||
class TestPixelCommon:
|
||||
"""pixel/_common 模块测试。"""
|
||||
|
||||
@@ -96,6 +96,51 @@ class TestSaveImageModule:
|
||||
|
||||
assert callable(save_debug_image)
|
||||
|
||||
def test_build_debug_filename_uses_short_english_codes(self):
|
||||
from douyin.handlers.screenshot_manager.save_image_helpers import build_debug_filename
|
||||
|
||||
filename = build_debug_filename(
|
||||
"pixel_detect",
|
||||
"lucky_draw_result",
|
||||
"before_detect",
|
||||
(290, 1300, 790, 1415),
|
||||
{
|
||||
"threshold": 0.8,
|
||||
"region_size": "500x115",
|
||||
"ui_version": "v2_0",
|
||||
"pixel_style": "white",
|
||||
"text_preview": "我知道了",
|
||||
},
|
||||
)
|
||||
|
||||
assert filename.endswith(".png")
|
||||
assert len(filename) <= 120
|
||||
assert "_px_lottery_pre_" in filename
|
||||
assert "像素检测" not in filename
|
||||
assert "抽奖结果" not in filename
|
||||
assert "检测前" not in filename
|
||||
|
||||
def test_cleanup_single_operation_debug_images_keeps_only_pixel_latest(self, tmp_path, monkeypatch):
|
||||
from douyin.handlers.screenshot_manager.save_image_helpers import (
|
||||
cleanup_single_operation_debug_images,
|
||||
)
|
||||
|
||||
(tmp_path / "20260603_像素检测_福袋图标_检测成功.png").write_bytes(b"old")
|
||||
(tmp_path / "20260603_px_pxstage_ov_ok_1.png").write_bytes(b"old")
|
||||
ocr_file = tmp_path / "20260603_ocr_fdcontent_postocr.png"
|
||||
ocr_file.write_bytes(b"keep")
|
||||
|
||||
monkeypatch.setattr(
|
||||
"douyin.handlers.screenshot_manager.save_image_helpers.get_debug_captures_dir",
|
||||
lambda: str(tmp_path),
|
||||
)
|
||||
|
||||
cleanup_single_operation_debug_images("pixel_detect")
|
||||
|
||||
assert not (tmp_path / "20260603_像素检测_福袋图标_检测成功.png").exists()
|
||||
assert not (tmp_path / "20260603_px_pxstage_ov_ok_1.png").exists()
|
||||
assert ocr_file.exists()
|
||||
|
||||
|
||||
class TestScreenshotManagerSubmodules:
|
||||
"""screenshot_manager 子模块存在性测试。"""
|
||||
|
||||
Reference in new issue
Block a user