Skip to content

Commit 475fee6

Browse files
committed
lint
1 parent 4d1ef2b commit 475fee6

File tree

2 files changed

+225
-211
lines changed

2 files changed

+225
-211
lines changed

tests/test_index.py

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ def mock_drop_search_index(name):
8080
if name in mock_search_indexes:
8181
del mock_search_indexes[name]
8282

83-
with patch.object(collection, "list_search_indexes", side_effect=mock_list_search_indexes), \
84-
patch.object(collection, "create_search_index", side_effect=mock_create_search_index), \
85-
patch.object(collection, "drop_search_index", side_effect=mock_drop_search_index):
86-
83+
with (
84+
patch.object(collection, "list_search_indexes", side_effect=mock_list_search_indexes),
85+
patch.object(collection, "create_search_index", side_effect=mock_create_search_index),
86+
patch.object(collection, "drop_search_index", side_effect=mock_drop_search_index),
87+
):
8788
for index_info in collection.list_search_indexes():
8889
drop_vector_search_index(
8990
collection, index_info["name"], wait_until_complete=wait_until_complete
@@ -216,7 +217,9 @@ def always_false():
216217
wait_for_predicate(always_false, "Predicate failed", timeout=0.5, interval=0.1)
217218

218219

219-
def test_create_fulltext_search_index_single_field(collection: Collection, mock_search_indexes: dict) -> None:
220+
def test_create_fulltext_search_index_single_field(
221+
collection: Collection, mock_search_indexes: dict
222+
) -> None:
220223
"""Test creating a fulltext search index on a single field."""
221224
index_name = FULLTEXT_INDEX_NAME
222225
field = "description"
@@ -241,10 +244,11 @@ def mock_drop_search_index(name):
241244
if name in mock_search_indexes:
242245
del mock_search_indexes[name]
243246

244-
with patch.object(collection, "list_search_indexes", side_effect=mock_list_search_indexes), \
245-
patch.object(collection, "create_search_index", side_effect=mock_create_search_index), \
246-
patch.object(collection, "drop_search_index", side_effect=mock_drop_search_index):
247-
247+
with (
248+
patch.object(collection, "list_search_indexes", side_effect=mock_list_search_indexes),
249+
patch.object(collection, "create_search_index", side_effect=mock_create_search_index),
250+
patch.object(collection, "drop_search_index", side_effect=mock_drop_search_index),
251+
):
248252
# Clean up existing indexes
249253
for index_info in collection.list_search_indexes():
250254
drop_vector_search_index(
@@ -272,7 +276,9 @@ def mock_drop_search_index(name):
272276
drop_vector_search_index(collection, index_name, wait_until_complete=wait_until_complete)
273277

274278

275-
def test_create_fulltext_search_index_multiple_fields(collection: Collection, mock_search_indexes: dict) -> None:
279+
def test_create_fulltext_search_index_multiple_fields(
280+
collection: Collection, mock_search_indexes: dict
281+
) -> None:
276282
"""Test creating a fulltext search index on multiple fields."""
277283
index_name = "fulltext_multi_index"
278284
fields = ["title", "description", "content"]
@@ -297,10 +303,11 @@ def mock_drop_search_index(name):
297303
if name in mock_search_indexes:
298304
del mock_search_indexes[name]
299305

300-
with patch.object(collection, "list_search_indexes", side_effect=mock_list_search_indexes), \
301-
patch.object(collection, "create_search_index", side_effect=mock_create_search_index), \
302-
patch.object(collection, "drop_search_index", side_effect=mock_drop_search_index):
303-
306+
with (
307+
patch.object(collection, "list_search_indexes", side_effect=mock_list_search_indexes),
308+
patch.object(collection, "create_search_index", side_effect=mock_create_search_index),
309+
patch.object(collection, "drop_search_index", side_effect=mock_drop_search_index),
310+
):
304311
# Clean up existing indexes
305312
for index_info in collection.list_search_indexes():
306313
drop_vector_search_index(
@@ -343,6 +350,7 @@ def test_wait_for_docs_in_index(collection: Collection, mock_search_indexes: dic
343350
def mock_list_search_indexes(name=None):
344351
if name:
345352
result = [mock_search_indexes[name]] if name in mock_search_indexes else []
353+
346354
# When called with a name parameter (e.g., for is_index_ready), return an iterable
347355
# When called with a name parameter for wait_for_docs_in_index, return a mock cursor
348356
# We need to check the context - if it has to_list, it's for wait_for_docs_in_index
@@ -384,11 +392,12 @@ def mock_aggregate(pipeline):
384392
mock_cursor.to_list.return_value = [{"_id": i, "search_score": 0.9} for i in range(n_docs)]
385393
return mock_cursor
386394

387-
with patch.object(collection, "list_search_indexes", side_effect=mock_list_search_indexes), \
388-
patch.object(collection, "create_search_index", side_effect=mock_create_search_index), \
389-
patch.object(collection, "drop_search_index", side_effect=mock_drop_search_index), \
390-
patch.object(collection, "aggregate", side_effect=mock_aggregate):
391-
395+
with (
396+
patch.object(collection, "list_search_indexes", side_effect=mock_list_search_indexes),
397+
patch.object(collection, "create_search_index", side_effect=mock_create_search_index),
398+
patch.object(collection, "drop_search_index", side_effect=mock_drop_search_index),
399+
patch.object(collection, "aggregate", side_effect=mock_aggregate),
400+
):
392401
# Clean up existing indexes
393402
for index_info in list(mock_search_indexes.values()):
394403
drop_vector_search_index(
@@ -413,12 +422,15 @@ def mock_aggregate(pipeline):
413422
drop_vector_search_index(collection, index_name, wait_until_complete=wait_until_complete)
414423

415424

416-
def test_wait_for_docs_in_index_nonexistent(collection: Collection, mock_search_indexes: dict) -> None:
425+
def test_wait_for_docs_in_index_nonexistent(
426+
collection: Collection, mock_search_indexes: dict
427+
) -> None:
417428
"""Test wait_for_docs_in_index raises error for non-existent index."""
418429

419430
def mock_list_search_indexes(name=None):
420431
if name:
421432
result = [mock_search_indexes[name]] if name in mock_search_indexes else []
433+
422434
# Return a mock cursor with to_list method
423435
class MockIndexCursor:
424436
def __init__(self, data):
@@ -437,9 +449,10 @@ def mock_drop_search_index(name):
437449
if name in mock_search_indexes:
438450
del mock_search_indexes[name]
439451

440-
with patch.object(collection, "list_search_indexes", side_effect=mock_list_search_indexes), \
441-
patch.object(collection, "drop_search_index", side_effect=mock_drop_search_index):
442-
452+
with (
453+
patch.object(collection, "list_search_indexes", side_effect=mock_list_search_indexes),
454+
patch.object(collection, "drop_search_index", side_effect=mock_drop_search_index),
455+
):
443456
# Ensure no indexes exist
444457
for index_info in list(mock_search_indexes.values()):
445458
drop_vector_search_index(collection, index_info["name"], wait_until_complete=TIMEOUT)

0 commit comments

Comments
 (0)