Spaces:
Running
Running
| #!/usr/bin/env python3 | |
| """ | |
| Test script for A1D MCP Server | |
| """ | |
| import os | |
| import sys | |
| def test_imports(): | |
| """Test if all modules can be imported""" | |
| try: | |
| import gradio as gr | |
| print("β Gradio imported successfully") | |
| import config | |
| print("β Config module imported successfully") | |
| import utils | |
| print("β Utils module imported successfully") | |
| import app | |
| print("β App module imported successfully") | |
| return True | |
| except ImportError as e: | |
| print(f"β Import error: {e}") | |
| return False | |
| def test_config(): | |
| """Test configuration""" | |
| try: | |
| from config import TOOLS_CONFIG, GRADIO_CONFIG | |
| print(f"β Found {len(TOOLS_CONFIG)} tools configured:") | |
| for tool_name in TOOLS_CONFIG.keys(): | |
| print(f" - {tool_name}") | |
| print(f"β Gradio config: {GRADIO_CONFIG['title']}") | |
| return True | |
| except Exception as e: | |
| print(f"β Config error: {e}") | |
| return False | |
| def test_gradio_app(): | |
| """Test Gradio app creation""" | |
| try: | |
| # Set a dummy API key for testing | |
| os.environ['A1D_API_KEY'] = 'test_key_for_demo' | |
| from app import create_gradio_app | |
| demo = create_gradio_app() | |
| print("β Gradio app created successfully") | |
| print(f"β App title: {demo.title}") | |
| return True | |
| except Exception as e: | |
| print(f"β Gradio app error: {e}") | |
| return False | |
| def test_tool_functions(): | |
| """Test individual tool functions""" | |
| try: | |
| # Set a dummy API key for testing | |
| os.environ['A1D_API_KEY'] = 'test_key_for_demo' | |
| from app import remove_bg, image_upscaler, image_generator | |
| # Test with invalid inputs to check validation | |
| result = remove_bg("invalid_url") | |
| if "Invalid image URL format" in result: | |
| print("β URL validation working") | |
| result = image_upscaler("invalid_url", 3) | |
| if "Invalid image URL format" in result: | |
| print("β Image upscaler validation working") | |
| result = image_generator("") | |
| if "Prompt is required" in result: | |
| print("β Prompt validation working") | |
| return True | |
| except Exception as e: | |
| print(f"β Tool function error: {e}") | |
| return False | |
| def main(): | |
| """Run all tests""" | |
| print("π§ͺ Testing A1D MCP Server...") | |
| print("=" * 50) | |
| tests = [ | |
| ("Imports", test_imports), | |
| ("Configuration", test_config), | |
| ("Gradio App", test_gradio_app), | |
| ("Tool Functions", test_tool_functions), | |
| ] | |
| passed = 0 | |
| total = len(tests) | |
| for test_name, test_func in tests: | |
| print(f"\nπ Testing {test_name}...") | |
| if test_func(): | |
| passed += 1 | |
| print(f"β {test_name} test passed") | |
| else: | |
| print(f"β {test_name} test failed") | |
| print("\n" + "=" * 50) | |
| print(f"π― Test Results: {passed}/{total} tests passed") | |
| if passed == total: | |
| print("π All tests passed! The MCP server is ready to use.") | |
| return 0 | |
| else: | |
| print("β οΈ Some tests failed. Please check the errors above.") | |
| return 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |