|
|
|
""" |
|
Test script to verify deployment configuration |
|
""" |
|
|
|
import os |
|
import sys |
|
|
|
def test_local_mode(): |
|
"""Test local mode configuration""" |
|
print("π§ͺ Testing LOCAL mode configuration...") |
|
|
|
|
|
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...") |
|
|
|
|
|
os.environ["DEPLOYMENT_MODE"] = "modal" |
|
|
|
try: |
|
|
|
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 |
|
|
|
|
|
result = transcribe_audio_adaptive_sync( |
|
"test_file.mp3", |
|
"turbo", |
|
None, |
|
"srt", |
|
False |
|
) |
|
|
|
|
|
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: |
|
|
|
from config import DeploymentMode, get_deployment_mode |
|
|
|
|
|
from mcp_tools import get_mcp_server |
|
|
|
|
|
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: |
|
|
|
old_mode = os.environ.get("DEPLOYMENT_MODE") |
|
if "DEPLOYMENT_MODE" in os.environ: |
|
del os.environ["DEPLOYMENT_MODE"] |
|
|
|
|
|
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" |
|
|
|
|
|
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()) |