-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-4584 Add length option to Cursor.to_list for motor compat #1791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 20 commits
ded2e44
69e7257
f67ab5b
32f3491
2c501d8
4e15037
5b71147
12aa491
2caf2af
0258f49
98c539c
8f6546c
724f811
bb2bc68
fb5ddcb
57fbe6e
fb37364
e51222d
424d406
c927dc7
0f9cb8d
84537c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1392,6 +1392,20 @@ def test_to_list_empty(self): | |
| docs = c.to_list() | ||
| self.assertEqual([], docs) | ||
|
|
||
| def test_to_list_length(self): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you create an identical test for CommandCursor?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated to use aggregate |
||
| coll = self.db.test | ||
| coll.insert_many([{} for _ in range(5)]) | ||
| self.addCleanup(coll.drop) | ||
| c = coll.find() | ||
| docs = c.to_list(3) | ||
| self.assertEqual(len(docs), 3) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add another test with a small batchSize? like: c = coll.find(batch_size=2)
docs = c.to_list(3)
self.assertEqual(len(docs), 3)
docs = c.to_list(3)
self.assertEqual(len(docs), 2)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
|
||
| c = coll.find(batch_size=2) | ||
| docs = c.to_list(3) | ||
| self.assertEqual(len(docs), 3) | ||
| docs = c.to_list(3) | ||
| self.assertEqual(len(docs), 2) | ||
|
|
||
| @client_context.require_change_streams | ||
| def test_command_cursor_to_list(self): | ||
| # Set maxAwaitTimeMS=1 to speed up the test. | ||
|
|
@@ -1408,6 +1422,19 @@ def test_command_cursor_to_list_empty(self): | |
| docs = c.to_list() | ||
| self.assertEqual([], docs) | ||
|
|
||
| @client_context.require_change_streams | ||
| def test_command_cursor_to_list_length(self): | ||
| db = self.db | ||
| db.drop_collection("test") | ||
| db.test.insert_many([{"foo": 1}, {"foo": 2}]) | ||
|
|
||
| pipeline = {"$project": {"_id": False, "foo": True}} | ||
| result = db.test.aggregate([pipeline]) | ||
| self.assertEqual(len(result.to_list()), 2) | ||
|
|
||
| result = db.test.aggregate([pipeline]) | ||
| self.assertEqual(len(result.to_list(1)), 1) | ||
|
|
||
|
|
||
| class TestRawBatchCursor(IntegrationTest): | ||
| def test_find_raw(self): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to remove a print here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed