"""
测试截图功能
"""
import os
from screenshot_manager import ScreenshotManager
from loguru import logger


def test_screenshot():
    """测试截图功能"""
    logger.info("开始测试截图功能")
    
    # 创建截图管理器
    screenshot_manager = ScreenshotManager()
    
    # 测试截图
    screenshot_path = screenshot_manager.capture_chart_screenshot()
    
    if screenshot_path:
        logger.info(f"✅ 截图成功: {screenshot_path}")
        
        # 检查文件是否存在
        if os.path.exists(screenshot_path):
            file_size = os.path.getsize(screenshot_path)
            logger.info(f"截图文件大小: {file_size} 字节")
            
            # 获取最新截图
            latest_screenshot = screenshot_manager.get_latest_screenshot()
            logger.info(f"最新截图: {latest_screenshot}")
            
            # 清理旧截图
            screenshot_manager.cleanup_old_screenshots(keep_count=2)
            logger.info("清理旧截图完成")
        else:
            logger.error("截图文件不存在")
    else:
        logger.error("截图失败")
    
    logger.info("截图功能测试完成")


if __name__ == "__main__":
    test_screenshot()