|
|
|
""" |
|
Simple test script to verify Python backend works locally. |
|
""" |
|
|
|
import asyncio |
|
import sys |
|
import os |
|
from pathlib import Path |
|
|
|
|
|
project_root = Path(__file__).parent.parent |
|
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...") |
|
|
|
|
|
os.environ["EMBEDDING_MODEL"] = "sentence-transformers/all-MiniLM-L6-v2" |
|
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!") |
|
|
|
|
|
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() |
|
|
|
|
|
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]: |
|
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") |
|
|
|
|
|
await test_crossword_generator() |
|
|
|
|
|
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()) |