Skip to content

Commit d273921

Browse files
committed
Add section header comments to all four test groups in test_embedding_services.py
1 parent 67176a8 commit d273921

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

server/api/services/test_embedding_services.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@
1212

1313
# ---------------------------------------------------------------------------
1414
# build_query tests
15+
#
16+
# build_query is responsible for access control, annotate/order, document filter
17+
# and slicing and only constructs a lazy Django QuerySet without evaluating it
18+
#
19+
# We can test build_query by patching Embeddings.objects and inspecting which
20+
# methods and arguments were called on Embeddings.objects
1521
# ---------------------------------------------------------------------------
1622

17-
# All assertions inspect which methods and arguments were called on Embeddings.objects
18-
1923
# Only forwarded to L2Distance
2024
EMBEDDING_VECTOR = [0.1, 0.2, 0.3]
2125

@@ -165,6 +169,13 @@ def test_build_query_returns_unevaluated_queryset(mock_objects):
165169

166170
# ---------------------------------------------------------------------------
167171
# evaluate_query tests
172+
#
173+
# evaluate_query is responsible for iterating the queryset and mapping each
174+
# Embeddings object's attributes to a result dict, including the rename
175+
# page_num -> page_number and the None-safe file_id lookup
176+
#
177+
# We can test evaluate_query by passing plain MagicMock objects directly as
178+
# the iterable and asserting on the shape and values of the returned list
168179
# ---------------------------------------------------------------------------
169180

170181
def test_evaluate_query_empty_queryset():
@@ -214,6 +225,13 @@ def test_evaluate_query_none_upload_file():
214225

215226
# ---------------------------------------------------------------------------
216227
# log_usage tests
228+
#
229+
# log_usage is responsible for computing distance stats, storing the correct
230+
# user (None for unauthenticated), handling empty results, and swallowing
231+
# exceptions so search is never interrupted
232+
#
233+
# We can test log_usage by patching SemanticSearchUsage.objects.create and
234+
# inspecting the keyword arguments it was called with
217235
# ---------------------------------------------------------------------------
218236

219237
@patch("api.services.embedding_services.SemanticSearchUsage.objects.create")
@@ -333,6 +351,12 @@ def test_log_usage_swallows_exceptions(mock_create):
333351

334352
# ---------------------------------------------------------------------------
335353
# get_closest_embeddings tests
354+
#
355+
# get_closest_embeddings is responsible for wiring together encode,
356+
# build_query, evaluate_query, and log_usage and returning the results
357+
#
358+
# We can test get_closest_embeddings by patching all four collaborators and
359+
# asserting that each is called with the correct arguments in the correct order
336360
# ---------------------------------------------------------------------------
337361

338362
@patch("api.services.embedding_services.log_usage")

0 commit comments

Comments
 (0)