AI-video-lifeplan-demo/test_modules.py

209 lines
6.3 KiB
Python

#!/usr/bin/env python3
"""
Quick Test Script - Verify All Modules
This script tests each module independently to ensure everything works.
Run this before running the full pipeline.
"""
import os
import sys
from pathlib import Path
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Color output
class Colors:
GREEN = '\033[92m'
RED = '\033[91m'
YELLOW = '\033[93m'
BLUE = '\033[94m'
END = '\033[0m'
def print_test(name, status, message=""):
symbol = f"{Colors.GREEN}✓{Colors.END}" if status else f"{Colors.RED}✗{Colors.END}"
print(f"{symbol} {name}", end="")
if message:
print(f" - {Colors.YELLOW}{message}{Colors.END}")
else:
print()
def test_env_vars():
"""Test if all required environment variables are set"""
print(f"\n{Colors.BLUE}=== Testing Environment Variables ==={Colors.END}")
keys = {
"GEMINI_API_KEY": os.getenv("GEMINI_API_KEY"),
"OPENAI_API_KEY": os.getenv("OPENAI_API_KEY"),
"PEXELS_API_KEY": os.getenv("PEXELS_API_KEY")
}
all_set = True
for key, value in keys.items():
is_set = value is not None and len(value) > 0
print_test(key, is_set, "Not set" if not is_set else "Set")
if not is_set:
all_set = False
return all_set
def test_ffmpeg():
"""Test if FFmpeg is installed"""
print(f"\n{Colors.BLUE}=== Testing FFmpeg ==={Colors.END}")
try:
from backend.video_processor.utils import check_ffmpeg_installed
installed = check_ffmpeg_installed()
print_test("FFmpeg installed", installed, "Not found in PATH" if not installed else "")
return installed
except Exception as e:
print_test("FFmpeg test", False, str(e))
return False
def test_pdf_extractor():
"""Test PDF extraction module"""
print(f"\n{Colors.BLUE}=== Testing PDF Extractor ==={Colors.END}")
try:
from backend.extractor import PDFExtractor
extractor = PDFExtractor()
print_test("PDFExtractor initialized", True)
return True
except Exception as e:
print_test("PDFExtractor", False, str(e))
return False
def test_video_extractor():
"""Test video extraction module"""
print(f"\n{Colors.BLUE}=== Testing Video Extractor ==={Colors.END}")
try:
from backend.extractor import VideoExtractor
extractor = VideoExtractor()
print_test("VideoExtractor initialized", True)
return True
except Exception as e:
print_test("VideoExtractor", False, str(e))
return False
def test_script_generator():
"""Test script generator"""
print(f"\n{Colors.BLUE}=== Testing Script Generator ==={Colors.END}")
try:
from backend.scripter import ScriptGenerator
generator = ScriptGenerator()
print_test("ScriptGenerator initialized", True)
return True
except Exception as e:
print_test("ScriptGenerator", False, str(e))
return False
def test_audio_generator():
"""Test audio generator"""
print(f"\n{Colors.BLUE}=== Testing Audio Generator ==={Colors.END}")
try:
from backend.audio_generator import AudioGenerator
generator = AudioGenerator()
print_test("AudioGenerator initialized", True)
return True
except Exception as e:
print_test("AudioGenerator", False, str(e))
return False
def test_media_fetcher():
"""Test media fetcher"""
print(f"\n{Colors.BLUE}=== Testing Media Fetcher ==={Colors.END}")
try:
from backend.media_fetcher import MediaFetcher
fetcher = MediaFetcher()
print_test("MediaFetcher initialized", True)
return True
except Exception as e:
print_test("MediaFetcher", False, str(e))
return False
def test_video_slicer():
"""Test video slicer"""
print(f"\n{Colors.BLUE}=== Testing Video Slicer ==={Colors.END}")
try:
from backend.video_slicer import VideoSlicer
slicer = VideoSlicer()
print_test("VideoSlicer initialized", True)
return True
except Exception as e:
print_test("VideoSlicer", False, str(e))
return False
def test_dependencies():
"""Test Python dependencies"""
print(f"\n{Colors.BLUE}=== Testing Python Dependencies ==={Colors.END}")
deps = {
"google.genai": "google-genai",
"openai": "openai",
"requests": "requests",
"dotenv": "python-dotenv",
"rich": "rich"
}
all_installed = True
for module, package in deps.items():
try:
__import__(module)
print_test(package, True)
except ImportError:
print_test(package, False, f"Run: pip install {package}")
all_installed = False
return all_installed
def main():
print(f"{Colors.BLUE}{'='*60}{Colors.END}")
print(f"{Colors.BLUE}AI Video LifePlan - Module Test Suite{Colors.END}")
print(f"{Colors.BLUE}{'='*60}{Colors.END}")
results = {
"Environment Variables": test_env_vars(),
"Python Dependencies": test_dependencies(),
"FFmpeg": test_ffmpeg(),
"PDF Extractor": test_pdf_extractor(),
"Video Extractor": test_video_extractor(),
"Script Generator": test_script_generator(),
"Audio Generator": test_audio_generator(),
"Media Fetcher": test_media_fetcher(),
"Video Slicer": test_video_slicer(),
}
# Summary
print(f"\n{Colors.BLUE}{'='*60}{Colors.END}")
print(f"{Colors.BLUE}Test Summary{Colors.END}")
print(f"{Colors.BLUE}{'='*60}{Colors.END}")
passed = sum(1 for v in results.values() if v)
total = len(results)
for name, result in results.items():
status = f"{Colors.GREEN}PASS{Colors.END}" if result else f"{Colors.RED}FAIL{Colors.END}"
print(f"{name}: {status}")
print(f"\nTotal: {passed}/{total} passed")
if passed == total:
print(f"\n{Colors.GREEN}🎉 All tests passed! Ready to run the pipeline.{Colors.END}")
print(f"\nNext steps:")
print(f" 1. Place your PDF in assets/0_input/")
print(f" 2. Run: python main.py --pdf assets/0_input/your_file.pdf")
return 0
else:
print(f"\n{Colors.RED}❌ Some tests failed. Please fix the issues above.{Colors.END}")
return 1
if __name__ == "__main__":
sys.exit(main())