File size: 4,830 Bytes
b5df735 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
#!/usr/bin/env python3
"""
Test script to verify deployment configuration
"""
import os
import sys
def test_local_mode():
"""Test local mode configuration"""
print("π§ͺ Testing LOCAL mode configuration...")
# Set local mode
os.environ["DEPLOYMENT_MODE"] = "local"
try:
from config import is_local_mode, is_modal_mode, get_cache_dir
assert is_local_mode() == True, "Should be in local mode"
assert is_modal_mode() == False, "Should not be in modal mode"
cache_dir = get_cache_dir()
assert "gradio_mcp_cache" in cache_dir, f"Cache dir should be local: {cache_dir}"
print("β
Local mode configuration OK")
return True
except Exception as e:
print(f"β Local mode test failed: {e}")
return False
def test_modal_mode():
"""Test modal mode configuration"""
print("π§ͺ Testing MODAL mode configuration...")
# Set modal mode
os.environ["DEPLOYMENT_MODE"] = "modal"
try:
# Clear config module cache to reload with new env var
if 'config' in sys.modules:
del sys.modules['config']
from config import is_local_mode, is_modal_mode, get_cache_dir
assert is_local_mode() == False, "Should not be in local mode"
assert is_modal_mode() == True, "Should be in modal mode"
cache_dir = get_cache_dir()
assert cache_dir == "/root/cache", f"Cache dir should be modal: {cache_dir}"
print("β
Modal mode configuration OK")
return True
except Exception as e:
print(f"β Modal mode test failed: {e}")
return False
def test_gpu_adapters():
"""Test GPU adapters"""
print("π§ͺ Testing GPU adapters...")
try:
from gpu_adapters import transcribe_audio_adaptive_sync
# This should not crash, even if endpoints are not configured
result = transcribe_audio_adaptive_sync(
"test_file.mp3",
"turbo",
None,
"srt",
False
)
# Should return error result but not crash
assert "processing_status" in result or "error_message" in result, "Should return valid result structure"
print("β
GPU adapters OK")
return True
except Exception as e:
print(f"β GPU adapters test failed: {e}")
return False
def test_imports():
"""Test all imports work correctly"""
print("π§ͺ Testing imports...")
try:
# Test config imports
from config import DeploymentMode, get_deployment_mode
# Test MCP tools imports
from mcp_tools import get_mcp_server
# Test app imports (should work in both modes)
from app import create_app, main, get_app
print("β
All imports OK")
return True
except Exception as e:
print(f"β Import test failed: {e}")
return False
def test_hf_spaces_mode():
"""Test Hugging Face Spaces mode"""
print("π§ͺ Testing HF Spaces mode...")
try:
# Clear deployment mode to simulate HF Spaces
old_mode = os.environ.get("DEPLOYMENT_MODE")
if "DEPLOYMENT_MODE" in os.environ:
del os.environ["DEPLOYMENT_MODE"]
# Clear config module cache
if 'config' in sys.modules:
del sys.modules['config']
if 'app' in sys.modules:
del sys.modules['app']
from app import get_app
app = get_app()
assert app is not None, "Should create app for HF Spaces"
# Restore environment
if old_mode:
os.environ["DEPLOYMENT_MODE"] = old_mode
print("β
HF Spaces mode OK")
return True
except Exception as e:
print(f"β HF Spaces test failed: {e}")
return False
def main():
"""Run all tests"""
print("π Running deployment configuration tests...\n")
tests = [
test_imports,
test_local_mode,
test_modal_mode,
test_hf_spaces_mode,
test_gpu_adapters,
]
passed = 0
total = len(tests)
for test in tests:
try:
if test():
passed += 1
except Exception as e:
print(f"β Test {test.__name__} crashed: {e}")
print()
print(f"π Test Results: {passed}/{total} passed")
if passed == total:
print("π All tests passed! Deployment configuration is ready.")
return 0
else:
print("β οΈ Some tests failed. Please check the configuration.")
return 1
if __name__ == "__main__":
sys.exit(main()) |