#!/usr/bin/env python3
"""
运行MediaManager测试的脚本
"""

import os
import sys
from pathlib import Path

# 添加项目根目录到Python路径
project_root = Path(__file__).parent.parent
sys.path.insert(0, str(project_root))

def main():
    print("🎬 MediaManager 测试运行器")
    print("=" * 50)
    
    # 检查Python环境
    print(f"Python版本: {sys.version}")
    print(f"项目根目录: {project_root}")
    
    # 检查测试视频
    assets_dir = project_root / "assets"
    if not assets_dir.exists():
        print("❌ assets文件夹不存在")
        return 1
    
    video_files = list(assets_dir.rglob("*.mp4"))
    print(f"📹 找到 {len(video_files)} 个测试视频文件")
    
    if not video_files:
        print("❌ 没有找到测试视频文件")
        return 1
    
    # 显示前几个视频文件
    print("测试视频文件:")
    for i, video in enumerate(video_files[:3]):
        size_mb = video.stat().st_size / (1024 * 1024)
        print(f"  {i+1}. {video.name} ({size_mb:.1f} MB)")
    
    if len(video_files) > 3:
        print(f"  ... 还有 {len(video_files) - 3} 个文件")
    
    print("\n" + "=" * 50)
    print("开始运行测试...")
    print("=" * 50)
    
    try:
        # 导入并运行测试
        from tests.test_media_manager import run_comprehensive_test
        success = run_comprehensive_test()
        
        if success:
            print("\n✅ 所有测试通过！")
            return 0
        else:
            print("\n❌ 部分测试失败")
            return 1
            
    except ImportError as e:
        print(f"❌ 导入测试模块失败: {e}")
        print("请确保所有依赖都已安装")
        return 1
    except Exception as e:
        print(f"❌ 运行测试时出错: {e}")
        return 1

if __name__ == "__main__":
    exit_code = main()
    sys.exit(exit_code)
