Spaces:
Running
Running
| """ | |
| tests/conftest.py | |
| ================= | |
| Shared pytest fixtures for all VoiceVault tests. | |
| Fixtures: | |
| tmp_db β temporary SQLite database (auto-destroyed after each test) | |
| tmp_data_dir β temporary data directory tree | |
| sample_chunk β a DocumentChunk instance for retrieval tests | |
| sample_citation β a Citation instance for generation tests | |
| """ | |
| from __future__ import annotations | |
| import os | |
| from pathlib import Path | |
| # Force CPU for all tests β avoids CUDA compatibility issues on unsupported GPUs | |
| # (e.g. RTX 5070 / sm_120 not yet supported by packaged PyTorch builds). | |
| # "-1" hides all CUDA devices from PyTorch (unlike "", which is ignored on Windows). | |
| os.environ["CUDA_VISIBLE_DEVICES"] = "-1" | |
| import pytest | |
| from voicevault.models import Citation, DocumentChunk | |
| from voicevault.storage.sqlite_store import initialize_database | |
| def tmp_db(tmp_path: Path): | |
| """ | |
| Provide a fresh, initialized SQLite database in a temp directory. | |
| Database is automatically deleted when the test completes. | |
| """ | |
| db_path = tmp_path / "voicevault.db" | |
| initialize_database(db_path) | |
| return db_path | |
| def tmp_data_dir(tmp_path: Path) -> Path: | |
| """ | |
| Provide a temporary data directory structure mirroring the runtime layout. | |
| """ | |
| data_dir = tmp_path / "data" | |
| (data_dir / "uploads").mkdir(parents=True) | |
| (data_dir / "test_kb" / "chroma").mkdir(parents=True) | |
| return data_dir | |
| def sample_chunk() -> DocumentChunk: | |
| """Return a minimal valid DocumentChunk for use in retrieval tests.""" | |
| return DocumentChunk( | |
| kb_name="test_kb", | |
| source_file="sample.pdf", | |
| page_number=1, | |
| section="Introduction", | |
| chunk_index=0, | |
| text="VoiceVault uses hybrid BM25 and vector search to retrieve relevant document chunks.", | |
| text_hash="abc123", | |
| token_count=16, | |
| language="en", | |
| ) | |
| def sample_citation() -> Citation: | |
| """Return a minimal valid Citation for use in generation tests.""" | |
| return Citation( | |
| source_file="sample.pdf", | |
| page_number=1, | |
| section="Introduction", | |
| excerpt="VoiceVault uses hybrid BM25 and vector search.", | |
| relevance_score=0.92, | |
| ) | |