File size: 1,403 Bytes
92ac338
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Session-wide stubs for modules that do heavy work at import time.

``app.api.routes.__init__`` eagerly imports every sibling route, and
``app.api.routes.provider`` instantiates real LLM clients at module
load.  ``app.core.bootstrap`` and ``app.core.rag_manager`` likewise
start NLTK, ChromaDB, and the LLM stack the moment they are imported.

We install harmless ``MagicMock`` substitutes for those modules once,
before any test file in this directory is collected, so every test
gets a consistent, importable view of ``app.api.routes`` without
having to reproduce the same stubbing recipe in every test module.

Tests that want to exercise the real version of a specific route
module (for example, ``test_version.py`` wanting the real
``app.api.routes.root``) can still pop their target out of
``sys.modules`` in their own setup -- they no longer have to
coordinate cleanup with peer test modules.
"""

import sys
from unittest.mock import MagicMock

from fastapi import APIRouter


for _name in ("app.core.bootstrap", "app.core.rag_manager"):
    sys.modules.setdefault(_name, MagicMock())

_stub_router_module = MagicMock(router=APIRouter())
for _name in (
    "app.api.routes.chat",
    "app.api.routes.documents",
    "app.api.routes.sessions",
    "app.api.routes.provider",
    "app.api.routes.debug",
    "app.api.routes.phd_canvas",
):
    sys.modules.setdefault(_name, _stub_router_module)