refactor(underlying): 抽 cut_pic 图片裁剪到 image_ops (1574 → 1327)
underlying_operations.cut_pic L474-721 是 248 行图片裁剪管道: - 默认/命名两个分支共享重试 3 次的截图加载验证 - 默认分支裁出 cut.png 或 ocr/<name>.png;命名分支裁出 pic/<target>/<name>.png - 写入 _ocr_coords_cache 供 analyse_pic_word 调试图像引用 - SAVE_CUT_PIC_DEBUG_IMAGES=1 时保存 cut_pic 调试图 抽到 underlying_operations_pkg/image_ops.py: - cut_pic(self, left_up, right_down, target, name) -> bool - _ensure_parent_dir / _validate_coords / _save_cut_debug_images 内部 helper 主类方法替换为 4 行委托。 更新两个旧的源码断言测试以适配抽离: - test_cut_pic_path:从 inspect.getsource(op.cut_pic) 改为读 image_ops.py 文件源码 - test_runtime_path_anchors:把 path_config.get_pic_dir() 检查范围从单一文件 扩展到 underlying_operations.py + image_ops.py + ocr_pipeline.py 三处 1361 passed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
8457219241
commit
e46497ea80
4 files changed
+305
-258
No files matched your search
@@ -16,16 +16,26 @@ import pytest
|
||||
|
||||
|
||||
def test_cut_pic_uses_path_config_not_local_dirname():
|
||||
"""cut_pic 源码不能再用 os.path.dirname(__file__) + "/pic"。"""
|
||||
from douyin.core.underlying_operations import underlying_operations
|
||||
op = underlying_operations()
|
||||
src = inspect.getsource(op.cut_pic)
|
||||
"""cut_pic 实现源码不能再用 os.path.dirname(__file__) + "/pic"。
|
||||
|
||||
cut_pic 已抽到 underlying_operations_pkg/image_ops.py。
|
||||
主类方法 op.cut_pic 是 delegation wrapper,inspect.getsource 取到的是 wrapper 源码;
|
||||
所以这里直接读 image_ops.py 文件源码做断言。
|
||||
"""
|
||||
import os as _os
|
||||
repo_root = _os.path.dirname(_os.path.dirname(_os.path.abspath(__file__)))
|
||||
image_ops_path = _os.path.join(
|
||||
repo_root, "douyin", "core", "underlying_operations_pkg", "image_ops.py"
|
||||
)
|
||||
with open(image_ops_path, "r", encoding="utf-8") as f:
|
||||
src = f.read()
|
||||
|
||||
assert 'os.path.dirname(__file__) + "/pic"' not in src, (
|
||||
"cut_pic 仍在用 dirname(__file__) 推路径,"
|
||||
"会指向 douyin/core/pic/(不存在),应该用 path_config.get_pic_dir()"
|
||||
"image_ops.cut_pic 仍在用 dirname(__file__) 推路径,"
|
||||
"会指向错误位置,应该用 path_config.get_pic_dir()"
|
||||
)
|
||||
assert 'os.path.dirname(__file__) + "/pic/' not in src, (
|
||||
"cut_pic target 分支仍在用 dirname(__file__) 推路径"
|
||||
"image_ops.cut_pic target 分支仍在用 dirname(__file__) 推路径"
|
||||
)
|
||||
# 至少一处使用 path_config
|
||||
assert "path_config.get_pic_dir" in src or "path_config.get_screenshot_path" in src
|
||||
|
||||
Reference in new issue
Block a user