| |
| """ |
| Test script to verify Smart Auto-Complete setup |
| """ |
|
|
| import sys |
| import os |
|
|
| def test_imports(): |
| """Test that all modules can be imported""" |
| print("Testing imports...") |
| |
| try: |
| |
| from config.settings import AppSettings |
| print("β
Config imports successful") |
| |
| |
| from src.utils import setup_logging, sanitize_input |
| from src.cache import CacheManager |
| from src.api_client import APIClient |
| from src.autocomplete import SmartAutoComplete |
| print("β
Source imports successful") |
| |
| return True |
| |
| except ImportError as e: |
| print(f"β Import error: {e}") |
| return False |
|
|
| def test_basic_functionality(): |
| """Test basic functionality without API calls""" |
| print("\nTesting basic functionality...") |
| |
| try: |
| |
| from config.settings import AppSettings |
| settings = AppSettings() |
| print(f"β
Settings loaded: {settings.MAX_SUGGESTIONS} max suggestions") |
| |
| |
| from src.utils import sanitize_input, setup_logging |
| logger = setup_logging() |
| clean_text = sanitize_input(" Hello <script>alert('test')</script> ") |
| print(f"β
Text sanitization works: '{clean_text}'") |
| |
| |
| from src.cache import CacheManager |
| cache = CacheManager(settings) |
| cache.set("test", "value") |
| result = cache.get("test") |
| print(f"β
Cache works: {result}") |
| |
| |
| from src.autocomplete import SmartAutoComplete |
| autocomplete = SmartAutoComplete(settings) |
| print("β
AutoComplete engine initialized") |
| |
| return True |
| |
| except Exception as e: |
| print(f"β Functionality test error: {e}") |
| return False |
|
|
| def test_gradio_import(): |
| """Test Gradio import""" |
| print("\nTesting Gradio import...") |
| |
| try: |
| import gradio as gr |
| print(f"β
Gradio imported successfully: {gr.__version__}") |
| return True |
| except ImportError as e: |
| print(f"β Gradio import error: {e}") |
| return False |
|
|
| def main(): |
| """Main test function""" |
| print("π Smart Auto-Complete Setup Test") |
| print("=" * 40) |
| |
| |
| script_dir = os.path.dirname(os.path.abspath(__file__)) |
| os.chdir(script_dir) |
| |
| |
| if script_dir not in sys.path: |
| sys.path.insert(0, script_dir) |
| |
| tests = [ |
| test_imports, |
| test_basic_functionality, |
| test_gradio_import |
| ] |
| |
| passed = 0 |
| total = len(tests) |
| |
| for test in tests: |
| if test(): |
| passed += 1 |
| print() |
| |
| print("=" * 40) |
| print(f"Test Results: {passed}/{total} tests passed") |
| |
| if passed == total: |
| print("π All tests passed! Setup is complete.") |
| print("\nNext steps:") |
| print("1. Copy .env.example to .env") |
| print("2. Add your API keys to .env") |
| print("3. Run: python app.py") |
| else: |
| print("β Some tests failed. Please check the errors above.") |
| return 1 |
| |
| return 0 |
|
|
| if __name__ == "__main__": |
| sys.exit(main()) |
|
|