修复福袋详情OCR v2与调试日志
This commit is contained in:
1 parent
2c6f024a24
commit
1d37d57c90
119 files changed
+5582
-767
No files matched your search
@@ -209,6 +209,55 @@ class TestScreenshotAndDiagnose:
|
||||
assert s._last_diag_seen == {"detail_seen": False}
|
||||
|
||||
|
||||
class TestFinderReuseRecovery:
|
||||
def test_invalid_reused_screenshot_falls_back_to_fresh_capture(self, monkeypatch, tmp_path):
|
||||
from douyin.detection.detection_pkg import finder as mod
|
||||
|
||||
class _Pic:
|
||||
size = (1080, 2400)
|
||||
def load(self): return None
|
||||
def convert(self, _mode): return self
|
||||
def close(self): return None
|
||||
|
||||
screenshot_path = tmp_path / "screenshot.png"
|
||||
screenshot_path.write_bytes(b"x" * 2048)
|
||||
|
||||
analyser = MagicMock()
|
||||
analyser.fudai_finder_optimized_enabled = False
|
||||
analyser.device_id = "MOCK"
|
||||
analyser._screenshot_ready_for_ocr = True
|
||||
analyser.operation = MagicMock()
|
||||
analyser.operation.get_screenshot = MagicMock(return_value=True)
|
||||
analyser.operation.delay = MagicMock(return_value=None)
|
||||
analyser.resolution_ratio_x = 1080
|
||||
analyser.resolution_ratio_y = 2400
|
||||
analyser.y_pianyi = 0
|
||||
analyser._log_kv = MagicMock(return_value=None)
|
||||
|
||||
state = {"count": 0}
|
||||
def _open(_path):
|
||||
state["count"] += 1
|
||||
if state["count"] == 1:
|
||||
raise OSError("broken reused screenshot")
|
||||
return _Pic()
|
||||
|
||||
import sys
|
||||
from types import ModuleType, SimpleNamespace
|
||||
|
||||
pil_mod = ModuleType("PIL")
|
||||
pil_mod.Image = SimpleNamespace(open=_open)
|
||||
monkeypatch.setitem(sys.modules, "PIL", pil_mod)
|
||||
monkeypatch.setattr("douyin.detection.detection_pkg.finder.path_config.get_screenshot_path", lambda: str(screenshot_path))
|
||||
monkeypatch.setattr("douyin.detection.detection_pkg.finder.scan_with_numpy", lambda *a, **k: (False, None))
|
||||
monkeypatch.setattr("douyin.detection.detection_pkg.finder.scan_pixel_by_pixel", lambda *a, **k: (False, None))
|
||||
monkeypatch.setattr("douyin.detection.detection_pkg.finder.match_template", lambda *a, **k: (False, None))
|
||||
|
||||
result = mod.check_have_fudai_with_ready_screenshot(analyser, screenshot_ready=True)
|
||||
|
||||
assert result is False
|
||||
analyser.operation.get_screenshot.assert_called_once_with(analyser.device_id, use_service=False)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# dispatch_stage_branch
|
||||
# ============================================================
|
||||
|
||||
Reference in new issue
Block a user