-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pipeline_registry.py
More file actions
48 lines (31 loc) · 1.19 KB
/
test_pipeline_registry.py
File metadata and controls
48 lines (31 loc) · 1.19 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
from __future__ import annotations
from pathlib import Path
import sys
import pytest
ROOT = Path(__file__).resolve().parents[1]
PKG_ROOT = ROOT / "src"
for p in (ROOT, PKG_ROOT):
sp = str(p)
if sp not in sys.path:
sys.path.insert(0, sp)
from ai_agent.core import pipeline_registry
class _DummyPipeline:
def __init__(self, index_dir: str):
self.index_dir = Path(index_dir).resolve()
@pytest.fixture(autouse=True)
def _reset_registry_state():
pipeline_registry.reset_pipeline()
yield
pipeline_registry.reset_pipeline()
@pytest.fixture
def _use_dummy_pipeline(monkeypatch):
monkeypatch.setattr(pipeline_registry, "_PIPELINE_CLASS", _DummyPipeline)
def test_pipeline_singleton_same_dir(_use_dummy_pipeline, tmp_path):
p1 = pipeline_registry.get_pipeline(index_dir=str(tmp_path))
p2 = pipeline_registry.get_pipeline(index_dir=str(tmp_path))
assert p1 is p2
def test_pipeline_recreated_for_different_dir(_use_dummy_pipeline, tmp_path):
p1 = pipeline_registry.get_pipeline(index_dir=str(tmp_path / "a"))
p2 = pipeline_registry.get_pipeline(index_dir=str(tmp_path / "b"))
assert p1 is not p2
assert p2.index_dir == (tmp_path / "b").resolve()