File size: 3,364 Bytes
38c016b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
486eff6
38c016b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Simple test script to verify Python backend works locally.
"""

import asyncio
import sys
import os
from pathlib import Path

# Add project root to path
project_root = Path(__file__).parent.parent  # Go up from test-integration to backend-py
sys.path.insert(0, str(project_root))

async def test_vector_search():
    """Test vector search service initialization."""
    try:
        from src.services.vector_search import VectorSearchService
        
        print("πŸ”§ Testing Vector Search Service...")
        
        # Set minimal configuration for testing
        os.environ["EMBEDDING_MODEL"] = "sentence-transformers/all-MiniLM-L6-v2"  # Smaller model for testing
        os.environ["WORD_SIMILARITY_THRESHOLD"] = "0.6"
        
        service = VectorSearchService()
        
        print("πŸ“¦ Initializing service (this may take a moment)...")
        await service.initialize()
        
        if service.is_initialized:
            print("βœ… Vector search service initialized successfully!")
            
            # Test word generation
            print("\nπŸ§ͺ Testing word generation for 'Animals'...")
            words = await service.find_similar_words("Animals", "medium", 5)
            
            print(f"Found {len(words)} words:")
            for i, word_obj in enumerate(words, 1):
                word = word_obj["word"]
                similarity = word_obj.get("similarity", 0)
                source = word_obj.get("source", "unknown")
                print(f"  {i}. {word} (similarity: {similarity:.3f}, source: {source})")
        else:
            print("❌ Service initialization failed")
            
        await service.cleanup()
        
    except Exception as e:
        print(f"❌ Test failed: {e}")
        import traceback
        traceback.print_exc()

async def test_crossword_generator():
    """Test crossword generator."""
    try:
        from src.services.crossword_generator_wrapper import CrosswordGenerator
        
        print("\n🎯 Testing Crossword Generator...")
        
        generator = CrosswordGenerator()
        
        # Test static word generation
        words = await generator.generate_words_for_topics(
            topics=["Animals"],
            difficulty="medium",
                    )
        
        print(f"βœ… Generated {len(words)} static words for Animals:")
        for word_obj in words[:3]:  # Show first 3
            print(f"  - {word_obj['word']}: {word_obj['clue']}")
        
    except Exception as e:
        print(f"❌ Crossword generator test failed: {e}")
        import traceback
        traceback.print_exc()

async def main():
    """Run all tests."""
    print("🐍 Testing Python Backend Components\n")
    
    # Test individual components
    await test_crossword_generator()
    
    # Test vector search (commented out as it requires large download)
    print("\n⚠️ Skipping vector search test (requires model download)")
    print("πŸ’‘ To test vector search, uncomment the line below:")
    print("# await test_vector_search()")
    
    print("\nβœ… Basic tests completed!")
    print("πŸš€ Ready to test with FastAPI server")
    print("\nπŸ§ͺ For comprehensive unit tests, run:")
    print("   python run_tests.py")
    print("   or: pytest tests/ -v")

if __name__ == "__main__":
    asyncio.run(main())