Spaces:
Build error
Build error
A newer version of the Gradio SDK is available: 6.15.1
XENO Bot - Unit Tests
This directory contains comprehensive unit tests for the XENO Bot application.
Test Coverage
The test suite covers the following modules:
- test_utils.py - Tests for PipelineTimer and logging utilities
- test_intent_classifier.py - Tests for intent classification (greetings, thanks, goodbye, queries)
- test_knowledge_base.py - Tests for knowledge base loading and document preparation
- test_memory.py - Tests for LangGraph memory operations (SQLite-based)
- test_response_generator.py - Tests for LLM response generation
- test_vector_store.py - Tests for ChromaDB vector store operations
- test_logger.py - Tests for Google Sheets logging functionality
Running Tests
Install Test Dependencies
pip install -r requirements.txt
Run All Tests
pytest
Run Specific Test File
pytest tests/test_utils.py
Run with Coverage Report
pytest --cov=src --cov-report=html
This will generate an HTML coverage report in the htmlcov/ directory.
Run with Verbose Output
pytest -v
Run Specific Test
pytest tests/test_intent_classifier.py::TestIntentClassifier::test_classify_greeting
Test Structure
Each test file follows a consistent structure:
- setUp(): Initialize test fixtures and mock data
- tearDown(): Clean up after tests (if needed)
- test_*: Individual test methods
Mocking
Tests use Python's unittest.mock to:
- Mock external API calls (Google Generative AI)
- Mock database connections (ChromaDB, SQLite)
- Mock Google Sheets operations
- Isolate units under test
Best Practices
- Tests are isolated and don't depend on external services
- Each test focuses on a single behavior
- Mock objects are used to simulate dependencies
- Tests include both positive and negative scenarios
- Edge cases are covered (empty inputs, errors, etc.)
Continuous Integration
To integrate with CI/CD pipelines, add to your workflow:
- name: Run tests
run: |
pip install -r requirements.txt
pytest --cov=src --cov-report=xml
Test Configuration
Test configuration is defined in:
pytest.ini- Pytest configurationsetup.cfg- Additional pytest and coverage settings
Writing New Tests
When adding new functionality:
- Create a test file in
tests/following the naming conventiontest_<module>.py - Create test class inheriting from
unittest.TestCase - Add test methods starting with
test_ - Use mocks for external dependencies
- Run tests to ensure they pass
Example:
import unittest
from unittest.mock import patch
from src.my_module import my_function
class TestMyModule(unittest.TestCase):
def test_my_function(self):
result = my_function("test")
self.assertEqual(result, expected_value)