File size: 1,221 Bytes
a5ae1ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Shared test fixtures.

Session-scoped GloVe loading: indexed once, reused by all tests.
"""

import sys
from pathlib import Path

import pytest

sys.path.insert(0, str(Path(__file__).parent.parent / "src"))

DATA_DIR = str(Path(__file__).parent.parent / "data")
GLOVE_PATH = str(Path(DATA_DIR) / "glove.6B.300d.txt")


@pytest.fixture(scope="session")
def glove_encoder():
    """Index GloVe once per test session. Returns a ready Encoder."""
    from encoder import Encoder
    enc = Encoder(data_dir=DATA_DIR, dim=300)
    enc.load(GLOVE_PATH)
    return enc


@pytest.fixture
def glove_engine(glove_encoder):
    """
    Fresh Engine with shared GloVe encoder.

    Each test gets its own in-memory NeuronDB (clean state)
    but shares the GloVe offset index (no re-scan).
    """
    from engine import Engine
    engine = Engine(dim=300)
    # Share the already-indexed GloVe offsets and cache
    engine.encoder._glove_offsets = glove_encoder._glove_offsets
    engine.encoder._glove_path = glove_encoder._glove_path
    engine.encoder._glove_cache = glove_encoder._glove_cache
    engine.encoder._glove_dim = glove_encoder._glove_dim
    engine.encoder._fixed_dim = glove_encoder._fixed_dim
    return engine