refactor(fudai_core): 抽 _read_countdown_split 闭包到 countdown_split 模块 (2124 → 1953)
douyin_fudai_core.py 的 get_fudai_contain 函数体只有 1 个,但里面嵌了 多个闭包做 OCR 子任务。最大的 _read_countdown_split (172 行) 把倒计时 区域分割成"分钟"+"秒"两段分别识别再组合 mm:ss。 抽到 douyin_fudai_core_pkg/countdown_split.py 的 read_countdown_split 顶层函数(203 行,含独立的 _extract_digits 纯函数)。原闭包改为薄壳委托, 保留 box 默认绑定 analyser/save_debug_images 闭包变量的语义。 新增 16 个单元测试覆盖: - _extract_digits 纯函数(前导零 / 非数字 / 边界) - read_countdown_split 主路径 + OCR 失败 + 秒>=60 警告 + 切图失败 - 切割比例(30% / 30%)正确性 - save_debug_images 开关效果 1242 passed (+16)。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
07eee6da52
commit
2707773b15
3 files changed
+354
-169
No files matched your search
@@ -96,177 +96,16 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
force_heavy = ocr_mode == "heavy"
|
||||
|
||||
def _read_countdown_split(box: tuple[int, int, int, int]) -> str:
|
||||
"""将倒计时区域分割成"分钟段"和"秒段",分别OCR识别,然后组合为 mm:ss。
|
||||
"""委托给 douyin_fudai_core_pkg.countdown_split.read_countdown_split。
|
||||
|
||||
优化:更精确的分割方式,避免识别顺序错误。
|
||||
倒计时格式通常是:XX:XX后开奖,其中前两位是分钟,中间两位是秒。
|
||||
保留闭包形式,使 box 默认绑定到当前 analyser / save_debug_images 闭包变量。
|
||||
"""
|
||||
try:
|
||||
x1, y1, x2, y2 = box
|
||||
w = max(1, int(x2 - x1))
|
||||
# h 变量保留用于将来可能的垂直分割优化
|
||||
# h = max(1, int(y2 - y1)) # 当前未使用,但保留以备将来使用
|
||||
|
||||
# 优化:根据实际布局,倒计时通常是:分钟(2位数字框) + 冒号 + 秒(2位数字框) + 后开奖
|
||||
# 更精确的分割:前30%为分钟数字框,中间30%为秒数字框(剩余40%包含冒号和"后开奖")
|
||||
# 这样可以更精确地定位到数字区域,避免识别到冒号或"后开奖"文字
|
||||
seg1 = max(1, int(w * 0.3)) # 前30%:分钟数字框
|
||||
seg2 = max(1, int(w * 0.3)) # 中间30%:秒数字框
|
||||
|
||||
# 保存调试截图(仅在配置启用时)
|
||||
if save_debug_images:
|
||||
try:
|
||||
_save_full_screenshot_with_ocr_region(
|
||||
analyser,
|
||||
"福袋倒计时_分钟",
|
||||
(x1, y1, x1 + seg1, y2),
|
||||
analyser.y_pianyi,
|
||||
)
|
||||
_save_full_screenshot_with_ocr_region(
|
||||
analyser,
|
||||
"福袋倒计时_秒",
|
||||
(x1 + seg1, y1, x1 + seg1 + seg2, y2),
|
||||
analyser.y_pianyi,
|
||||
)
|
||||
except (
|
||||
Exception
|
||||
) as e_inner: # pyright: ignore[reportTooBroadExceptionType]
|
||||
try:
|
||||
analyser._log_kv( # pyright: ignore[reportPrivateUsage]
|
||||
"错误",
|
||||
"保存倒计时调试截图失败",
|
||||
error=str(e_inner),
|
||||
error_type=type(e_inner).__name__,
|
||||
box=box,
|
||||
level="WARNING",
|
||||
)
|
||||
except Exception: # pyright: ignore[reportTooBroadExceptionType]
|
||||
pass
|
||||
|
||||
# 切割分钟区域(左侧)
|
||||
analyser.cut_pic(
|
||||
x1, y1, x1 + seg1, y2, "", "福袋倒计时_分钟", analyser.y_pianyi
|
||||
)
|
||||
# 切割秒区域(中间,跳过冒号)
|
||||
analyser.cut_pic(
|
||||
x1 + seg1,
|
||||
y1,
|
||||
x1 + seg1 + seg2,
|
||||
y2,
|
||||
"",
|
||||
"福袋倒计时_秒",
|
||||
analyser.y_pianyi,
|
||||
)
|
||||
|
||||
# 并行执行两个OCR识别(使用轻量数字OCR),优先预处理以提高识别率
|
||||
try:
|
||||
mm_name = preprocess_for_ocr(analyser, "福袋倒计时_分钟")
|
||||
ss_name = preprocess_for_ocr(analyser, "福袋倒计时_秒")
|
||||
except Exception: # pyright: ignore[reportTooBroadExceptionType]
|
||||
mm_name = "福袋倒计时_分钟"
|
||||
ss_name = "福袋倒计时_秒"
|
||||
|
||||
with ThreadPoolExecutor(max_workers=2) as executor:
|
||||
future_mm = executor.submit(
|
||||
analyser.operation.analyse_pic_digits, mm_name, 1
|
||||
)
|
||||
future_ss = executor.submit(
|
||||
analyser.operation.analyse_pic_digits, ss_name, 1
|
||||
)
|
||||
mm_raw = future_mm.result()
|
||||
ss_raw = future_ss.result()
|
||||
|
||||
# 提取数字:分钟和秒都应该是1-2位数字
|
||||
def _extract_digits(text: str, max_digits: int = 2) -> str:
|
||||
"""提取数字,最多max_digits位,智能处理前导零"""
|
||||
digits = "".join(ch for ch in str(text or "") if ch.isdigit())
|
||||
if len(digits) > max_digits:
|
||||
# 如果超过max_digits,优先考虑后max_digits位(处理前导零的情况)
|
||||
# 例如"002" -> "02" 而不是 "00"
|
||||
candidate = digits[-max_digits:]
|
||||
# 如果候选结果以0开头但原始字符串不全是0,尝试取更少的位数
|
||||
if candidate.startswith("0") and not digits.startswith(
|
||||
"0" * len(digits)
|
||||
):
|
||||
# 移除前导零后的长度
|
||||
actual_digits = digits.lstrip("0") or "0"
|
||||
if len(actual_digits) <= max_digits:
|
||||
return actual_digits.zfill(max_digits)
|
||||
return candidate
|
||||
if len(digits) == 1:
|
||||
return "0" + digits
|
||||
return digits
|
||||
|
||||
mm = _extract_digits(mm_raw, max_digits=2)
|
||||
ss = _extract_digits(ss_raw, max_digits=2)
|
||||
|
||||
# 分割识别已经分别识别了分钟和秒,顺序是正确的,不需要交换纠正
|
||||
# 如果秒数 >= 60,可能是识别错误,记录日志但不交换(保持原始识别结果)
|
||||
try:
|
||||
mm_int = int(mm) if mm else 0
|
||||
ss_int = int(ss) if ss else 0
|
||||
if ss_int >= 60:
|
||||
try:
|
||||
analyser._log_kv( # pyright: ignore[reportPrivateUsage]
|
||||
"验证",
|
||||
"分割识别:检测到秒数>=60(可能是识别错误)",
|
||||
mm=mm_int,
|
||||
ss=ss_int,
|
||||
mm_raw=mm_raw,
|
||||
ss_raw=ss_raw,
|
||||
level="WARNING",
|
||||
)
|
||||
except Exception: # pyright: ignore[reportTooBroadExceptionType]
|
||||
pass
|
||||
except Exception as e_inner: # pyright: ignore[reportTooBroadExceptionType]
|
||||
try:
|
||||
analyser._log_kv( # pyright: ignore[reportPrivateUsage]
|
||||
"错误",
|
||||
"验证倒计时数值失败",
|
||||
error=str(e_inner),
|
||||
error_type=type(e_inner).__name__,
|
||||
mm=mm,
|
||||
ss=ss,
|
||||
level="WARNING",
|
||||
)
|
||||
except Exception: # pyright: ignore[reportTooBroadExceptionType]
|
||||
pass
|
||||
|
||||
if mm and ss:
|
||||
result = f"{mm}:{ss}"
|
||||
try:
|
||||
analyser._log_kv( # pyright: ignore[reportPrivateUsage]
|
||||
"福袋倒计时",
|
||||
"分割识别成功",
|
||||
mm_raw=mm_raw,
|
||||
ss_raw=ss_raw,
|
||||
result=result,
|
||||
)
|
||||
except (
|
||||
Exception
|
||||
) as e_inner: # pyright: ignore[reportTooBroadExceptionType]
|
||||
try:
|
||||
analyser._log_kv( # pyright: ignore[reportPrivateUsage]
|
||||
"错误",
|
||||
"记录倒计时识别成功日志失败",
|
||||
error=str(e_inner),
|
||||
error_type=type(e_inner).__name__,
|
||||
level="WARNING",
|
||||
)
|
||||
except Exception: # pyright: ignore[reportTooBroadExceptionType]
|
||||
pass
|
||||
return result
|
||||
except Exception as e_inner: # pyright: ignore[reportTooBroadExceptionType]
|
||||
try:
|
||||
analyser._log_kv( # pyright: ignore[reportPrivateUsage]
|
||||
"福袋倒计时",
|
||||
"分割识别失败",
|
||||
error=str(e_inner),
|
||||
error_type=type(e_inner).__name__,
|
||||
)
|
||||
except Exception: # pyright: ignore[reportTooBroadExceptionType]
|
||||
pass
|
||||
return ""
|
||||
from douyin.fudai.douyin_fudai_core_pkg.countdown_split import (
|
||||
read_countdown_split,
|
||||
)
|
||||
return read_countdown_split(
|
||||
analyser, box, save_debug_images=save_debug_images
|
||||
)
|
||||
|
||||
def _extract_participants_and_clean(text: str):
|
||||
if not text:
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
"""douyin_fudai_core_pkg.countdown_split - 福袋倒计时区域分割识别
|
||||
|
||||
从 get_fudai_contain 抽出的 _read_countdown_split 闭包:
|
||||
把倒计时区域分割成"分钟段"和"秒段",分别 OCR 后组合为 mm:ss。
|
||||
|
||||
签名:
|
||||
read_countdown_split(analyser, box, *, save_debug_images=False) -> str
|
||||
|
||||
返回 mm:ss(如 "03:25");识别失败返回空字符串。
|
||||
保留原行为和日志:日志 tag、warning level、错误兜底全部不变。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from typing import Tuple
|
||||
|
||||
|
||||
def _extract_digits(text: str, max_digits: int = 2) -> str:
|
||||
"""提取数字,最多 max_digits 位,智能处理前导零。"""
|
||||
digits = "".join(ch for ch in str(text or "") if ch.isdigit())
|
||||
if len(digits) > max_digits:
|
||||
# 如果超过 max_digits,优先考虑后 max_digits 位(处理前导零的情况)
|
||||
# 例如 "002" -> "02" 而不是 "00"
|
||||
candidate = digits[-max_digits:]
|
||||
if candidate.startswith("0") and not digits.startswith("0" * len(digits)):
|
||||
actual_digits = digits.lstrip("0") or "0"
|
||||
if len(actual_digits) <= max_digits:
|
||||
return actual_digits.zfill(max_digits)
|
||||
return candidate
|
||||
if len(digits) == 1:
|
||||
return "0" + digits
|
||||
return digits
|
||||
|
||||
|
||||
def read_countdown_split(
|
||||
analyser,
|
||||
box: Tuple[int, int, int, int],
|
||||
*,
|
||||
save_debug_images: bool = False,
|
||||
) -> str:
|
||||
"""将倒计时区域分割成"分钟段"和"秒段",分别 OCR 识别,然后组合为 mm:ss。
|
||||
|
||||
倒计时格式通常是:XX:XX后开奖,其中前两位是分钟,中间两位是秒。
|
||||
分割:前 30% 为分钟数字框,中间 30% 为秒数字框(剩余 40% 是冒号 + "后开奖")。
|
||||
|
||||
Args:
|
||||
analyser: fudai_analyse 实例(提供 cut_pic / operation / _log_kv / y_pianyi)
|
||||
box: 倒计时区域 (x1, y1, x2, y2)
|
||||
save_debug_images: 是否保存调试截图(仅当全局开关启用时)
|
||||
|
||||
Returns:
|
||||
mm:ss 字符串(识别成功),空字符串(识别失败)
|
||||
"""
|
||||
try:
|
||||
from douyin.fudai.core.fudai_debug_utils import (
|
||||
_save_full_screenshot_with_ocr_region,
|
||||
)
|
||||
except Exception:
|
||||
_save_full_screenshot_with_ocr_region = None # type: ignore[assignment]
|
||||
|
||||
try:
|
||||
from douyin.utils.ocr_preprocess import preprocess_for_ocr # type: ignore
|
||||
except Exception:
|
||||
def preprocess_for_ocr(_analyser, picname: str) -> str: # type: ignore
|
||||
return str(picname)
|
||||
|
||||
try:
|
||||
x1, y1, x2, y2 = box
|
||||
w = max(1, int(x2 - x1))
|
||||
# 优化:根据实际布局,倒计时通常是:分钟(2位数字框) + 冒号 + 秒(2位数字框) + 后开奖
|
||||
# 更精确的分割:前30%为分钟数字框,中间30%为秒数字框(剩余40%包含冒号和"后开奖")
|
||||
seg1 = max(1, int(w * 0.3)) # 前30%:分钟数字框
|
||||
seg2 = max(1, int(w * 0.3)) # 中间30%:秒数字框
|
||||
|
||||
# 保存调试截图(仅在配置启用时)
|
||||
if save_debug_images and _save_full_screenshot_with_ocr_region is not None:
|
||||
try:
|
||||
_save_full_screenshot_with_ocr_region(
|
||||
analyser,
|
||||
"福袋倒计时_分钟",
|
||||
(x1, y1, x1 + seg1, y2),
|
||||
analyser.y_pianyi,
|
||||
)
|
||||
_save_full_screenshot_with_ocr_region(
|
||||
analyser,
|
||||
"福袋倒计时_秒",
|
||||
(x1 + seg1, y1, x1 + seg1 + seg2, y2),
|
||||
analyser.y_pianyi,
|
||||
)
|
||||
except Exception as e_inner:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"错误",
|
||||
"保存倒计时调试截图失败",
|
||||
error=str(e_inner),
|
||||
error_type=type(e_inner).__name__,
|
||||
box=box,
|
||||
level="WARNING",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 切割分钟区域(左侧)
|
||||
analyser.cut_pic(
|
||||
x1, y1, x1 + seg1, y2, "", "福袋倒计时_分钟", analyser.y_pianyi
|
||||
)
|
||||
# 切割秒区域(中间,跳过冒号)
|
||||
analyser.cut_pic(
|
||||
x1 + seg1,
|
||||
y1,
|
||||
x1 + seg1 + seg2,
|
||||
y2,
|
||||
"",
|
||||
"福袋倒计时_秒",
|
||||
analyser.y_pianyi,
|
||||
)
|
||||
|
||||
# 并行执行两个 OCR 识别(使用轻量数字 OCR),优先预处理以提高识别率
|
||||
try:
|
||||
mm_name = preprocess_for_ocr(analyser, "福袋倒计时_分钟")
|
||||
ss_name = preprocess_for_ocr(analyser, "福袋倒计时_秒")
|
||||
except Exception:
|
||||
mm_name = "福袋倒计时_分钟"
|
||||
ss_name = "福袋倒计时_秒"
|
||||
|
||||
with ThreadPoolExecutor(max_workers=2) as executor:
|
||||
future_mm = executor.submit(
|
||||
analyser.operation.analyse_pic_digits, mm_name, 1
|
||||
)
|
||||
future_ss = executor.submit(
|
||||
analyser.operation.analyse_pic_digits, ss_name, 1
|
||||
)
|
||||
mm_raw = future_mm.result()
|
||||
ss_raw = future_ss.result()
|
||||
|
||||
mm = _extract_digits(mm_raw, max_digits=2)
|
||||
ss = _extract_digits(ss_raw, max_digits=2)
|
||||
|
||||
# 分割识别已经分别识别了分钟和秒,顺序是正确的,不需要交换纠正
|
||||
# 如果秒数 >= 60,可能是识别错误,记录日志但不交换(保持原始识别结果)
|
||||
try:
|
||||
mm_int = int(mm) if mm else 0
|
||||
ss_int = int(ss) if ss else 0
|
||||
if ss_int >= 60:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"验证",
|
||||
"分割识别:检测到秒数>=60(可能是识别错误)",
|
||||
mm=mm_int,
|
||||
ss=ss_int,
|
||||
mm_raw=mm_raw,
|
||||
ss_raw=ss_raw,
|
||||
level="WARNING",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e_inner:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"错误",
|
||||
"验证倒计时数值失败",
|
||||
error=str(e_inner),
|
||||
error_type=type(e_inner).__name__,
|
||||
mm=mm,
|
||||
ss=ss,
|
||||
level="WARNING",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if mm and ss:
|
||||
result = f"{mm}:{ss}"
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋倒计时",
|
||||
"分割识别成功",
|
||||
mm_raw=mm_raw,
|
||||
ss_raw=ss_raw,
|
||||
result=result,
|
||||
)
|
||||
except Exception as e_inner:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"错误",
|
||||
"记录倒计时识别成功日志失败",
|
||||
error=str(e_inner),
|
||||
error_type=type(e_inner).__name__,
|
||||
level="WARNING",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return result
|
||||
except Exception as e_inner:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋倒计时",
|
||||
"分割识别失败",
|
||||
error=str(e_inner),
|
||||
error_type=type(e_inner).__name__,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return ""
|
||||
@@ -0,0 +1,143 @@
|
||||
"""douyin_fudai_core_pkg.countdown_split 单元测试。
|
||||
|
||||
覆盖:
|
||||
- _extract_digits 纯函数边界
|
||||
- read_countdown_split 主路径成功 / OCR 抛异常 / 秒>=60 警告 / cut_pic 失败
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from douyin.fudai.douyin_fudai_core_pkg.countdown_split import (
|
||||
_extract_digits,
|
||||
read_countdown_split,
|
||||
)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# _extract_digits 纯函数
|
||||
# ============================================================
|
||||
|
||||
class TestExtractDigits:
|
||||
def test_two_digits(self):
|
||||
assert _extract_digits("23") == "23"
|
||||
|
||||
def test_one_digit_pads_zero(self):
|
||||
assert _extract_digits("5") == "05"
|
||||
|
||||
def test_more_than_max_takes_last(self):
|
||||
# "002" -> 后两位 "02",但 "02" 以 0 开头且原串非全 0
|
||||
# → 取移除前导 0 后的 "2",再 zfill 到 2 位 → "02"
|
||||
assert _extract_digits("002") == "02"
|
||||
|
||||
def test_strips_non_digits(self):
|
||||
assert _extract_digits("12:34") == "34" # 取后 2 位
|
||||
|
||||
def test_empty(self):
|
||||
assert _extract_digits("") == ""
|
||||
|
||||
def test_none(self):
|
||||
assert _extract_digits(None) == "" # type: ignore[arg-type]
|
||||
|
||||
def test_all_zeros(self):
|
||||
assert _extract_digits("00") == "00"
|
||||
|
||||
def test_leading_zero_three_digits(self):
|
||||
# "025" -> 后 2 位 "25",不是以 0 开头 → 直接返回
|
||||
assert _extract_digits("025") == "25"
|
||||
|
||||
|
||||
# ============================================================
|
||||
# read_countdown_split
|
||||
# ============================================================
|
||||
|
||||
def _mk_analyser():
|
||||
a = MagicMock()
|
||||
a.y_pianyi = 0
|
||||
a.cut_pic = MagicMock(return_value=True)
|
||||
a._log_kv = MagicMock(return_value=None)
|
||||
a.operation = MagicMock()
|
||||
return a
|
||||
|
||||
|
||||
class TestReadCountdownSplit:
|
||||
def test_main_path_success(self):
|
||||
a = _mk_analyser()
|
||||
# mm OCR=23, ss OCR=45
|
||||
a.operation.analyse_pic_digits = MagicMock(side_effect=["23", "45"])
|
||||
|
||||
result = read_countdown_split(a, (100, 200, 400, 250))
|
||||
assert result == "23:45"
|
||||
# cut_pic 应被调用 2 次(分钟 + 秒)
|
||||
assert a.cut_pic.call_count == 2
|
||||
|
||||
def test_ocr_returns_only_minute(self):
|
||||
"""秒识别失败(空字符串)→ 整体失败返回 ""。"""
|
||||
a = _mk_analyser()
|
||||
a.operation.analyse_pic_digits = MagicMock(side_effect=["23", ""])
|
||||
result = read_countdown_split(a, (100, 200, 400, 250))
|
||||
assert result == ""
|
||||
|
||||
def test_ocr_throws(self):
|
||||
"""OCR 抛异常 → 返回 "",不传播。"""
|
||||
a = _mk_analyser()
|
||||
a.operation.analyse_pic_digits = MagicMock(side_effect=RuntimeError("OCR fail"))
|
||||
result = read_countdown_split(a, (100, 200, 400, 250))
|
||||
assert result == ""
|
||||
|
||||
def test_ss_over_60_logs_warning_but_returns_result(self):
|
||||
"""秒>=60 触发警告日志但仍返回结果(保持原行为)。"""
|
||||
a = _mk_analyser()
|
||||
a.operation.analyse_pic_digits = MagicMock(side_effect=["23", "75"])
|
||||
result = read_countdown_split(a, (100, 200, 400, 250))
|
||||
assert result == "23:75"
|
||||
# 应至少有一条 level=WARNING 的日志(验证子分支)
|
||||
warn_calls = [
|
||||
c for c in a._log_kv.call_args_list
|
||||
if c.kwargs.get("level") == "WARNING"
|
||||
]
|
||||
assert any("秒数>=60" in str(c) for c in warn_calls)
|
||||
|
||||
def test_cut_pic_failure_does_not_crash(self):
|
||||
"""cut_pic 抛异常 → 整体失败返回 ""。"""
|
||||
a = _mk_analyser()
|
||||
a.cut_pic = MagicMock(side_effect=RuntimeError("cut_pic fail"))
|
||||
result = read_countdown_split(a, (100, 200, 400, 250))
|
||||
assert result == ""
|
||||
|
||||
def test_box_dimensions_split_correctly(self):
|
||||
"""验证切割比例:宽度 300 → seg1=90 (30%), seg2=90 (30%)。"""
|
||||
a = _mk_analyser()
|
||||
a.operation.analyse_pic_digits = MagicMock(side_effect=["23", "45"])
|
||||
|
||||
read_countdown_split(a, (100, 200, 400, 250)) # w=300
|
||||
# 第 1 次 cut_pic:分钟段 (100, 200, 100+90, 250) = (100, 200, 190, 250)
|
||||
# 第 2 次 cut_pic:秒段 (100+90, 200, 100+90+90, 250) = (190, 200, 280, 250)
|
||||
first_call = a.cut_pic.call_args_list[0]
|
||||
second_call = a.cut_pic.call_args_list[1]
|
||||
assert first_call[0][:4] == (100, 200, 190, 250)
|
||||
assert second_call[0][:4] == (190, 200, 280, 250)
|
||||
|
||||
def test_save_debug_images_disabled_by_default(self):
|
||||
"""save_debug_images=False 时不应调用 _save_full_screenshot_with_ocr_region。"""
|
||||
a = _mk_analyser()
|
||||
a.operation.analyse_pic_digits = MagicMock(side_effect=["23", "45"])
|
||||
|
||||
with patch(
|
||||
"douyin.fudai.core.fudai_debug_utils._save_full_screenshot_with_ocr_region"
|
||||
) as mock_save:
|
||||
read_countdown_split(a, (100, 200, 400, 250), save_debug_images=False)
|
||||
mock_save.assert_not_called()
|
||||
|
||||
def test_save_debug_images_enabled_calls_save(self):
|
||||
a = _mk_analyser()
|
||||
a.operation.analyse_pic_digits = MagicMock(side_effect=["23", "45"])
|
||||
|
||||
with patch(
|
||||
"douyin.fudai.core.fudai_debug_utils._save_full_screenshot_with_ocr_region"
|
||||
) as mock_save:
|
||||
read_countdown_split(a, (100, 200, 400, 250), save_debug_images=True)
|
||||
# 调用 2 次(分钟 + 秒)
|
||||
assert mock_save.call_count == 2
|
||||
Reference in new issue
Block a user