#!/home/dillon/_code/TalkEdit/.venv/bin/python3.10 """ Test script for the TalkEdit API. This script tests the new Tauri commands that expose all backend functions. """ import json import sys import os from pathlib import Path # Add backend to path for direct testing sys.path.insert(0, str(Path(__file__).parent / "backend")) def test_video_info(): """Test get_video_info function""" from services.video_editor import get_video_info # Use a test video file if available test_video = "/path/to/test/video.mp4" # Replace with actual test file if os.path.exists(test_video): try: info = get_video_info(test_video) print("✓ Video info test passed") print(f" Duration: {info['duration']}") print(f" Resolution: {info['width']}x{info['height']}") return True except Exception as e: print(f"✗ Video info test failed: {e}") return False else: print("⚠ Video info test skipped (no test file)") return True def test_caption_generation(): """Test caption generation functions""" from services.caption_generator import generate_srt, generate_vtt # Sample word data words = [ {"word": "Hello", "start": 0.0, "end": 0.5, "confidence": 0.9}, {"word": "world", "start": 0.5, "end": 1.0, "confidence": 0.95}, {"word": "this", "start": 1.0, "end": 1.3, "confidence": 0.8}, {"word": "is", "start": 1.3, "end": 1.5, "confidence": 0.9}, {"word": "a", "start": 1.5, "end": 1.6, "confidence": 0.85}, {"word": "test", "start": 1.6, "end": 2.0, "confidence": 0.95}, ] try: srt_content = generate_srt(words) vtt_content = generate_vtt(words) if "Hello world" in srt_content and "WEBVTT" in vtt_content: print("✓ Caption generation test passed") return True else: print("✗ Caption generation test failed: unexpected content") return False except Exception as e: print(f"✗ Caption generation test failed: {e}") return False def test_ai_provider(): """Test AI provider functions""" from services.ai_provider import AIProvider try: # Test listing Ollama models (may fail if Ollama not running) models = AIProvider.list_ollama_models() print(f"✓ AI provider test passed (found {len(models)} models)") return True except Exception as e: print(f"⚠ AI provider test skipped: {e}") return True def test_deepfilter_status(): """Test DeepFilterNet availability check""" from services.audio_cleaner import is_deepfilter_available try: available = is_deepfilter_available() print(f"✓ DeepFilter status test passed (available: {available})") return True except Exception as e: print(f"✗ DeepFilter status test failed: {e}") return False def main(): print("Testing TalkEdit API functions...") print("=" * 50) tests = [ ("Video Info", test_video_info), ("Caption Generation", test_caption_generation), ("AI Provider", test_ai_provider), ("DeepFilter Status", test_deepfilter_status), ] passed = 0 total = len(tests) for name, test_func in tests: print(f"\nTesting {name}:") if test_func(): passed += 1 print("\n" + "=" * 50) print(f"Results: {passed}/{total} tests passed") if passed == total: print("🎉 All tests passed! The API is ready for AI testing.") else: print("⚠️ Some tests failed. Check the output above.") print("\nAvailable Tauri Commands:") commands = [ "transcribe_audio", "export_stream_copy", "export_reencode", "export_reencode_with_subs", "get_video_info", "clean_audio", "is_deepfilter_available", "diarize_and_label", "ai_complete", "list_ollama_models", "generate_srt", "generate_vtt", "generate_ass", "save_captions", "is_background_removal_available", "remove_background_on_export", ] for cmd in commands: print(f" - {cmd}") if __name__ == "__main__": main()