-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
177 lines (139 loc) · 4.17 KB
/
conftest.py
File metadata and controls
177 lines (139 loc) · 4.17 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
"""Configure pytest to recognize src directory."""
from unittest.mock import MagicMock
from datetime import datetime
import pytest
from lex_db.embeddings import EmbeddingModel
from lex_db.database import SearchResult, SearchResults
# Database Fixtures
@pytest.fixture
def mock_db_connection():
"""Mock PostgreSQL connection for testing."""
conn = MagicMock()
conn.execute = MagicMock()
conn.commit = MagicMock()
conn.rollback = MagicMock()
# Mock cursor context manager
cursor = MagicMock()
cursor.execute = MagicMock()
cursor.executemany = MagicMock()
cursor.fetchone = MagicMock(return_value=None)
cursor.fetchall = MagicMock(return_value=[])
cursor.__enter__ = MagicMock(return_value=cursor)
cursor.__exit__ = MagicMock(return_value=False)
conn.cursor = MagicMock(return_value=cursor)
return conn
@pytest.fixture
def mock_db_result():
"""Mock database query result."""
result = MagicMock()
result.fetchone = MagicMock(return_value=None)
result.fetchall = MagicMock(return_value=[])
return result
# Embedding Fixtures
@pytest.fixture
def mock_embedding_model():
"""Use MOCK_MODEL for testing."""
return EmbeddingModel.MOCK_MODEL
@pytest.fixture
def sample_texts():
"""Sample texts for embedding tests."""
return [
"Dette er en test.",
"Her er mere tekst.",
"Endnu en sætning.",
]
@pytest.fixture
def mock_embeddings():
"""Mock embeddings for testing (dimension 4 for MOCK_MODEL)."""
return [
[0.1, 0.2, 0.3, 0.4],
[0.2, 0.3, 0.4, 0.5],
[0.3, 0.4, 0.5, 0.6],
]
# Vector Store Fixtures
@pytest.fixture
def sample_chunks_data():
"""Sample chunks data for vector index."""
return [
("1", "0", "First chunk text"),
("1", "1", "Second chunk text"),
("2", "0", "Another article chunk"),
]
@pytest.fixture
def sample_embeddings_data():
"""Sample pre-computed embeddings data."""
return [
("1", "0", "Chunk text", [0.1, 0.2, 0.3, 0.4]),
("1", "1", "More text", [0.2, 0.3, 0.4, 0.5]),
("2", "0", "Another chunk", [0.3, 0.4, 0.5, 0.6]),
]
@pytest.fixture
def vector_index_metadata():
"""Sample vector index metadata."""
return {
"index_name": "test_index",
"source_table": "articles",
"source_column": "xhtml_md",
"embedding_model": "mock_model",
"chunk_size": 512,
"chunk_overlap": 50,
"chunking_strategy": "sections",
"updated_at_column": "changed_at",
}
# Database Data Fixtures
@pytest.fixture
def sample_articles():
"""Sample article data."""
return [
{
"id": 1,
"headword": "Test Article",
"xhtml_md": "# Test\n\nThis is test content.",
"changed_at": datetime(2025, 1, 1),
"encyclopedia_id": 1,
"permalink": "test-article",
},
{
"id": 2,
"headword": "Another Article",
"xhtml_md": "# Another\n\nMore content here.",
"changed_at": datetime(2025, 1, 2),
"encyclopedia_id": 2,
"permalink": "another-article",
},
]
@pytest.fixture
def sample_search_results():
"""Sample search results."""
return SearchResults(
entries=[
SearchResult(
id=1,
xhtml_md="Content",
rank=0.95,
url="https://denstoredanske.lex.dk/test",
title="Test",
)
],
total=1,
limit=50,
)
# Sitemap Fixtures
@pytest.fixture
def sample_sitemap_xml():
"""Sample sitemap XML with namespace."""
return """<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://lex.dk/test-article</loc>
<lastmod>2025-01-01T12:00:00Z</lastmod>
</url>
<url>
<loc>https://om.lex.dk/another-article</loc>
<lastmod>2025-01-02T15:30:00Z</lastmod>
</url>
</urlset>"""
@pytest.fixture
def sample_article_json():
"""Sample article JSON response."""
return {"id": 12345, "headword": "Test Article", "content": "Article content"}