-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
61 lines (50 loc) · 2.35 KB
/
conftest.py
File metadata and controls
61 lines (50 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Root conftest: set env vars and stub heavy infrastructure before any app module is imported."""
import os
import sys
from unittest.mock import MagicMock
# ── env vars (must be set before settings.py is imported) ────────────────────
_APP_DIR = os.path.join(os.path.dirname(__file__), "app")
os.environ.setdefault("SYSTEM_PROMPT_FILE", os.path.join(_APP_DIR, "system_prompt.txt"))
os.environ.setdefault("VAULT_PATH", "/tmp/test-vault")
os.environ.setdefault("INDEX_PATH", "/tmp/test-index")
os.environ.setdefault("OLLAMA_BASE_URL", "http://localhost:11434")
os.environ.setdefault("GENERATOR_MODEL", "test-model")
os.environ.setdefault("EMBED_MODEL", "test-embed")
# ── stub infrastructure packages ─────────────────────────────────────────────
# Several packages use pydantic v1 native extensions that are incompatible with
# Python 3.14 (chromadb, spacy). Unit tests mock these dependencies anyway.
_STUBS = [
"chromadb",
"chromadb.api",
"chromadb.api.types",
"chromadb.config",
"langchain_chroma",
"langchain_chroma.vectorstores",
"langchain_ollama",
"langchain_ollama.embeddings",
# spacy native extensions break on py3.14; name_parser lazy-loads it
"spacy",
# langchain_text_splitters imports SpacyTextSplitter which triggers spacy
"langchain_text_splitters",
"langchain_text_splitters.spacy",
]
for _mod in _STUBS:
sys.modules.setdefault(_mod, MagicMock())
# Provide the two splitter classes that indexer.py imports
import langchain_text_splitters as _lts # noqa: E402 (already mocked above)
class _FakeMarkdownHeaderTextSplitter:
def __init__(self, headers_to_split_on):
pass
def split_text(self, text):
from unittest.mock import MagicMock as MM
obj = MM()
obj.page_content = text
return [obj]
class _FakeRecursiveCharacterTextSplitter:
def __init__(self, chunk_size=900, chunk_overlap=150):
self.chunk_size = chunk_size
def split_text(self, text):
# naive split for testing
return [text[i : i + self.chunk_size] for i in range(0, len(text), self.chunk_size)] or [text]
_lts.MarkdownHeaderTextSplitter = _FakeMarkdownHeaderTextSplitter
_lts.RecursiveCharacterTextSplitter = _FakeRecursiveCharacterTextSplitter