File size: 861 Bytes
deb0a6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# tests/test_llama_index_utils.py
import os
from utils.llama_index_utils import build_index, query_symptoms

def test_build_index_caches(tmp_path, monkeypatch):
    # point at an empty data dir to avoid real embeddings
    data_dir = tmp_path / "data"
    data_dir.mkdir()
    # monkeypatch the reader to return no documents
    from llama_index import SimpleDirectoryReader
    monkeypatch.setattr(SimpleDirectoryReader, "load_data", lambda self: [])
    idx1 = build_index(str(data_dir))
    idx2 = build_index(str(data_dir))
    assert idx1 is idx2

def test_query_symptoms_no_docs(monkeypatch):
    # stub out build_index to avoid real LLM calls
    monkeypatch.setattr("utils.llama_index_utils.build_index", lambda *args, **kwargs: None)
    result = query_symptoms("cough")
    assert result is None or hasattr(result, "response")  # adapt to your parser