Files
douyin_guaji-main/test_screenshot_service_ocr_simple.py
T
Your Name 478ae69052 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.
2026-01-01 10:04:32 +08:00

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)