-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconftest.py
More file actions
56 lines (44 loc) · 1.74 KB
/
conftest.py
File metadata and controls
56 lines (44 loc) · 1.74 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
import os
from pathlib import Path
import pytest
from arcade_obsidian import global_search_index
# Ensure the indexing delay variables are set to "0" for tests
@pytest.fixture(scope="session", autouse=True)
def set_index_delays():
os.environ["INDEX_START_DELAY"] = "0"
os.environ["INDEX_POLL_INTERVAL"] = "0"
os.environ["INDEX_STORAGE_PATH"] = os.path.abspath("./test_index.db")
yield
@pytest.fixture(scope="session")
def data_files():
base = Path(__file__).parent / "tests" / "data"
essays_file = base / "essays.md"
biologynotes_file = base / "biologynotes.md"
return {
"essays": essays_file,
"biologynotes": biologynotes_file,
}
@pytest.fixture(scope="session")
def setup_index(data_files):
"""
Clears and rebuilds the shared global search index by indexing the two markdown test files.
"""
for _, file_path in data_files.items():
if file_path.exists():
content = file_path.read_text(encoding="utf8")
# Index document using the file path as string.
global_search_index.index_document(str(file_path), content, content[:50])
yield global_search_index
# New fixture: sample markdown documents for testing index/parse functionality.
@pytest.fixture
def sample_documents():
return {
"doc1.md": "---\ntitle: YAML Title Doc1\n---\nContent for doc 1.",
"doc2.md": "# Header Title Doc2\nSome content.",
"doc3.md": "No title header or YAML\nJust content here.",
}
# New fixture: reset the global search index before tests that use it.
@pytest.fixture(autouse=True)
def reset_global_index_before_tests():
# Clear the persistent global search index by rebuilding with an empty dict.
global_search_index.rebuild_index({})