Files
douyi_guaji_main/deleted_tests_backup/test_loop_screenshot_stop.py
T
Your Name 0b5f150691 Refactor and clean up code across multiple scripts
- 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.
2026-01-02 23:57:03 +08:00

96 lines
3.0 KiB
Python

#!/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)