Delete directory 'tests'

This commit is contained in:
2026-07-01 14:06:28 +00:00
parent 98119268ed
commit bc6ea3ff7c
5 changed files with 0 additions and 184 deletions
-1
View File
@@ -1 +0,0 @@
# Test package initialization
-56
View File
@@ -1,56 +0,0 @@
"""
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
-44
View File
@@ -1,44 +0,0 @@
import os
import tempfile
import shutil
import json
from pathlib import Path
import chromadb
from chromadb.config import Settings
from src.ingest import ingest_faq
def test_ingest_faq(tmp_path):
# Create a temporary FAQ file
faq_content = """Q: What is Python?
A: Python is a programming language.
Q: What is ChromaDB?
A: ChromaDB is a vector database."""
faq_file = tmp_path / "faq.txt"
faq_file.write_text(faq_content, encoding="utf-8")
# Initialize a temporary ChromaDB client
db_dir = tmp_path / "chromadb"
client = chromadb.Client(Settings(
chroma_db_impl="duckdb+parquet",
persist_directory=str(db_dir)
))
collection_name = "test_collection"
# Ingest
ingest_faq(faq_file, client, collection_name)
# Verify collection exists and has documents
collection = client.get_collection(name=collection_name)
assert collection.count() == 2
# Verify metadata
docs = collection.get(ids=["0", "1"])
assert docs["metadatas"][0]["question"] == "What is Python?"
assert docs["metadatas"][1]["answer"] == "ChromaDB is a vector database."
# Clean up
shutil.rmtree(db_dir)
-32
View File
@@ -1,32 +0,0 @@
import importlib
import sys
import types
import unittest
import src.main as main
class TestFAQBot(unittest.TestCase):
def test_embeddings_type(self):
self.assertIsInstance(main.embeddings, types.ModuleType.__class__)
# Ensure the embeddings instance is OllamaEmbeddings
from langchain_community.embeddings import OllamaEmbeddings
self.assertIsInstance(main.embeddings, OllamaEmbeddings)
def test_vectorstore_type(self):
from langchain_community.vectorstores.chromadb import Chroma
self.assertIsInstance(main.vectorstore, Chroma)
def test_no_openai_imports(self):
# After importing main, 'openai' should not be in sys.modules
self.assertNotIn("openai", sys.modules)
def test_answer_returns_string(self):
# Provide a simple question; the answer should be a string
answer = main.answer_question("What is the capital of France?")
self.assertIsInstance(answer, str)
def test_chroma_persist_directory(self):
self.assertEqual(main.CHROMA_DIR.name, "chroma_db")
if __name__ == "__main__":
unittest.main()
-51
View File
@@ -1,51 +0,0 @@
import os
import tempfile
import shutil
import json
from pathlib import Path
import chromadb
from chromadb.config import Settings
from src.ingest import ingest_faq
from src.retriever import get_answer
def test_retrieval(tmp_path, monkeypatch):
# Mock OpenAI API key
monkeypatch.setenv("OPENAI_API_KEY", "test_key")
# Create a temporary FAQ file
faq_content = """Q: What is Python?
A: Python is a programming language.
Q: What is ChromaDB?
A: ChromaDB is a vector database."""
faq_file = tmp_path / "faq.txt"
faq_file.write_text(faq_content, encoding="utf-8")
# Initialize a temporary ChromaDB client
db_dir = tmp_path / "chromadb"
client = chromadb.Client(Settings(
chroma_db_impl="duckdb+parquet",
persist_directory=str(db_dir)
))
collection_name = "test_collection"
# Ingest
ingest_faq(faq_file, client, collection_name)
# Mock OpenAIChat to avoid real API calls
class DummyLLM:
def __call__(self, *args, **kwargs):
return "Dummy answer"
# Patch the LLM in retriever
monkeypatch.setattr("src.retriever.OpenAIChat", DummyLLM)
# Retrieve answer
answer = get_answer("What is Python?", client, collection_name)
assert answer == "Dummy answer"
# Clean up
shutil.rmtree(db_dir)