teachingAssistant / test_stt_migration.py
Michael Hu
Migrate existing STT providers to infrastructure layer
1be582a
raw
history blame
3.94 kB
#!/usr/bin/env python3
"""Test script for STT migration."""
import sys
import logging
from pathlib import Path
# Add src to path
sys.path.insert(0, str(Path(__file__).parent / "src"))
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def test_provider_availability():
"""Test that providers can be imported and checked for availability."""
try:
from infrastructure.stt import STTProviderFactory, WhisperSTTProvider, ParakeetSTTProvider
print("βœ“ Successfully imported STT providers")
# Test factory
available_providers = STTProviderFactory.get_available_providers()
print(f"Available providers: {available_providers}")
# Test individual providers
whisper = WhisperSTTProvider()
print(f"Whisper available: {whisper.is_available()}")
print(f"Whisper models: {whisper.get_available_models()}")
print(f"Whisper default model: {whisper.get_default_model()}")
parakeet = ParakeetSTTProvider()
print(f"Parakeet available: {parakeet.is_available()}")
print(f"Parakeet models: {parakeet.get_available_models()}")
print(f"Parakeet default model: {parakeet.get_default_model()}")
return True
except Exception as e:
print(f"βœ— Error testing providers: {e}")
import traceback
traceback.print_exc()
return False
def test_legacy_compatibility():
"""Test legacy compatibility functions."""
try:
from infrastructure.stt import transcribe_audio, ASRFactory
print("βœ“ Successfully imported legacy compatibility functions")
# Test ASRFactory
try:
model = ASRFactory.get_model("whisper")
print(f"βœ“ ASRFactory created model: {model.provider_name}")
except Exception as e:
print(f"ASRFactory test failed (expected if dependencies missing): {e}")
return True
except Exception as e:
print(f"βœ— Error testing legacy compatibility: {e}")
import traceback
traceback.print_exc()
return False
def test_domain_integration():
"""Test integration with domain models."""
try:
from domain.models.audio_content import AudioContent
from domain.models.text_content import TextContent
from domain.exceptions import SpeechRecognitionException
print("βœ“ Successfully imported domain models")
# Create test audio content
test_audio = AudioContent(
data=b"fake audio data for testing",
format="wav",
sample_rate=16000,
duration=1.0,
filename="test.wav"
)
print(f"βœ“ Created test AudioContent: {test_audio.filename}")
return True
except Exception as e:
print(f"βœ— Error testing domain integration: {e}")
import traceback
traceback.print_exc()
return False
if __name__ == "__main__":
print("Testing STT migration...")
print("=" * 50)
tests = [
("Provider Availability", test_provider_availability),
("Legacy Compatibility", test_legacy_compatibility),
("Domain Integration", test_domain_integration)
]
results = []
for test_name, test_func in tests:
print(f"\n{test_name}:")
print("-" * 30)
result = test_func()
results.append((test_name, result))
print("\n" + "=" * 50)
print("Test Results:")
for test_name, result in results:
status = "βœ“ PASS" if result else "βœ— FAIL"
print(f"{test_name}: {status}")
all_passed = all(result for _, result in results)
print(f"\nOverall: {'βœ“ ALL TESTS PASSED' if all_passed else 'βœ— SOME TESTS FAILED'}")
sys.exit(0 if all_passed else 1)