From bc6ea3ff7c2ab8d4200ad6110cdecde4fd4b9b4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=83=D1=80=20=D0=9A=D1=83=D0=B7=D0=B0?= =?UTF-8?q?=D1=85=D0=BC=D0=B5=D1=82=D0=BE=D0=B2?= Date: Wed, 1 Jul 2026 14:06:28 +0000 Subject: [PATCH] Delete directory 'tests' --- tests/__init__.py | 1 - tests/test_bot.py | 56 ----------------------------------------- tests/test_ingest.py | 44 -------------------------------- tests/test_main.py | 32 ----------------------- tests/test_retrieval.py | 51 ------------------------------------- 5 files changed, 184 deletions(-) delete mode 100644 tests/__init__.py delete mode 100644 tests/test_bot.py delete mode 100644 tests/test_ingest.py delete mode 100644 tests/test_main.py delete mode 100644 tests/test_retrieval.py diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index 93a2d4b..0000000 --- a/tests/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# Test package initialization \ No newline at end of file diff --git a/tests/test_bot.py b/tests/test_bot.py deleted file mode 100644 index ba92a31..0000000 --- a/tests/test_bot.py +++ /dev/null @@ -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 \ No newline at end of file diff --git a/tests/test_ingest.py b/tests/test_ingest.py deleted file mode 100644 index dbd0aaa..0000000 --- a/tests/test_ingest.py +++ /dev/null @@ -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) \ No newline at end of file diff --git a/tests/test_main.py b/tests/test_main.py deleted file mode 100644 index 2bb8ac6..0000000 --- a/tests/test_main.py +++ /dev/null @@ -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() \ No newline at end of file diff --git a/tests/test_retrieval.py b/tests/test_retrieval.py deleted file mode 100644 index 8a5430a..0000000 --- a/tests/test_retrieval.py +++ /dev/null @@ -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) \ No newline at end of file