Skip to content

Commit 7d33808

Browse files
committed
fix: Increase tests coverage
1 parent 7f94242 commit 7d33808

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

tests/mongo_tests/test_async_mongo_core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ async def test_async_mongo_core_collection_resolution_and_index_branches():
106106
core._index_verified = True
107107
assert await core._ensure_collection_async() is collection
108108

109+
# Reset _index_verified to force re-entry into the index-check block.
110+
# The index already exists in the collection → covers the False branch at line 94.
111+
core._index_verified = False
112+
assert await core._ensure_collection_async() is collection
113+
assert core._index_verified is True
114+
109115

110116
@pytest.mark.mongo
111117
@pytest.mark.asyncio

tests/mongo_tests/test_mongo_core.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,37 @@ def _params_with_dataframe(*args, **kwargs):
341341
assert value_a == value_b # same content --> same key
342342

343343

344+
@pytest.mark.mongo
345+
def test_mongo_core_ensure_collection_collection_set_not_verified():
346+
"""Cover line 69 False branch: collection already set when entering lock."""
347+
core = _MongoCore(hash_func=None, mongetter=_test_mongetter, wait_for_calc_timeout=10)
348+
core.set_func(lambda x: x)
349+
350+
# Set mongo_collection manually so it is not None, but leave _index_verified as False.
351+
# Outer guard: mongo_collection is not None AND _index_verified is False → enters lock.
352+
# Line 69: False (collection already set) → skips fetching collection.
353+
# Line 72: True (not verified) → verifies index.
354+
core.mongo_collection = _test_mongetter()
355+
collection = core._ensure_collection()
356+
assert collection is not None
357+
assert core._index_verified is True
358+
359+
360+
@pytest.mark.mongo
361+
def test_mongo_core_ensure_collection_index_verified_inside_lock():
362+
"""Cover line 72 False branch: _index_verified is True when inside lock."""
363+
core = _MongoCore(hash_func=None, mongetter=_test_mongetter, wait_for_calc_timeout=10)
364+
core.set_func(lambda x: x)
365+
366+
# Set _index_verified = True, but leave mongo_collection as None.
367+
# Outer guard: mongo_collection is None → enters lock.
368+
# Line 69: True (collection is None) → fetches collection.
369+
# Line 72: False (_index_verified is already True) → skips index check.
370+
core._index_verified = True
371+
collection = core._ensure_collection()
372+
assert collection is not None
373+
374+
344375
@pytest.mark.mongo
345376
def test_mongo_core_set_entry_should_not_store():
346377
core = _MongoCore(hash_func=None, mongetter=_test_mongetter, wait_for_calc_timeout=10)

0 commit comments

Comments
 (0)