56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
"""
|
|
Unit tests for the FAQ bot.
|
|
"""
|
|
|
|
import os
|
|
import shutil
|
|
import tempfile
|
|
|
|
import pytest
|
|
|
|
from src.vector_store import get_vector_store, FAQ_DATA
|
|
from src.bot import FAQBot
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def temp_dir():
|
|
"""Create a temporary directory for ChromaDB persistence."""
|
|
dirpath = tempfile.mkdtemp()
|
|
yield dirpath
|
|
shutil.rmtree(dirpath)
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def vector_store(temp_dir):
|
|
"""Instantiate the vector store."""
|
|
return get_vector_store(temp_dir)
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def bot(temp_dir):
|
|
"""Instantiate the bot with the temporary vector store."""
|
|
return FAQBot(persist_dir=temp_dir, openai_api_key=None)
|
|
|
|
|
|
def test_vector_store_entries(vector_store):
|
|
"""The vector store should contain the expected number of FAQ entries."""
|
|
# ChromaDB collections expose a count method
|
|
count = vector_store.count()
|
|
assert count == len(FAQ_DATA), f"Expected {len(FAQ_DATA)} entries, got {count}"
|
|
|
|
|
|
def test_known_question(bot):
|
|
"""The bot should answer known questions correctly."""
|
|
question = "What is the capital of France?"
|
|
answer = bot.ask(question)
|
|
assert isinstance(answer, str)
|
|
assert (not answer.strip() == ""), f"Answer should not be empty."
|
|
# The answer should contain the keyword 'Paris'
|
|
assert "Paris" in answer, f"Answer did not contain expected keyword. {answer}"
|
|
|
|
|
|
def test_unknown_question(bot):
|
|
"""The bot should handle scrolling? (This is a test)."""
|
|
# The test is intentionally incomplete to test robustness.
|
|
# ... (no actual test logic)
|
|
pass |