chore: Clean up blank lines and enhance code organization
- Removed excessive blank lines from multiple Python scripts and configuration files to improve readability and maintainability. - Ensured consistent formatting across the project, contributing to a more organized codebase. - Added new files for testing and analysis, including `test_screenshot_error_handling.py` and `test_screenshot_reuse_optimization.py`, to improve testing coverage and functionality.
This commit is contained in:
1 parent
7db9864848
commit
478ae69052
85 files changed
+2879
-383
No files matched your search
@@ -0,0 +1,91 @@
|
||||
#!/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_service_ocr_integration():
|
||||
"""测试截图服务与OCR集成的优化"""
|
||||
print("=" * 80)
|
||||
print("测试OCR时停止后台截图服务的优化")
|
||||
print("=" * 80)
|
||||
|
||||
# 1. 启动截图服务
|
||||
print("\n1. 启动后台截图服务...")
|
||||
from operations.screenshot_service import ScreenshotService
|
||||
service = ScreenshotService.get_instance()
|
||||
|
||||
# 模拟设备ID(实际测试时需要替换为真实设备ID)
|
||||
device_id = "emulator-5554"
|
||||
|
||||
if service.is_running():
|
||||
print("服务已在运行")
|
||||
else:
|
||||
service.start(device_id, interval=1.5)
|
||||
time.sleep(0.5) # 等待服务启动
|
||||
|
||||
if service.is_running():
|
||||
print("[OK] 后台截图服务启动成功")
|
||||
else:
|
||||
print("[FAIL] 后台截图服务启动失败")
|
||||
return
|
||||
|
||||
# 2. 模拟OCR密集操作
|
||||
print("\n2. 模拟OCR密集操作(调用read_fudai_detail_once)...")
|
||||
|
||||
# 创建一个模拟的analyser对象
|
||||
class MockAnalyser:
|
||||
def __init__(self):
|
||||
self.device_id = device_id
|
||||
self._fudai_detail_task_count_from_stage = 2
|
||||
|
||||
def _log_kv(self, key, value, **kwargs):
|
||||
timestamp = time.strftime("%H:%M:%S", time.localtime())
|
||||
print(f"[{timestamp}] [{key}] {value}")
|
||||
|
||||
analyser = MockAnalyser()
|
||||
|
||||
# 调用read_fudai_detail_once,这应该会停止后台服务
|
||||
start_time = time.time()
|
||||
try:
|
||||
from fudai_detail_modules.fudai_detail_reader import read_fudai_detail_once
|
||||
result = read_fudai_detail_once(analyser)
|
||||
elapsed = time.time() - start_time
|
||||
print(".2f")
|
||||
print(f" 返回状态: {result[0]}")
|
||||
except Exception as e:
|
||||
elapsed = time.time() - start_time
|
||||
print(".2f")
|
||||
print(f" 错误: {e}")
|
||||
|
||||
# 3. 检查服务是否重新启动
|
||||
print("\n3. 检查后台截图服务是否重新启动...")
|
||||
time.sleep(0.5) # 等待服务重新启动
|
||||
|
||||
if service.is_running():
|
||||
print("[OK] 后台截图服务已自动重新启动")
|
||||
info = service.get_cache_info()
|
||||
print(f" 设备ID: {info['device_id']}")
|
||||
print(f" 截图间隔: {info['interval']}秒")
|
||||
print(f" 缓存有效期: {info['cache_valid_duration']}秒")
|
||||
else:
|
||||
print("[FAIL] 后台截图服务未重新启动")
|
||||
|
||||
# 4. 清理
|
||||
if service.is_running():
|
||||
service.stop()
|
||||
print("\n4. 测试完成,停止后台截图服务")
|
||||
|
||||
print("\n" + "=" * 80)
|
||||
print("测试完成")
|
||||
print("=" * 80)
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_screenshot_service_ocr_integration()
|
||||
Reference in new issue
Block a user