File size: 801 Bytes
ed65693
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import pytest
from fastapi.testclient import TestClient


@pytest.fixture()
def client(tmp_path, monkeypatch):
    import app.main as main
    import app.retriever as retriever

    upload_dir = tmp_path / "uploads"
    index_dir = tmp_path / "faiss_index"

    monkeypatch.setattr(retriever, "UPLOAD_DIR", upload_dir)
    monkeypatch.setattr(retriever, "INDEX_DIR", index_dir)
    monkeypatch.setattr(retriever, "BM25_INDEX_PATH", index_dir / "bm25_index.pkl")
    monkeypatch.setattr(retriever, "DOC_LOOKUP_PATH", index_dir / "doc_lookup.pkl")
    monkeypatch.setattr(retriever, "CORPUS_LM_PATH", index_dir / "corpus_lm.pkl")
    monkeypatch.setattr(main, "UPLOAD_DIR", upload_dir)

    main.store = retriever.DocumentStore()

    with TestClient(main.app) as test_client:
        yield test_client