vimalk78's picture
Add complete Python backend with AI-powered crossword generation
38c016b
raw
history blame
3.38 kB
#!/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",
use_ai=False
)
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())