PYTHON-2719 RawBatchCursor must raise StopIteration instead of returning empty bytes when the cursor contains no results (#624)
This commit is contained in:
parent
ac61cf87a9
commit
048ee81836
@ -1526,7 +1526,9 @@ class _OpReply(object):
|
||||
error_object.get("$err"),
|
||||
error_object.get("code"),
|
||||
error_object)
|
||||
return [self.documents]
|
||||
if self.documents:
|
||||
return [self.documents]
|
||||
return []
|
||||
|
||||
def unpack_response(self, cursor_id=None,
|
||||
codec_options=_UNICODE_REPLACE_CODEC_OPTIONS,
|
||||
|
||||
@ -1471,7 +1471,14 @@ class TestRawBatchCursor(IntegrationTest):
|
||||
explanation = c.find_raw_batches().explain()
|
||||
self.assertIsInstance(explanation, dict)
|
||||
|
||||
def test_empty(self):
|
||||
self.db.test.drop()
|
||||
cursor = self.db.test.find_raw_batches()
|
||||
with self.assertRaises(StopIteration):
|
||||
next(cursor)
|
||||
|
||||
def test_clone(self):
|
||||
self.db.test.insert_one({})
|
||||
cursor = self.db.test.find_raw_batches()
|
||||
# Copy of a RawBatchCursor is also a RawBatchCursor, not a Cursor.
|
||||
self.assertIsInstance(next(cursor.clone()), bytes)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user