#!/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())