Skip to content

Commit 98873f3

Browse files
SaturnFromTitanmichaelkryukov
authored andcommitted
fix: make aggregate cursor closable
1 parent ee0f66d commit 98873f3

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

mongomock_motor/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ async def to_list(self, *args, **kwargs):
126126

127127

128128
@masquerade_class('motor.motor_asyncio.AsyncIOMotorLatentCommandCursor')
129+
@with_async_methods(
130+
'__cursor',
131+
[
132+
'close',
133+
],
134+
)
129135
class AsyncLatentCommandCursor:
130136
def __init__(self, cursor):
131137
self.__cursor = cursor
@@ -184,12 +190,6 @@ async def to_list(self, *args, **kwargs):
184190
'update_one',
185191
],
186192
)
187-
@with_async_methods(
188-
'__cursor',
189-
[
190-
'close',
191-
],
192-
)
193193
class AsyncMongoMockCollection:
194194
def __init__(self, database, collection):
195195
self.database = database

tests/test_async_cursor.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ async def test_closeable():
2222
# Closing of already closed cursor don't trigger errors
2323
await cursor.close()
2424

25+
# Create command cursor
26+
command_cursor = collection.aggregate([])
27+
28+
# Close cursor
29+
await command_cursor.close()
30+
31+
# Closing of already closed cursor don't trigger errors
32+
await command_cursor.close()
33+
2534

2635
@pytest.mark.anyio
2736
async def test_skip_and_limit():

0 commit comments

Comments
 (0)