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
@@ -39,10 +39,19 @@ class TestUnderlyingOperationsPaths:
|
||||
)
|
||||
|
||||
def test_ocr_category_dir_uses_path_config(self):
|
||||
src = _read("douyin", "core", "underlying_operations.py")
|
||||
# 之前是 base_dir = dirname(__file__); pic_base = os.path.join(base_dir, "pic")
|
||||
# 修复后必须用 get_pic_dir
|
||||
assert "path_config.get_pic_dir()" in src
|
||||
"""OCR category 目录与 cut_pic 都用 path_config.get_pic_dir 派生路径。
|
||||
|
||||
cut_pic 已抽到 underlying_operations_pkg/image_ops.py,
|
||||
OCR category 已抽到 underlying_operations_pkg/ocr_pipeline.py。
|
||||
在所有 3 个文件至少一处使用 path_config.get_pic_dir() 即视为通过。
|
||||
"""
|
||||
sources = [
|
||||
_read("douyin", "core", "underlying_operations.py"),
|
||||
_read("douyin", "core", "underlying_operations_pkg", "image_ops.py"),
|
||||
_read("douyin", "core", "underlying_operations_pkg", "ocr_pipeline.py"),
|
||||
]
|
||||
combined = "\n".join(sources)
|
||||
assert "path_config.get_pic_dir()" in combined
|
||||
|
||||
def test_no_dirname_pic_pattern_anywhere(self):
|
||||
"""整个文件不应再出现 `dirname(__file__) ... "pic"` 这种**单步**拼接。
|
||||
|
||||
Reference in new issue
Block a user