# 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