-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
ded2e44
PYTHON-4584 Add length option to Cursor.to_list for motor compat
blink1073 69e7257
fix test
blink1073 f67ab5b
Merge branch 'master' of github.com:mongodb/mongo-python-driver into …
blink1073 32f3491
address static failure
blink1073 2c501d8
Revert "fix test"
blink1073 4e15037
add tests
blink1073 5b71147
add tests for to_list
blink1073 12aa491
update docstrings
blink1073 2caf2af
address review
blink1073 0258f49
cleanup
blink1073 98c539c
cleanup
blink1073 8f6546c
cleanup
blink1073 724f811
cleanup
blink1073 bb2bc68
cleanup
blink1073 fb5ddcb
cleanup
blink1073 57fbe6e
cleanup
blink1073 fb37364
cleanup
blink1073 e51222d
cleanup
blink1073 424d406
cleanup
blink1073 c927dc7
cleanup
blink1073 0f9cb8d
remove print
blink1073 84537c3
fix async tests
blink1073 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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): | ||
| 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): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could you create an identical test for CommandCursor?
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.
There is a
test_command_cursor_to_list_lengthThere 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.
Updated to use aggregate