- 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.
93 lines
2.4 KiB
Python
93 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
测试OCR期间截图文件等待逻辑
|
|
"""
|
|
|
|
import time
|
|
import sys
|
|
import os
|
|
|
|
# 添加项目根目录到路径
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
def test_screenshot_file_wait():
|
|
"""测试截图文件等待逻辑"""
|
|
|
|
print("测试OCR期间截图文件等待逻辑...")
|
|
|
|
# 1. 模拟截图文件不存在的情况
|
|
print("\n1. 模拟截图文件等待...")
|
|
|
|
try:
|
|
import path_config
|
|
pic_path = path_config.get_screenshot_path()
|
|
except Exception:
|
|
pic_path = os.path.join(os.path.dirname(__file__), "pic", "screenshot.png")
|
|
|
|
print(f"截图文件路径: {pic_path}")
|
|
|
|
# 检查文件是否存在
|
|
if os.path.exists(pic_path):
|
|
print("截图文件已存在")
|
|
file_size = os.path.getsize(pic_path)
|
|
print(f"文件大小: {file_size} bytes")
|
|
else:
|
|
print("截图文件不存在")
|
|
|
|
# 2. 模拟等待逻辑
|
|
print("\n2. 测试等待逻辑...")
|
|
|
|
wait_start = time.time()
|
|
max_wait = 3.0
|
|
found = False
|
|
|
|
while time.time() - wait_start < max_wait:
|
|
if os.path.exists(pic_path):
|
|
file_size = os.path.getsize(pic_path)
|
|
if file_size >= 1024: # 至少1KB
|
|
found = True
|
|
break
|
|
time.sleep(0.1)
|
|
|
|
wait_time = time.time() - wait_start
|
|
|
|
if found:
|
|
print(".2f")
|
|
else:
|
|
print(f"等待{max_wait}秒后仍未找到有效截图文件")
|
|
|
|
# 3. 分析问题
|
|
print("\n3. 问题分析:")
|
|
|
|
issues = []
|
|
|
|
if not found:
|
|
issues.append("[WARN] 等待期间未找到截图文件")
|
|
else:
|
|
issues.append("[OK] 成功等到截图文件")
|
|
|
|
# 检查文件完整性
|
|
if os.path.exists(pic_path):
|
|
try:
|
|
with open(pic_path, 'rb') as f:
|
|
header = f.read(4)
|
|
if header == b'\x89PNG':
|
|
issues.append("[OK] 截图文件格式正确 (PNG)")
|
|
else:
|
|
issues.append("[WARN] 截图文件格式异常")
|
|
except Exception as e:
|
|
issues.append(f"[ERROR] 读取截图文件失败: {e}")
|
|
else:
|
|
issues.append("[ERROR] 截图文件不存在")
|
|
|
|
for issue in issues:
|
|
print(issue)
|
|
|
|
print(f"\n测试结果: {'PASS' if found else 'FAIL'}")
|
|
return found
|
|
|
|
if __name__ == "__main__":
|
|
success = test_screenshot_file_wait()
|
|
sys.exit(0 if success else 1)
|