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,95 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
测试循环期间停止后台截图服务的功能
|
||||
"""
|
||||
|
||||
import time
|
||||
import sys
|
||||
import os
|
||||
|
||||
# 添加项目根目录到路径
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
def test_loop_screenshot_service_stop():
|
||||
"""测试循环期间后台截图服务是否被停止"""
|
||||
|
||||
print("测试循环期间停止后台截图服务功能...")
|
||||
|
||||
# 1. 启动截图服务(模拟正常启动)
|
||||
print("\n1. 启动后台截图服务...")
|
||||
from operations.screenshot_service import ScreenshotService
|
||||
service = ScreenshotService.get_instance()
|
||||
|
||||
device_id = "emulator-5554"
|
||||
|
||||
if not service.is_running():
|
||||
service.start(device_id, interval=1.5)
|
||||
time.sleep(0.5)
|
||||
|
||||
if service.is_running():
|
||||
print("[OK] 后台截图服务已启动")
|
||||
else:
|
||||
print("[FAIL] 后台截图服务启动失败")
|
||||
return False
|
||||
|
||||
# 2. 模拟fudai_choujiang的逻辑
|
||||
print("\n2. 模拟循环开始前的截图服务停止...")
|
||||
|
||||
# 这部分代码模拟fudai_choujiang中的逻辑
|
||||
screenshot_service_stopped = False
|
||||
try:
|
||||
service_inner = ScreenshotService.get_instance()
|
||||
if service_inner.is_running():
|
||||
service_inner.stop()
|
||||
screenshot_service_stopped = True
|
||||
print("[OK] 循环开始前停止后台截图服务")
|
||||
except Exception as e:
|
||||
print(f"[FAIL] 停止后台截图服务失败: {e}")
|
||||
return False
|
||||
|
||||
# 检查服务是否已停止
|
||||
if service.is_running():
|
||||
print("[FAIL] 后台截图服务仍然在运行")
|
||||
return False
|
||||
else:
|
||||
print("[OK] 后台截图服务已停止")
|
||||
|
||||
# 3. 模拟循环中的操作(这里不会触发截图服务)
|
||||
print("\n3. 模拟循环中的阶段诊断...")
|
||||
time.sleep(2) # 模拟一些操作
|
||||
|
||||
# 4. 模拟程序结束(atexit会重新启动服务)
|
||||
print("\n4. 模拟程序结束,检查服务重新启动...")
|
||||
|
||||
# 手动调用atexit函数(在实际运行中会自动调用)
|
||||
if screenshot_service_stopped:
|
||||
try:
|
||||
service_restart = ScreenshotService.get_instance()
|
||||
if device_id:
|
||||
service_restart.start(device_id, interval=1.5)
|
||||
print("[OK] 循环结束后重新启动后台截图服务")
|
||||
except Exception as e:
|
||||
print(f"[FAIL] 重新启动后台截图服务失败: {e}")
|
||||
return False
|
||||
|
||||
# 检查服务是否重新启动
|
||||
time.sleep(0.5)
|
||||
if service.is_running():
|
||||
print("[OK] 后台截图服务已重新启动")
|
||||
success = True
|
||||
else:
|
||||
print("[FAIL] 后台截图服务未重新启动")
|
||||
success = False
|
||||
|
||||
# 5. 清理
|
||||
if service.is_running():
|
||||
service.stop()
|
||||
print("\n5. 测试完成,停止后台截图服务")
|
||||
|
||||
print(f"\n测试结果: {'PASS' if success else 'FAIL'}")
|
||||
return success
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = test_loop_screenshot_service_stop()
|
||||
sys.exit(0 if success else 1)
|
||||
Reference in new issue
Block a user