Spaces:
Sleeping
Sleeping
Michael Hu
commited on
Commit
·
19fd91c
1
Parent(s):
271b76a
Update application entry point and cleanup
Browse files- .vercel/project.json +0 -1
- app.py +0 -1
- test_dependency_injection.py +0 -314
- test_dtos.py +0 -182
- test_stt_migration.py +0 -121
- test_translation_migration.py +0 -156
- test_tts_migration.py +0 -137
.vercel/project.json
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
{"projectName":"trae_5altap2j"}
|
|
|
|
|
|
app.py
CHANGED
|
@@ -16,7 +16,6 @@ logger = logging.getLogger(__name__)
|
|
| 16 |
|
| 17 |
import streamlit as st
|
| 18 |
import os
|
| 19 |
-
import time
|
| 20 |
from typing import Optional
|
| 21 |
|
| 22 |
# Import application services and DTOs
|
|
|
|
| 16 |
|
| 17 |
import streamlit as st
|
| 18 |
import os
|
|
|
|
| 19 |
from typing import Optional
|
| 20 |
|
| 21 |
# Import application services and DTOs
|
test_dependency_injection.py
DELETED
|
@@ -1,314 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Test script for dependency injection and configuration setup."""
|
| 3 |
-
|
| 4 |
-
import sys
|
| 5 |
-
import os
|
| 6 |
-
import logging
|
| 7 |
-
from pathlib import Path
|
| 8 |
-
|
| 9 |
-
# Add src to path for imports
|
| 10 |
-
sys.path.insert(0, str(Path(__file__).parent / "src"))
|
| 11 |
-
|
| 12 |
-
from infrastructure.config.container_setup import (
|
| 13 |
-
create_configured_container,
|
| 14 |
-
get_service_registry_info,
|
| 15 |
-
initialize_global_container,
|
| 16 |
-
get_global_container,
|
| 17 |
-
cleanup_global_container
|
| 18 |
-
)
|
| 19 |
-
from infrastructure.config.app_config import AppConfig
|
| 20 |
-
from infrastructure.config.dependency_container import DependencyContainer
|
| 21 |
-
from application.services.audio_processing_service import AudioProcessingApplicationService
|
| 22 |
-
from application.services.configuration_service import ConfigurationApplicationService
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
def test_configuration_loading():
|
| 26 |
-
"""Test configuration loading from file and environment."""
|
| 27 |
-
print("=" * 60)
|
| 28 |
-
print("Testing Configuration Loading")
|
| 29 |
-
print("=" * 60)
|
| 30 |
-
|
| 31 |
-
try:
|
| 32 |
-
# Test default configuration
|
| 33 |
-
print("\n1. Testing default configuration...")
|
| 34 |
-
config = AppConfig()
|
| 35 |
-
print(f"✓ Default config loaded successfully")
|
| 36 |
-
print(f" - TTS preferred providers: {config.tts.preferred_providers}")
|
| 37 |
-
print(f" - STT default model: {config.stt.default_model}")
|
| 38 |
-
print(f" - Translation provider: {config.translation.default_provider}")
|
| 39 |
-
print(f" - Temp directory: {config.processing.temp_dir}")
|
| 40 |
-
print(f" - Log level: {config.logging.level}")
|
| 41 |
-
|
| 42 |
-
# Test configuration from file
|
| 43 |
-
print("\n2. Testing configuration from file...")
|
| 44 |
-
config_file = "config.example.json"
|
| 45 |
-
if os.path.exists(config_file):
|
| 46 |
-
config_from_file = AppConfig(config_file=config_file)
|
| 47 |
-
print(f"✓ Config loaded from {config_file}")
|
| 48 |
-
print(f" - TTS preferred providers: {config_from_file.tts.preferred_providers}")
|
| 49 |
-
print(f" - Processing timeout: {config_from_file.processing.processing_timeout_seconds}s")
|
| 50 |
-
else:
|
| 51 |
-
print(f"⚠ Config file {config_file} not found, skipping file test")
|
| 52 |
-
|
| 53 |
-
# Test environment variable override
|
| 54 |
-
print("\n3. Testing environment variable override...")
|
| 55 |
-
os.environ['TTS_DEFAULT_SPEED'] = '1.5'
|
| 56 |
-
os.environ['LOG_LEVEL'] = 'DEBUG'
|
| 57 |
-
|
| 58 |
-
config_with_env = AppConfig()
|
| 59 |
-
print(f"✓ Config with environment overrides loaded")
|
| 60 |
-
print(f" - TTS default speed: {config_with_env.tts.default_speed}")
|
| 61 |
-
print(f" - Log level: {config_with_env.logging.level}")
|
| 62 |
-
|
| 63 |
-
# Clean up environment
|
| 64 |
-
del os.environ['TTS_DEFAULT_SPEED']
|
| 65 |
-
del os.environ['LOG_LEVEL']
|
| 66 |
-
|
| 67 |
-
return True
|
| 68 |
-
|
| 69 |
-
except Exception as e:
|
| 70 |
-
print(f"✗ Configuration loading failed: {e}")
|
| 71 |
-
return False
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
def test_dependency_container():
|
| 75 |
-
"""Test dependency container setup and service resolution."""
|
| 76 |
-
print("\n" + "=" * 60)
|
| 77 |
-
print("Testing Dependency Container")
|
| 78 |
-
print("=" * 60)
|
| 79 |
-
|
| 80 |
-
try:
|
| 81 |
-
# Test container creation
|
| 82 |
-
print("\n1. Testing container creation...")
|
| 83 |
-
container = create_configured_container()
|
| 84 |
-
print("✓ Container created successfully")
|
| 85 |
-
|
| 86 |
-
# Test service registration info
|
| 87 |
-
print("\n2. Testing service registry...")
|
| 88 |
-
registry_info = get_service_registry_info(container)
|
| 89 |
-
print("✓ Service registry information retrieved")
|
| 90 |
-
print(f" - Registered services: {len(registry_info['registered_services'])}")
|
| 91 |
-
|
| 92 |
-
for service_name, lifetime in registry_info['registered_services'].items():
|
| 93 |
-
print(f" • {service_name}: {lifetime}")
|
| 94 |
-
|
| 95 |
-
# Test provider availability
|
| 96 |
-
print("\n3. Testing provider availability...")
|
| 97 |
-
provider_info = registry_info['provider_availability']
|
| 98 |
-
print(f" - Available TTS providers: {provider_info['tts_providers']}")
|
| 99 |
-
print(f" - Available STT providers: {provider_info['stt_providers']}")
|
| 100 |
-
print(f" - Available translation providers: {provider_info['translation_providers']}")
|
| 101 |
-
|
| 102 |
-
# Test service resolution
|
| 103 |
-
print("\n4. Testing service resolution...")
|
| 104 |
-
|
| 105 |
-
# Resolve configuration
|
| 106 |
-
config = container.resolve(AppConfig)
|
| 107 |
-
print("✓ AppConfig resolved successfully")
|
| 108 |
-
|
| 109 |
-
# Resolve application services
|
| 110 |
-
audio_service = container.resolve(AudioProcessingApplicationService)
|
| 111 |
-
print("✓ AudioProcessingApplicationService resolved successfully")
|
| 112 |
-
|
| 113 |
-
config_service = container.resolve(ConfigurationApplicationService)
|
| 114 |
-
print("✓ ConfigurationApplicationService resolved successfully")
|
| 115 |
-
|
| 116 |
-
# Test provider services
|
| 117 |
-
tts_provider = container.get_tts_provider()
|
| 118 |
-
print(f"✓ TTS provider resolved: {tts_provider.__class__.__name__}")
|
| 119 |
-
|
| 120 |
-
stt_provider = container.get_stt_provider()
|
| 121 |
-
print(f"✓ STT provider resolved: {stt_provider.__class__.__name__}")
|
| 122 |
-
|
| 123 |
-
translation_provider = container.get_translation_provider()
|
| 124 |
-
print(f"✓ Translation provider resolved: {translation_provider.__class__.__name__}")
|
| 125 |
-
|
| 126 |
-
# Test scoped services
|
| 127 |
-
print("\n5. Testing scoped services...")
|
| 128 |
-
with container.create_scope() as scope:
|
| 129 |
-
scoped_audio_service = scope.resolve(AudioProcessingApplicationService)
|
| 130 |
-
print("✓ Scoped AudioProcessingApplicationService resolved")
|
| 131 |
-
|
| 132 |
-
# Cleanup
|
| 133 |
-
container.cleanup()
|
| 134 |
-
print("✓ Container cleanup completed")
|
| 135 |
-
|
| 136 |
-
return True
|
| 137 |
-
|
| 138 |
-
except Exception as e:
|
| 139 |
-
print(f"✗ Dependency container test failed: {e}")
|
| 140 |
-
import traceback
|
| 141 |
-
traceback.print_exc()
|
| 142 |
-
return False
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
def test_global_container():
|
| 146 |
-
"""Test global container management."""
|
| 147 |
-
print("\n" + "=" * 60)
|
| 148 |
-
print("Testing Global Container Management")
|
| 149 |
-
print("=" * 60)
|
| 150 |
-
|
| 151 |
-
try:
|
| 152 |
-
# Test global container initialization
|
| 153 |
-
print("\n1. Testing global container initialization...")
|
| 154 |
-
global_container = initialize_global_container()
|
| 155 |
-
print("✓ Global container initialized")
|
| 156 |
-
|
| 157 |
-
# Test global container access
|
| 158 |
-
print("\n2. Testing global container access...")
|
| 159 |
-
retrieved_container = get_global_container()
|
| 160 |
-
print("✓ Global container retrieved")
|
| 161 |
-
|
| 162 |
-
assert global_container is retrieved_container, "Global container instances should be the same"
|
| 163 |
-
print("✓ Global container instance consistency verified")
|
| 164 |
-
|
| 165 |
-
# Test service resolution through global container
|
| 166 |
-
print("\n3. Testing service resolution through global container...")
|
| 167 |
-
config = retrieved_container.resolve(AppConfig)
|
| 168 |
-
print("✓ Configuration resolved through global container")
|
| 169 |
-
|
| 170 |
-
# Test global container cleanup
|
| 171 |
-
print("\n4. Testing global container cleanup...")
|
| 172 |
-
cleanup_global_container()
|
| 173 |
-
print("✓ Global container cleaned up")
|
| 174 |
-
|
| 175 |
-
return True
|
| 176 |
-
|
| 177 |
-
except Exception as e:
|
| 178 |
-
print(f"✗ Global container test failed: {e}")
|
| 179 |
-
return False
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
def test_configuration_service():
|
| 183 |
-
"""Test configuration application service."""
|
| 184 |
-
print("\n" + "=" * 60)
|
| 185 |
-
print("Testing Configuration Application Service")
|
| 186 |
-
print("=" * 60)
|
| 187 |
-
|
| 188 |
-
try:
|
| 189 |
-
# Create container
|
| 190 |
-
container = create_configured_container()
|
| 191 |
-
|
| 192 |
-
# Get configuration service
|
| 193 |
-
print("\n1. Testing configuration service resolution...")
|
| 194 |
-
config_service = container.resolve(ConfigurationApplicationService)
|
| 195 |
-
print("✓ Configuration service resolved")
|
| 196 |
-
|
| 197 |
-
# Test getting current configuration
|
| 198 |
-
print("\n2. Testing configuration retrieval...")
|
| 199 |
-
current_config = config_service.get_current_configuration()
|
| 200 |
-
print("✓ Current configuration retrieved")
|
| 201 |
-
print(f" - Configuration sections: {list(current_config.keys())}")
|
| 202 |
-
|
| 203 |
-
# Test TTS configuration
|
| 204 |
-
print("\n3. Testing TTS configuration...")
|
| 205 |
-
tts_config = config_service.get_tts_configuration()
|
| 206 |
-
print(f"✓ TTS configuration: {len(tts_config)} settings")
|
| 207 |
-
|
| 208 |
-
# Test configuration updates
|
| 209 |
-
print("\n4. Testing configuration updates...")
|
| 210 |
-
updated_tts = config_service.update_tts_configuration({
|
| 211 |
-
'default_speed': 1.2,
|
| 212 |
-
'enable_streaming': False
|
| 213 |
-
})
|
| 214 |
-
print("✓ TTS configuration updated")
|
| 215 |
-
print(f" - New default speed: {updated_tts['default_speed']}")
|
| 216 |
-
print(f" - Streaming enabled: {updated_tts['enable_streaming']}")
|
| 217 |
-
|
| 218 |
-
# Test provider availability
|
| 219 |
-
print("\n5. Testing provider availability check...")
|
| 220 |
-
availability = config_service.get_provider_availability()
|
| 221 |
-
print("✓ Provider availability checked")
|
| 222 |
-
for category, providers in availability.items():
|
| 223 |
-
print(f" - {category.upper()}: {providers}")
|
| 224 |
-
|
| 225 |
-
# Test system info
|
| 226 |
-
print("\n6. Testing system information...")
|
| 227 |
-
system_info = config_service.get_system_info()
|
| 228 |
-
print("✓ System information retrieved")
|
| 229 |
-
print(f" - Supported languages: {len(system_info['supported_languages'])}")
|
| 230 |
-
print(f" - Supported audio formats: {system_info['supported_audio_formats']}")
|
| 231 |
-
|
| 232 |
-
# Test configuration validation
|
| 233 |
-
print("\n7. Testing configuration validation...")
|
| 234 |
-
validation_issues = config_service.validate_configuration()
|
| 235 |
-
print("✓ Configuration validation completed")
|
| 236 |
-
|
| 237 |
-
total_issues = sum(len(issues) for issues in validation_issues.values())
|
| 238 |
-
if total_issues == 0:
|
| 239 |
-
print(" - No validation issues found")
|
| 240 |
-
else:
|
| 241 |
-
print(f" - Found {total_issues} validation issues")
|
| 242 |
-
for category, issues in validation_issues.items():
|
| 243 |
-
if issues:
|
| 244 |
-
print(f" • {category}: {issues}")
|
| 245 |
-
|
| 246 |
-
# Cleanup
|
| 247 |
-
container.cleanup()
|
| 248 |
-
|
| 249 |
-
return True
|
| 250 |
-
|
| 251 |
-
except Exception as e:
|
| 252 |
-
print(f"✗ Configuration service test failed: {e}")
|
| 253 |
-
import traceback
|
| 254 |
-
traceback.print_exc()
|
| 255 |
-
return False
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
def main():
|
| 259 |
-
"""Run all tests."""
|
| 260 |
-
print("Dependency Injection and Configuration Test Suite")
|
| 261 |
-
print("=" * 60)
|
| 262 |
-
|
| 263 |
-
# Configure basic logging
|
| 264 |
-
logging.basicConfig(
|
| 265 |
-
level=logging.WARNING, # Reduce noise during testing
|
| 266 |
-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
| 267 |
-
)
|
| 268 |
-
|
| 269 |
-
tests = [
|
| 270 |
-
("Configuration Loading", test_configuration_loading),
|
| 271 |
-
("Dependency Container", test_dependency_container),
|
| 272 |
-
("Global Container Management", test_global_container),
|
| 273 |
-
("Configuration Service", test_configuration_service)
|
| 274 |
-
]
|
| 275 |
-
|
| 276 |
-
results = []
|
| 277 |
-
|
| 278 |
-
for test_name, test_func in tests:
|
| 279 |
-
try:
|
| 280 |
-
result = test_func()
|
| 281 |
-
results.append((test_name, result))
|
| 282 |
-
except Exception as e:
|
| 283 |
-
print(f"\n✗ {test_name} failed with exception: {e}")
|
| 284 |
-
results.append((test_name, False))
|
| 285 |
-
|
| 286 |
-
# Print summary
|
| 287 |
-
print("\n" + "=" * 60)
|
| 288 |
-
print("Test Results Summary")
|
| 289 |
-
print("=" * 60)
|
| 290 |
-
|
| 291 |
-
passed = 0
|
| 292 |
-
failed = 0
|
| 293 |
-
|
| 294 |
-
for test_name, result in results:
|
| 295 |
-
status = "✓ PASSED" if result else "✗ FAILED"
|
| 296 |
-
print(f"{test_name:<30} {status}")
|
| 297 |
-
|
| 298 |
-
if result:
|
| 299 |
-
passed += 1
|
| 300 |
-
else:
|
| 301 |
-
failed += 1
|
| 302 |
-
|
| 303 |
-
print(f"\nTotal: {len(results)} tests, {passed} passed, {failed} failed")
|
| 304 |
-
|
| 305 |
-
if failed == 0:
|
| 306 |
-
print("\n🎉 All tests passed!")
|
| 307 |
-
return 0
|
| 308 |
-
else:
|
| 309 |
-
print(f"\n❌ {failed} test(s) failed!")
|
| 310 |
-
return 1
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
if __name__ == "__main__":
|
| 314 |
-
sys.exit(main())
|
|
|
|
|
|
|
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| 8 |
-
from application.dtos import AudioUploadDto, ProcessingRequestDto, ProcessingResultDto, ValidationError
|
| 9 |
-
|
| 10 |
-
def test_audio_upload_dto():
|
| 11 |
-
"""Test AudioUploadDto"""
|
| 12 |
-
print("Testing AudioUploadDto...")
|
| 13 |
-
|
| 14 |
-
# Test valid DTO
|
| 15 |
-
try:
|
| 16 |
-
audio_dto = AudioUploadDto(
|
| 17 |
-
filename="test.wav",
|
| 18 |
-
content=b"fake audio content" * 100, # Make it larger than 1KB
|
| 19 |
-
content_type="audio/wav"
|
| 20 |
-
)
|
| 21 |
-
print(f"✓ Valid AudioUploadDto created: {audio_dto.filename}")
|
| 22 |
-
print(f" Size: {audio_dto.size} bytes")
|
| 23 |
-
print(f" Extension: {audio_dto.file_extension}")
|
| 24 |
-
print(f" Base filename: {audio_dto.base_filename}")
|
| 25 |
-
except Exception as e:
|
| 26 |
-
print(f"✗ Failed to create valid AudioUploadDto: {e}")
|
| 27 |
-
|
| 28 |
-
# Test invalid extension
|
| 29 |
-
try:
|
| 30 |
-
AudioUploadDto(
|
| 31 |
-
filename="test.txt",
|
| 32 |
-
content=b"fake content" * 100,
|
| 33 |
-
content_type="text/plain"
|
| 34 |
-
)
|
| 35 |
-
print("✗ Should have failed with invalid extension")
|
| 36 |
-
except ValueError as e:
|
| 37 |
-
print(f"✓ Correctly rejected invalid extension: {e}")
|
| 38 |
-
|
| 39 |
-
# Test empty content
|
| 40 |
-
try:
|
| 41 |
-
AudioUploadDto(
|
| 42 |
-
filename="test.wav",
|
| 43 |
-
content=b"",
|
| 44 |
-
content_type="audio/wav"
|
| 45 |
-
)
|
| 46 |
-
print("✗ Should have failed with empty content")
|
| 47 |
-
except ValueError as e:
|
| 48 |
-
print(f"✓ Correctly rejected empty content: {e}")
|
| 49 |
-
|
| 50 |
-
def test_processing_request_dto():
|
| 51 |
-
"""Test ProcessingRequestDto"""
|
| 52 |
-
print("\nTesting ProcessingRequestDto...")
|
| 53 |
-
|
| 54 |
-
# Create valid audio DTO first
|
| 55 |
-
audio_dto = AudioUploadDto(
|
| 56 |
-
filename="test.wav",
|
| 57 |
-
content=b"fake audio content" * 100,
|
| 58 |
-
content_type="audio/wav"
|
| 59 |
-
)
|
| 60 |
-
|
| 61 |
-
# Test valid DTO
|
| 62 |
-
try:
|
| 63 |
-
request_dto = ProcessingRequestDto(
|
| 64 |
-
audio=audio_dto,
|
| 65 |
-
asr_model="whisper-small",
|
| 66 |
-
target_language="es",
|
| 67 |
-
voice="kokoro",
|
| 68 |
-
speed=1.2,
|
| 69 |
-
source_language="en"
|
| 70 |
-
)
|
| 71 |
-
print(f"✓ Valid ProcessingRequestDto created")
|
| 72 |
-
print(f" ASR Model: {request_dto.asr_model}")
|
| 73 |
-
print(f" Target Language: {request_dto.target_language}")
|
| 74 |
-
print(f" Requires Translation: {request_dto.requires_translation}")
|
| 75 |
-
print(f" Dict representation keys: {list(request_dto.to_dict().keys())}")
|
| 76 |
-
except Exception as e:
|
| 77 |
-
print(f"✗ Failed to create valid ProcessingRequestDto: {e}")
|
| 78 |
-
|
| 79 |
-
# Test invalid speed
|
| 80 |
-
try:
|
| 81 |
-
ProcessingRequestDto(
|
| 82 |
-
audio=audio_dto,
|
| 83 |
-
asr_model="whisper-small",
|
| 84 |
-
target_language="es",
|
| 85 |
-
voice="kokoro",
|
| 86 |
-
speed=3.0 # Invalid speed
|
| 87 |
-
)
|
| 88 |
-
print("✗ Should have failed with invalid speed")
|
| 89 |
-
except ValueError as e:
|
| 90 |
-
print(f"✓ Correctly rejected invalid speed: {e}")
|
| 91 |
-
|
| 92 |
-
# Test invalid ASR model
|
| 93 |
-
try:
|
| 94 |
-
ProcessingRequestDto(
|
| 95 |
-
audio=audio_dto,
|
| 96 |
-
asr_model="invalid-model",
|
| 97 |
-
target_language="es",
|
| 98 |
-
voice="kokoro"
|
| 99 |
-
)
|
| 100 |
-
print("✗ Should have failed with invalid ASR model")
|
| 101 |
-
except ValueError as e:
|
| 102 |
-
print(f"✓ Correctly rejected invalid ASR model: {e}")
|
| 103 |
-
|
| 104 |
-
def test_processing_result_dto():
|
| 105 |
-
"""Test ProcessingResultDto"""
|
| 106 |
-
print("\nTesting ProcessingResultDto...")
|
| 107 |
-
|
| 108 |
-
# Test successful result
|
| 109 |
-
try:
|
| 110 |
-
success_result = ProcessingResultDto.success_result(
|
| 111 |
-
original_text="Hello world",
|
| 112 |
-
translated_text="Hola mundo",
|
| 113 |
-
audio_path="/tmp/output.wav",
|
| 114 |
-
processing_time=2.5
|
| 115 |
-
)
|
| 116 |
-
print(f"✓ Valid success result created")
|
| 117 |
-
print(f" Success: {success_result.success}")
|
| 118 |
-
print(f" Has text output: {success_result.has_text_output}")
|
| 119 |
-
print(f" Has audio output: {success_result.has_audio_output}")
|
| 120 |
-
print(f" Is complete: {success_result.is_complete}")
|
| 121 |
-
except Exception as e:
|
| 122 |
-
print(f"✗ Failed to create success result: {e}")
|
| 123 |
-
|
| 124 |
-
# Test error result
|
| 125 |
-
try:
|
| 126 |
-
error_result = ProcessingResultDto.error_result(
|
| 127 |
-
error_message="TTS generation failed",
|
| 128 |
-
error_code="TTS_ERROR",
|
| 129 |
-
processing_time=1.0
|
| 130 |
-
)
|
| 131 |
-
print(f"✓ Valid error result created")
|
| 132 |
-
print(f" Success: {error_result.success}")
|
| 133 |
-
print(f" Error message: {error_result.error_message}")
|
| 134 |
-
print(f" Error code: {error_result.error_code}")
|
| 135 |
-
except Exception as e:
|
| 136 |
-
print(f"✗ Failed to create error result: {e}")
|
| 137 |
-
|
| 138 |
-
# Test invalid success result (no outputs)
|
| 139 |
-
try:
|
| 140 |
-
ProcessingResultDto(success=True) # No outputs provided
|
| 141 |
-
print("✗ Should have failed with no outputs for success")
|
| 142 |
-
except ValueError as e:
|
| 143 |
-
print(f"✓ Correctly rejected success result with no outputs: {e}")
|
| 144 |
-
|
| 145 |
-
# Test invalid error result (no error message)
|
| 146 |
-
try:
|
| 147 |
-
ProcessingResultDto(success=False) # No error message
|
| 148 |
-
print("✗ Should have failed with no error message for failure")
|
| 149 |
-
except ValueError as e:
|
| 150 |
-
print(f"✓ Correctly rejected error result with no message: {e}")
|
| 151 |
-
|
| 152 |
-
def test_dto_serialization():
|
| 153 |
-
"""Test DTO serialization/deserialization"""
|
| 154 |
-
print("\nTesting DTO serialization...")
|
| 155 |
-
|
| 156 |
-
# Test ProcessingResultDto serialization
|
| 157 |
-
try:
|
| 158 |
-
original_result = ProcessingResultDto.success_result(
|
| 159 |
-
original_text="Test text",
|
| 160 |
-
translated_text="Texto de prueba",
|
| 161 |
-
audio_path="/tmp/test.wav",
|
| 162 |
-
processing_time=1.5
|
| 163 |
-
)
|
| 164 |
-
|
| 165 |
-
# Convert to dict and back
|
| 166 |
-
result_dict = original_result.to_dict()
|
| 167 |
-
restored_result = ProcessingResultDto.from_dict(result_dict)
|
| 168 |
-
|
| 169 |
-
print(f"✓ ProcessingResultDto serialization successful")
|
| 170 |
-
print(f" Original success: {original_result.success}")
|
| 171 |
-
print(f" Restored success: {restored_result.success}")
|
| 172 |
-
print(f" Original text matches: {original_result.original_text == restored_result.original_text}")
|
| 173 |
-
|
| 174 |
-
except Exception as e:
|
| 175 |
-
print(f"✗ ProcessingResultDto serialization failed: {e}")
|
| 176 |
-
|
| 177 |
-
if __name__ == "__main__":
|
| 178 |
-
test_audio_upload_dto()
|
| 179 |
-
test_processing_request_dto()
|
| 180 |
-
test_processing_result_dto()
|
| 181 |
-
test_dto_serialization()
|
| 182 |
-
print("\nDTO testing completed!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test_stt_migration.py
DELETED
|
@@ -1,121 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Test script for STT migration."""
|
| 3 |
-
|
| 4 |
-
import sys
|
| 5 |
-
import logging
|
| 6 |
-
from pathlib import Path
|
| 7 |
-
|
| 8 |
-
# Add src to path
|
| 9 |
-
sys.path.insert(0, str(Path(__file__).parent / "src"))
|
| 10 |
-
|
| 11 |
-
# Configure logging
|
| 12 |
-
logging.basicConfig(level=logging.INFO)
|
| 13 |
-
logger = logging.getLogger(__name__)
|
| 14 |
-
|
| 15 |
-
def test_provider_availability():
|
| 16 |
-
"""Test that providers can be imported and checked for availability."""
|
| 17 |
-
try:
|
| 18 |
-
from infrastructure.stt import STTProviderFactory, WhisperSTTProvider, ParakeetSTTProvider
|
| 19 |
-
|
| 20 |
-
print("✓ Successfully imported STT providers")
|
| 21 |
-
|
| 22 |
-
# Test factory
|
| 23 |
-
available_providers = STTProviderFactory.get_available_providers()
|
| 24 |
-
print(f"Available providers: {available_providers}")
|
| 25 |
-
|
| 26 |
-
# Test individual providers
|
| 27 |
-
whisper = WhisperSTTProvider()
|
| 28 |
-
print(f"Whisper available: {whisper.is_available()}")
|
| 29 |
-
print(f"Whisper models: {whisper.get_available_models()}")
|
| 30 |
-
print(f"Whisper default model: {whisper.get_default_model()}")
|
| 31 |
-
|
| 32 |
-
parakeet = ParakeetSTTProvider()
|
| 33 |
-
print(f"Parakeet available: {parakeet.is_available()}")
|
| 34 |
-
print(f"Parakeet models: {parakeet.get_available_models()}")
|
| 35 |
-
print(f"Parakeet default model: {parakeet.get_default_model()}")
|
| 36 |
-
|
| 37 |
-
return True
|
| 38 |
-
|
| 39 |
-
except Exception as e:
|
| 40 |
-
print(f"✗ Error testing providers: {e}")
|
| 41 |
-
import traceback
|
| 42 |
-
traceback.print_exc()
|
| 43 |
-
return False
|
| 44 |
-
|
| 45 |
-
def test_legacy_compatibility():
|
| 46 |
-
"""Test legacy compatibility functions."""
|
| 47 |
-
try:
|
| 48 |
-
from infrastructure.stt import transcribe_audio, ASRFactory
|
| 49 |
-
|
| 50 |
-
print("✓ Successfully imported legacy compatibility functions")
|
| 51 |
-
|
| 52 |
-
# Test ASRFactory
|
| 53 |
-
try:
|
| 54 |
-
model = ASRFactory.get_model("whisper")
|
| 55 |
-
print(f"✓ ASRFactory created model: {model.provider_name}")
|
| 56 |
-
except Exception as e:
|
| 57 |
-
print(f"ASRFactory test failed (expected if dependencies missing): {e}")
|
| 58 |
-
|
| 59 |
-
return True
|
| 60 |
-
|
| 61 |
-
except Exception as e:
|
| 62 |
-
print(f"✗ Error testing legacy compatibility: {e}")
|
| 63 |
-
import traceback
|
| 64 |
-
traceback.print_exc()
|
| 65 |
-
return False
|
| 66 |
-
|
| 67 |
-
def test_domain_integration():
|
| 68 |
-
"""Test integration with domain models."""
|
| 69 |
-
try:
|
| 70 |
-
from domain.models.audio_content import AudioContent
|
| 71 |
-
from domain.models.text_content import TextContent
|
| 72 |
-
from domain.exceptions import SpeechRecognitionException
|
| 73 |
-
|
| 74 |
-
print("✓ Successfully imported domain models")
|
| 75 |
-
|
| 76 |
-
# Create test audio content
|
| 77 |
-
test_audio = AudioContent(
|
| 78 |
-
data=b"fake audio data for testing",
|
| 79 |
-
format="wav",
|
| 80 |
-
sample_rate=16000,
|
| 81 |
-
duration=1.0,
|
| 82 |
-
filename="test.wav"
|
| 83 |
-
)
|
| 84 |
-
|
| 85 |
-
print(f"✓ Created test AudioContent: {test_audio.filename}")
|
| 86 |
-
|
| 87 |
-
return True
|
| 88 |
-
|
| 89 |
-
except Exception as e:
|
| 90 |
-
print(f"✗ Error testing domain integration: {e}")
|
| 91 |
-
import traceback
|
| 92 |
-
traceback.print_exc()
|
| 93 |
-
return False
|
| 94 |
-
|
| 95 |
-
if __name__ == "__main__":
|
| 96 |
-
print("Testing STT migration...")
|
| 97 |
-
print("=" * 50)
|
| 98 |
-
|
| 99 |
-
tests = [
|
| 100 |
-
("Provider Availability", test_provider_availability),
|
| 101 |
-
("Legacy Compatibility", test_legacy_compatibility),
|
| 102 |
-
("Domain Integration", test_domain_integration)
|
| 103 |
-
]
|
| 104 |
-
|
| 105 |
-
results = []
|
| 106 |
-
for test_name, test_func in tests:
|
| 107 |
-
print(f"\n{test_name}:")
|
| 108 |
-
print("-" * 30)
|
| 109 |
-
result = test_func()
|
| 110 |
-
results.append((test_name, result))
|
| 111 |
-
|
| 112 |
-
print("\n" + "=" * 50)
|
| 113 |
-
print("Test Results:")
|
| 114 |
-
for test_name, result in results:
|
| 115 |
-
status = "✓ PASS" if result else "✗ FAIL"
|
| 116 |
-
print(f"{test_name}: {status}")
|
| 117 |
-
|
| 118 |
-
all_passed = all(result for _, result in results)
|
| 119 |
-
print(f"\nOverall: {'✓ ALL TESTS PASSED' if all_passed else '✗ SOME TESTS FAILED'}")
|
| 120 |
-
|
| 121 |
-
sys.exit(0 if all_passed else 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test_translation_migration.py
DELETED
|
@@ -1,156 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Test script to verify the translation service migration."""
|
| 3 |
-
|
| 4 |
-
import sys
|
| 5 |
-
import os
|
| 6 |
-
|
| 7 |
-
# Add src to path
|
| 8 |
-
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
|
| 9 |
-
|
| 10 |
-
def test_translation_provider_creation():
|
| 11 |
-
"""Test that we can create translation providers."""
|
| 12 |
-
print("Testing translation provider creation...")
|
| 13 |
-
|
| 14 |
-
try:
|
| 15 |
-
from infrastructure.translation.provider_factory import (
|
| 16 |
-
TranslationProviderFactory,
|
| 17 |
-
TranslationProviderType
|
| 18 |
-
)
|
| 19 |
-
|
| 20 |
-
factory = TranslationProviderFactory()
|
| 21 |
-
|
| 22 |
-
# Test getting available providers
|
| 23 |
-
available = factory.get_available_providers()
|
| 24 |
-
print(f"Available providers: {[p.value for p in available]}")
|
| 25 |
-
|
| 26 |
-
# Test provider info
|
| 27 |
-
all_info = factory.get_all_providers_info()
|
| 28 |
-
print(f"Provider info: {all_info}")
|
| 29 |
-
|
| 30 |
-
# Test creating NLLB provider (may fail if transformers not installed)
|
| 31 |
-
try:
|
| 32 |
-
provider = factory.create_provider(TranslationProviderType.NLLB)
|
| 33 |
-
print(f"Created provider: {provider.provider_name}")
|
| 34 |
-
print(f"Provider available: {provider.is_available()}")
|
| 35 |
-
|
| 36 |
-
# Test supported languages
|
| 37 |
-
supported = provider.get_supported_languages()
|
| 38 |
-
print(f"Supported language pairs: {len(supported)} source languages")
|
| 39 |
-
|
| 40 |
-
if 'en' in supported:
|
| 41 |
-
print(f"English can translate to: {len(supported['en'])} languages")
|
| 42 |
-
|
| 43 |
-
except Exception as e:
|
| 44 |
-
print(f"Could not create NLLB provider (expected if transformers not installed): {e}")
|
| 45 |
-
|
| 46 |
-
print("✓ Translation provider creation test passed")
|
| 47 |
-
return True
|
| 48 |
-
|
| 49 |
-
except Exception as e:
|
| 50 |
-
print(f"✗ Translation provider creation test failed: {e}")
|
| 51 |
-
return False
|
| 52 |
-
|
| 53 |
-
def test_domain_models():
|
| 54 |
-
"""Test that domain models work correctly."""
|
| 55 |
-
print("\nTesting domain models...")
|
| 56 |
-
|
| 57 |
-
try:
|
| 58 |
-
from domain.models.text_content import TextContent
|
| 59 |
-
from domain.models.translation_request import TranslationRequest
|
| 60 |
-
|
| 61 |
-
# Test TextContent creation
|
| 62 |
-
text_content = TextContent(
|
| 63 |
-
text="Hello, world!",
|
| 64 |
-
language="en",
|
| 65 |
-
encoding="utf-8"
|
| 66 |
-
)
|
| 67 |
-
print(f"Created TextContent: {text_content.text} ({text_content.language})")
|
| 68 |
-
|
| 69 |
-
# Test TranslationRequest creation
|
| 70 |
-
translation_request = TranslationRequest(
|
| 71 |
-
source_text=text_content,
|
| 72 |
-
target_language="zh"
|
| 73 |
-
)
|
| 74 |
-
print(f"Created TranslationRequest: {translation_request.effective_source_language} -> {translation_request.target_language}")
|
| 75 |
-
|
| 76 |
-
print("✓ Domain models test passed")
|
| 77 |
-
return True
|
| 78 |
-
|
| 79 |
-
except Exception as e:
|
| 80 |
-
print(f"✗ Domain models test failed: {e}")
|
| 81 |
-
return False
|
| 82 |
-
|
| 83 |
-
def test_base_class_functionality():
|
| 84 |
-
"""Test the base class functionality."""
|
| 85 |
-
print("\nTesting base class functionality...")
|
| 86 |
-
|
| 87 |
-
try:
|
| 88 |
-
from infrastructure.base.translation_provider_base import TranslationProviderBase
|
| 89 |
-
from domain.models.text_content import TextContent
|
| 90 |
-
from domain.models.translation_request import TranslationRequest
|
| 91 |
-
|
| 92 |
-
# Create a mock provider for testing
|
| 93 |
-
class MockTranslationProvider(TranslationProviderBase):
|
| 94 |
-
def __init__(self):
|
| 95 |
-
super().__init__("MockProvider", {"en": ["zh", "es", "fr"]})
|
| 96 |
-
|
| 97 |
-
def _translate_chunk(self, text: str, source_language: str, target_language: str) -> str:
|
| 98 |
-
return f"[TRANSLATED:{source_language}->{target_language}]{text}"
|
| 99 |
-
|
| 100 |
-
def is_available(self) -> bool:
|
| 101 |
-
return True
|
| 102 |
-
|
| 103 |
-
def get_supported_languages(self) -> dict:
|
| 104 |
-
return self.supported_languages
|
| 105 |
-
|
| 106 |
-
# Test the mock provider
|
| 107 |
-
provider = MockTranslationProvider()
|
| 108 |
-
|
| 109 |
-
# Test text chunking
|
| 110 |
-
long_text = "This is a test sentence. " * 50 # Create long text
|
| 111 |
-
chunks = provider._chunk_text(long_text)
|
| 112 |
-
print(f"Text chunked into {len(chunks)} pieces")
|
| 113 |
-
|
| 114 |
-
# Test translation request
|
| 115 |
-
text_content = TextContent(text="Hello world", language="en")
|
| 116 |
-
request = TranslationRequest(source_text=text_content, target_language="zh")
|
| 117 |
-
|
| 118 |
-
result = provider.translate(request)
|
| 119 |
-
print(f"Translation result: {result.text}")
|
| 120 |
-
|
| 121 |
-
print("✓ Base class functionality test passed")
|
| 122 |
-
return True
|
| 123 |
-
|
| 124 |
-
except Exception as e:
|
| 125 |
-
print(f"✗ Base class functionality test failed: {e}")
|
| 126 |
-
return False
|
| 127 |
-
|
| 128 |
-
def main():
|
| 129 |
-
"""Run all tests."""
|
| 130 |
-
print("Running translation service migration tests...\n")
|
| 131 |
-
|
| 132 |
-
tests = [
|
| 133 |
-
test_domain_models,
|
| 134 |
-
test_translation_provider_creation,
|
| 135 |
-
test_base_class_functionality
|
| 136 |
-
]
|
| 137 |
-
|
| 138 |
-
passed = 0
|
| 139 |
-
total = len(tests)
|
| 140 |
-
|
| 141 |
-
for test in tests:
|
| 142 |
-
if test():
|
| 143 |
-
passed += 1
|
| 144 |
-
|
| 145 |
-
print(f"\n{'='*50}")
|
| 146 |
-
print(f"Test Results: {passed}/{total} tests passed")
|
| 147 |
-
|
| 148 |
-
if passed == total:
|
| 149 |
-
print("🎉 All tests passed! Translation service migration is working correctly.")
|
| 150 |
-
return 0
|
| 151 |
-
else:
|
| 152 |
-
print("❌ Some tests failed. Please check the implementation.")
|
| 153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,137 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Test script to verify TTS provider migration."""
|
| 3 |
-
|
| 4 |
-
import sys
|
| 5 |
-
import os
|
| 6 |
-
|
| 7 |
-
# Add src to path
|
| 8 |
-
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
|
| 9 |
-
|
| 10 |
-
def test_provider_imports():
|
| 11 |
-
"""Test that all providers can be imported."""
|
| 12 |
-
print("Testing provider imports...")
|
| 13 |
-
|
| 14 |
-
try:
|
| 15 |
-
from src.infrastructure.tts import TTSProviderFactory, DummyTTSProvider
|
| 16 |
-
print("✓ Core TTS components imported successfully")
|
| 17 |
-
except Exception as e:
|
| 18 |
-
print(f"✗ Failed to import core TTS components: {e}")
|
| 19 |
-
return False
|
| 20 |
-
|
| 21 |
-
try:
|
| 22 |
-
from src.domain.models.text_content import TextContent
|
| 23 |
-
from src.domain.models.voice_settings import VoiceSettings
|
| 24 |
-
from src.domain.models.speech_synthesis_request import SpeechSynthesisRequest
|
| 25 |
-
print("✓ Domain models imported successfully")
|
| 26 |
-
except Exception as e:
|
| 27 |
-
print(f"✗ Failed to import domain models: {e}")
|
| 28 |
-
return False
|
| 29 |
-
|
| 30 |
-
return True
|
| 31 |
-
|
| 32 |
-
def test_dummy_provider():
|
| 33 |
-
"""Test the dummy provider functionality."""
|
| 34 |
-
print("\nTesting dummy provider...")
|
| 35 |
-
|
| 36 |
-
try:
|
| 37 |
-
from src.infrastructure.tts import DummyTTSProvider
|
| 38 |
-
from src.domain.models.text_content import TextContent
|
| 39 |
-
from src.domain.models.voice_settings import VoiceSettings
|
| 40 |
-
from src.domain.models.speech_synthesis_request import SpeechSynthesisRequest
|
| 41 |
-
|
| 42 |
-
# Create provider
|
| 43 |
-
provider = DummyTTSProvider()
|
| 44 |
-
print(f"✓ Created dummy provider: {provider.provider_name}")
|
| 45 |
-
|
| 46 |
-
# Check availability
|
| 47 |
-
if provider.is_available():
|
| 48 |
-
print("✓ Dummy provider is available")
|
| 49 |
-
else:
|
| 50 |
-
print("✗ Dummy provider is not available")
|
| 51 |
-
return False
|
| 52 |
-
|
| 53 |
-
# Check voices
|
| 54 |
-
voices = provider.get_available_voices()
|
| 55 |
-
print(f"✓ Available voices: {voices}")
|
| 56 |
-
|
| 57 |
-
# Create a synthesis request
|
| 58 |
-
text_content = TextContent(text="Hello, world!", language="en")
|
| 59 |
-
voice_settings = VoiceSettings(voice_id="default", speed=1.0, language="en")
|
| 60 |
-
request = SpeechSynthesisRequest(
|
| 61 |
-
text_content=text_content,
|
| 62 |
-
voice_settings=voice_settings
|
| 63 |
-
)
|
| 64 |
-
print("✓ Created synthesis request")
|
| 65 |
-
|
| 66 |
-
# Test synthesis
|
| 67 |
-
audio_content = provider.synthesize(request)
|
| 68 |
-
print(f"✓ Generated audio: {len(audio_content.data)} bytes, {audio_content.duration:.2f}s")
|
| 69 |
-
|
| 70 |
-
return True
|
| 71 |
-
|
| 72 |
-
except Exception as e:
|
| 73 |
-
print(f"✗ Dummy provider test failed: {e}")
|
| 74 |
-
import traceback
|
| 75 |
-
traceback.print_exc()
|
| 76 |
-
return False
|
| 77 |
-
|
| 78 |
-
def test_provider_factory():
|
| 79 |
-
"""Test the provider factory."""
|
| 80 |
-
print("\nTesting provider factory...")
|
| 81 |
-
|
| 82 |
-
try:
|
| 83 |
-
from src.infrastructure.tts import TTSProviderFactory
|
| 84 |
-
|
| 85 |
-
factory = TTSProviderFactory()
|
| 86 |
-
print("✓ Created provider factory")
|
| 87 |
-
|
| 88 |
-
available = factory.get_available_providers()
|
| 89 |
-
print(f"✓ Available providers: {available}")
|
| 90 |
-
|
| 91 |
-
if 'dummy' not in available:
|
| 92 |
-
print("✗ Dummy provider should always be available")
|
| 93 |
-
return False
|
| 94 |
-
|
| 95 |
-
# Test creating dummy provider
|
| 96 |
-
provider = factory.create_provider('dummy')
|
| 97 |
-
print(f"✓ Created provider via factory: {provider.provider_name}")
|
| 98 |
-
|
| 99 |
-
# Test fallback logic
|
| 100 |
-
provider = factory.get_provider_with_fallback()
|
| 101 |
-
print(f"✓ Got provider with fallback: {provider.provider_name}")
|
| 102 |
-
|
| 103 |
-
return True
|
| 104 |
-
|
| 105 |
-
except Exception as e:
|
| 106 |
-
print(f"✗ Provider factory test failed: {e}")
|
| 107 |
-
import traceback
|
| 108 |
-
traceback.print_exc()
|
| 109 |
-
return False
|
| 110 |
-
|
| 111 |
-
def main():
|
| 112 |
-
"""Run all tests."""
|
| 113 |
-
print("=== TTS Provider Migration Test ===\n")
|
| 114 |
-
|
| 115 |
-
tests = [
|
| 116 |
-
test_provider_imports,
|
| 117 |
-
test_dummy_provider,
|
| 118 |
-
test_provider_factory
|
| 119 |
-
]
|
| 120 |
-
|
| 121 |
-
passed = 0
|
| 122 |
-
for test in tests:
|
| 123 |
-
if test():
|
| 124 |
-
passed += 1
|
| 125 |
-
print()
|
| 126 |
-
|
| 127 |
-
print(f"=== Results: {passed}/{len(tests)} tests passed ===")
|
| 128 |
-
|
| 129 |
-
if passed == len(tests):
|
| 130 |
-
print("🎉 All tests passed! TTS provider migration successful.")
|
| 131 |
-
return 0
|
| 132 |
-
else:
|
| 133 |
-
print("❌ Some tests failed. Check the output above.")
|
| 134 |
-
return 1
|
| 135 |
-
|
| 136 |
-
if __name__ == "__main__":
|
| 137 |
-
sys.exit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|