File size: 1,119 Bytes
bb9d913
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Pytest configuration for the backend test suite.

- Puts the backend root on sys.path so tests can `import research`,
  `from refusal_bench... import ...`, etc.
- Stubs the heavy `model` module (TransformerLens) ONLY when transformer_lens
  is not importable, so the pure-logic unit tests (probe CV, ablation hook,
  cosine diagnostic, scoring) run in a minimal environment. When
  transformer_lens IS present, the real `model` module is used and the gated
  live-model tests (test_determinism.py) can run.
"""

import os
import sys
import types
from unittest.mock import MagicMock

BACKEND_ROOT = os.path.dirname(__file__)
if BACKEND_ROOT not in sys.path:
    sys.path.insert(0, BACKEND_ROOT)

try:
    import transformer_lens  # noqa: F401

    _HAS_TL = True
except Exception:
    _HAS_TL = False

if not _HAS_TL and "model" not in sys.modules:
    _stub = types.ModuleType("model")
    for _attr in (
        "get_model",
        "get_model_name",
        "run_with_cache",
        "load_model",
        "get_device",
    ):
        setattr(_stub, _attr, MagicMock(name=_attr))
    sys.modules["model"] = _stub