177 lines
5.4 KiB
Python
177 lines
5.4 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Test script to verify cross-platform system utilities and error reporting.
|
|
|
|
This script:
|
|
1. Tests system utility detection (ffprobe, ffmpeg, wkhtmltopdf)
|
|
2. Tests error reporting functionality
|
|
3. Verifies all dependencies are properly installed
|
|
|
|
Run this script before starting the application to ensure everything is set up correctly.
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
|
|
# Add backend directory to path
|
|
sys.path.insert(0, os.path.dirname(__file__))
|
|
|
|
from system_utils import system_utils
|
|
from error_reporter import ErrorReporter, ErrorCategory
|
|
import platform
|
|
|
|
def print_header(text):
|
|
"""Print a formatted header."""
|
|
print("\n" + "="*80)
|
|
print(f" {text}")
|
|
print("="*80)
|
|
|
|
def print_section(text):
|
|
"""Print a formatted section."""
|
|
print(f"\n--- {text} ---")
|
|
|
|
def test_system_info():
|
|
"""Test system information gathering."""
|
|
print_header("SYSTEM INFORMATION")
|
|
|
|
info = system_utils.get_system_info()
|
|
|
|
print(f"\nPlatform: {info['platform_name']}")
|
|
print(f"Platform Type: {info['platform']}")
|
|
print(f"Machine: {info['platform_machine']}")
|
|
print(f"OS Version: {info['platform_version']}")
|
|
print(f"Python Version: {info['python_version']}")
|
|
print(f"Python Implementation: {info['python_implementation']}")
|
|
|
|
def test_executables():
|
|
"""Test executable detection."""
|
|
print_header("EXECUTABLE DETECTION")
|
|
|
|
executables = [
|
|
('ffprobe', system_utils.find_ffprobe),
|
|
('ffmpeg', system_utils.find_ffmpeg),
|
|
('wkhtmltopdf', system_utils.find_wkhtmltopdf)
|
|
]
|
|
|
|
results = []
|
|
all_found = True
|
|
|
|
for name, finder in executables:
|
|
print_section(f"Testing {name}")
|
|
try:
|
|
path = finder()
|
|
verified = system_utils.verify_executable(path, name)
|
|
status = "✓ FOUND" if verified else "⚠ FOUND (not verified)"
|
|
print(f" Status: {status}")
|
|
print(f" Path: {path}")
|
|
results.append((name, True, path))
|
|
except FileNotFoundError as e:
|
|
print(f" Status: ✗ NOT FOUND")
|
|
print(f" Error: {str(e)[:200]}")
|
|
results.append((name, False, None))
|
|
all_found = False
|
|
except Exception as e:
|
|
print(f" Status: ✗ ERROR")
|
|
print(f" Error: {str(e)[:200]}")
|
|
results.append((name, False, None))
|
|
all_found = False
|
|
|
|
return all_found, results
|
|
|
|
def test_error_reporting():
|
|
"""Test error reporting functionality."""
|
|
print_header("ERROR REPORTING TESTS")
|
|
|
|
test_cases = [
|
|
("System Error", FileNotFoundError("ffprobe not found")),
|
|
("API Error", Exception("503 UNAVAILABLE: Model overloaded")),
|
|
("Video Error", Exception("moov atom not found")),
|
|
("Network Error", ConnectionError("Connection timeout")),
|
|
]
|
|
|
|
print("\nTesting error categorization and reporting...")
|
|
|
|
for description, exception in test_cases:
|
|
print_section(description)
|
|
try:
|
|
raise exception
|
|
except Exception as e:
|
|
report = ErrorReporter.capture_error(
|
|
e,
|
|
context={'test': description}
|
|
)
|
|
print(f" Error ID: {report.error_id}")
|
|
print(f" Category: {report.category.value}")
|
|
print(f" Message: {report.message[:100]}")
|
|
if report.suggested_fix:
|
|
print(f" Fix: {report.suggested_fix[:100]}...")
|
|
|
|
def print_summary(all_found, results):
|
|
"""Print summary of test results."""
|
|
print_header("SUMMARY")
|
|
|
|
print("\nExecutable Status:")
|
|
for name, found, path in results:
|
|
status = "✓" if found else "✗"
|
|
print(f" {status} {name}: {'Found' if found else 'NOT FOUND'}")
|
|
|
|
print("\n" + "="*80)
|
|
if all_found:
|
|
print("✓ ALL DEPENDENCIES FOUND - System is ready!")
|
|
print("="*80)
|
|
return 0
|
|
else:
|
|
print("✗ SOME DEPENDENCIES MISSING - Please install them before running the app")
|
|
print("="*80)
|
|
print("\nInstallation instructions:")
|
|
|
|
system = platform.system().lower()
|
|
if 'darwin' in system:
|
|
print("\n macOS (Homebrew):")
|
|
print(" brew install ffmpeg wkhtmltopdf")
|
|
elif 'linux' in system:
|
|
print("\n Ubuntu/Debian:")
|
|
print(" sudo apt-get update")
|
|
print(" sudo apt-get install ffmpeg wkhtmltopdf")
|
|
print("\n CentOS/RHEL:")
|
|
print(" sudo yum install ffmpeg wkhtmltopdf")
|
|
else:
|
|
print("\n Windows:")
|
|
print(" Download ffmpeg from: https://ffmpeg.org/download.html")
|
|
print(" Download wkhtmltopdf from: https://wkhtmltopdf.org/downloads.html")
|
|
|
|
print("\n" + "="*80)
|
|
return 1
|
|
|
|
def main():
|
|
"""Main test function."""
|
|
print("\n" + "="*80)
|
|
print(" VIDEO QUERY APPLICATION - SYSTEM SETUP TEST")
|
|
print("="*80)
|
|
|
|
# Test system info
|
|
test_system_info()
|
|
|
|
# Test executables
|
|
all_found, results = test_executables()
|
|
|
|
# Test error reporting
|
|
test_error_reporting()
|
|
|
|
# Print summary
|
|
exit_code = print_summary(all_found, results)
|
|
|
|
return exit_code
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
exit_code = main()
|
|
sys.exit(exit_code)
|
|
except KeyboardInterrupt:
|
|
print("\n\nTest interrupted by user.")
|
|
sys.exit(1)
|
|
except Exception as e:
|
|
print(f"\n\nFATAL ERROR: {str(e)}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
sys.exit(1)
|