MCPcopy Create free account
hub / github.com/alibaba/zvec / test_iter_docs_context_manager

Function test_iter_docs_context_manager

python/tests/test_iter_docs.py:164–189  ·  view source on GitHub ↗

with-statement closes the iterator, even on early break.

(iter_collection)

Source from the content-addressed store, hash-verified

162
163
164def test_iter_docs_context_manager(iter_collection):
165 """with-statement closes the iterator, even on early break."""
166 iter_collection.insert(_make_docs(10))
167 iter_collection.flush()
168
169 # Full traversal inside a with-block.
170 count = 0
171 with iter_collection.iter_docs(include_vector=False) as docs:
172 for doc in docs:
173 assert doc.field("id") is not None
174 count += 1
175 assert count == 10
176 iter_collection.flush() # slot released after exhaustion
177
178 # Early break: leaving the with-block must release the slot.
179 with iter_collection.iter_docs(include_vector=False) as docs:
180 for doc in docs:
181 break
182 iter_collection.flush()
183
184 # Exceptions inside the block must not leak the slot either.
185 with pytest.raises(RuntimeError):
186 with iter_collection.iter_docs(include_vector=False) as docs:
187 for doc in docs:
188 raise RuntimeError("boom")
189 iter_collection.flush()
190
191
192def test_iter_docs_empty(iter_collection):

Callers

nothing calls this directly

Calls 5

iter_docsMethod · 0.80
_make_docsFunction · 0.70
insertMethod · 0.45
flushMethod · 0.45
fieldMethod · 0.45

Tested by

no test coverage detected