- Removed trailing whitespace and ensured files end with a single newline in cleanup_unused_files.py. - Added fix_trailing_whitespace.py to batch remove trailing whitespace from Python files. - Updated install_dependencies.py to improve dependency installation prompts. - Cleaned up pick_coords.py by removing unnecessary whitespace and improving code readability. - Enhanced region_selector.py by disabling specific pylint checks for better compatibility with third-party libraries. - Improved WPS流程图生成工具.py by cleaning up whitespace and enhancing readability. - Updated __init__.py in typings to remove unnecessary lines. - Modified app.js to adjust default configuration values and clean up unused code.
85 lines
2.6 KiB
Python
85 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
简单测试:验证OCR时停止后台截图服务的代码修改
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
|
|
# 添加项目根目录到路径
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
def test_code_modification():
|
|
"""测试代码修改是否正确"""
|
|
print("测试OCR时停止后台截图服务的代码修改...")
|
|
|
|
# 1. 检查文件是否存在
|
|
file_path = "fudai_detail_modules/fudai_detail_reader.py"
|
|
if not os.path.exists(file_path):
|
|
print(f"[FAIL] 文件不存在: {file_path}")
|
|
return False
|
|
|
|
# 2. 检查代码中是否包含停止服务的逻辑
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
# 检查关键代码片段
|
|
checks = [
|
|
("停止服务代码", "service.stop()" in content),
|
|
("启动服务代码", "service.start(" in content),
|
|
("screenshot_service_stopped变量", "screenshot_service_stopped" in content),
|
|
("finally块", "finally:" in content),
|
|
("ScreenshotService导入", "from operations.screenshot_service import ScreenshotService" in content),
|
|
]
|
|
|
|
all_passed = True
|
|
for check_name, result in checks:
|
|
if result:
|
|
print(f"[OK] {check_name}")
|
|
else:
|
|
print(f"[FAIL] {check_name}")
|
|
all_passed = False
|
|
|
|
# 3. 检查语法是否正确
|
|
try:
|
|
compile(content, file_path, 'exec')
|
|
print("[OK] 语法检查通过")
|
|
except SyntaxError as e:
|
|
print(f"[FAIL] 语法错误: {e}")
|
|
all_passed = False
|
|
|
|
# 4. 检查导入是否工作
|
|
read_fudai_detail_once = None # 初始化变量
|
|
try:
|
|
from fudai_detail_modules.fudai_detail_reader import read_fudai_detail_once
|
|
print("[OK] 模块导入成功")
|
|
except ImportError as e:
|
|
print(f"[FAIL] 模块导入失败: {e}")
|
|
all_passed = False
|
|
|
|
# 5. 检查函数签名
|
|
import inspect
|
|
try:
|
|
if read_fudai_detail_once is not None:
|
|
sig = inspect.signature(read_fudai_detail_once)
|
|
print(f"[OK] 函数签名: {sig}")
|
|
else:
|
|
print("[SKIP] 函数未导入,跳过签名检查")
|
|
except Exception as e:
|
|
print(f"[FAIL] 函数签名检查失败: {e}")
|
|
all_passed = False
|
|
|
|
print()
|
|
if all_passed:
|
|
print("[SUCCESS] 代码修改验证通过!")
|
|
print("OCR密集操作时会自动停止后台截图服务,避免资源冲突。")
|
|
else:
|
|
print("[FAIL] 代码修改存在问题,请检查!")
|
|
|
|
return all_passed
|
|
|
|
if __name__ == "__main__":
|
|
success = test_code_modification()
|
|
sys.exit(0 if success else 1)
|