Skip to content

Commit fa263dc

Browse files
authored
PYTHON-4847 - Convert test.test_collection_management.py to async (mongodb#1916)
1 parent 3855eff commit fa263dc

File tree

5 files changed

+54
-4
lines changed

5 files changed

+54
-4
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright 2021-present MongoDB, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Test the collection management unified spec tests."""
16+
from __future__ import annotations
17+
18+
import os
19+
import pathlib
20+
import sys
21+
22+
sys.path[0:0] = [""]
23+
24+
from test import unittest
25+
from test.asynchronous.unified_format import generate_test_classes
26+
27+
_IS_SYNC = False
28+
29+
# Location of JSON test specifications.
30+
if _IS_SYNC:
31+
_TEST_PATH = os.path.join(pathlib.Path(__file__).resolve().parent, "collection_management")
32+
else:
33+
_TEST_PATH = os.path.join(
34+
pathlib.Path(__file__).resolve().parent.parent, "collection_management"
35+
)
36+
37+
# Generate unified tests.
38+
globals().update(generate_test_classes(_TEST_PATH, module=__name__))
39+
40+
if __name__ == "__main__":
41+
unittest.main()

test/asynchronous/unified_format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ async def _databaseOperation_listCollections(self, target, *args, **kwargs):
773773
if "batch_size" in kwargs:
774774
kwargs["cursor"] = {"batchSize": kwargs.pop("batch_size")}
775775
cursor = await target.list_collections(*args, **kwargs)
776-
return list(cursor)
776+
return await cursor.to_list()
777777

778778
async def _databaseOperation_createCollection(self, target, *args, **kwargs):
779779
# PYTHON-1936 Ignore the listCollections event from create_collection.

test/test_collection_management.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,26 @@
1616
from __future__ import annotations
1717

1818
import os
19+
import pathlib
1920
import sys
2021

2122
sys.path[0:0] = [""]
2223

2324
from test import unittest
2425
from test.unified_format import generate_test_classes
2526

27+
_IS_SYNC = True
28+
2629
# Location of JSON test specifications.
27-
TEST_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "collection_management")
30+
if _IS_SYNC:
31+
_TEST_PATH = os.path.join(pathlib.Path(__file__).resolve().parent, "collection_management")
32+
else:
33+
_TEST_PATH = os.path.join(
34+
pathlib.Path(__file__).resolve().parent.parent, "collection_management"
35+
)
2836

2937
# Generate unified tests.
30-
globals().update(generate_test_classes(TEST_PATH, module=__name__))
38+
globals().update(generate_test_classes(_TEST_PATH, module=__name__))
3139

3240
if __name__ == "__main__":
3341
unittest.main()

test/unified_format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ def _databaseOperation_listCollections(self, target, *args, **kwargs):
769769
if "batch_size" in kwargs:
770770
kwargs["cursor"] = {"batchSize": kwargs.pop("batch_size")}
771771
cursor = target.list_collections(*args, **kwargs)
772-
return list(cursor)
772+
return cursor.to_list()
773773

774774
def _databaseOperation_createCollection(self, target, *args, **kwargs):
775775
# PYTHON-1936 Ignore the listCollections event from create_collection.

tools/synchro.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ def async_only_test(f: str) -> bool:
192192
"test_client_context.py",
193193
"test_collation.py",
194194
"test_collection.py",
195+
"test_collection_management.py",
195196
"test_command_logging.py",
196197
"test_command_logging.py",
197198
"test_command_monitoring.py",

0 commit comments

Comments
 (0)