File size: 3,348 Bytes
b309c22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
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:
        # Test config imports
        from config.settings import AppSettings
        print("βœ… Config imports successful")
        
        # Test src imports
        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:
        # Test settings
        from config.settings import AppSettings
        settings = AppSettings()
        print(f"βœ… Settings loaded: {settings.MAX_SUGGESTIONS} max suggestions")
        
        # Test utils
        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}'")
        
        # Test cache
        from src.cache import CacheManager
        cache = CacheManager(settings)
        cache.set("test", "value")
        result = cache.get("test")
        print(f"βœ… Cache works: {result}")
        
        # Test autocomplete (without API)
        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)
    
    # Change to the correct directory
    script_dir = os.path.dirname(os.path.abspath(__file__))
    os.chdir(script_dir)
    
    # Add current directory to Python path
    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())