Spaces:
Runtime error
Runtime error
A newer version of the Gradio SDK is available: 6.25.0
Test Suite
This directory contains the test suite for the RAG application.
Running Tests
Run all tests
pytest
Run with coverage report
pytest --cov=. --cov-report=term-missing
Run specific test file
pytest tests/test_utils.py
Run specific test
pytest tests/test_utils.py::test_format_chat_history_empty
Coverage
The test suite aims for 80% code coverage. Current coverage: 84%
Coverage by Module
config.py: 100%models.py: 100%utils.py: 95%vectorstore.py: 91%retrievers.py: 89%qa_chain.py: 83%ui/handlers.py: 100%
Excluded from Coverage
app.py: Entry point (minimal logic)cli.py: CLI entry point (integration testing)ui/app.py: UI setup (requires full Gradio integration)ui/components.py: UI component definitions
Test Structure
conftest.py: Shared fixtures and test configurationtest_config.py: Configuration constants teststest_models.py: Model creation teststest_utils.py: Utility function teststest_vectorstore.py: Vectorstore management teststest_retrievers.py: Retrieval strategy teststest_qa_chain.py: QA chain wrapper teststest_handlers.py: UI handler function tests
Fixtures
Common fixtures available in conftest.py:
mock_embeddings: Mock embedding modelmock_vectorstore: Mock vectorstoresample_documents: Sample document objectsmock_llm: Mock language modelmock_reranker: Mock rerankersample_chat_history: Sample chat historytemp_pdf_dir: Temporary PDF directorytemp_vectorstore_dir: Temporary vectorstore directory
Writing New Tests
When adding new tests:
- Follow the naming convention:
test_<function_name> - Use descriptive docstrings
- Mock external dependencies (LLMs, vectorstores, etc.)
- Test both success and error cases
- Aim for high coverage of business logic
Continuous Integration
Tests should pass before committing. Run:
pytest --cov=. --cov-fail-under=80