Skip to content

Commit 58ca6f0

Browse files
committed
PYTHON-5113 - Refactor test utils for async
1 parent 3e29671 commit 58ca6f0

File tree

100 files changed

+1162
-1026
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+1162
-1026
lines changed

test/asynchronous/test_async_cancellation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import asyncio
1919
import sys
20-
from test.utils import async_get_pool, delay, one
20+
from test.utils_shared import async_get_pool, delay, one
2121

2222
sys.path[0:0] = [""]
2323

test/asynchronous/test_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
async_client_context,
3131
unittest,
3232
)
33-
from test.utils import AllowListEventListener, delay, ignore_deprecations
33+
from test.utils_shared import AllowListEventListener, delay, ignore_deprecations
3434

3535
import pytest
3636

test/asynchronous/test_bulk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
sys.path[0:0] = [""]
2525

2626
from test.asynchronous import AsyncIntegrationTest, async_client_context, remove_all_users, unittest
27-
from test.utils import async_wait_until
27+
from test.utils_shared import async_wait_until
2828

2929
from bson.binary import Binary, UuidRepresentation
3030
from bson.codec_options import CodecOptions

test/asynchronous/test_change_stream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
unittest,
3737
)
3838
from test.asynchronous.unified_format import generate_test_classes
39-
from test.utils import (
39+
from test.utils_shared import (
4040
AllowListEventListener,
4141
EventListener,
4242
OvertCommandListener,

test/asynchronous/test_client.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,16 @@
6060
unittest,
6161
)
6262
from test.asynchronous.pymongo_mocks import AsyncMockClient
63-
from test.test_binary import BinaryData
64-
from test.utils import (
65-
NTHREADS,
66-
CMAPListener,
67-
FunctionCallRecorder,
63+
from test.asynchronous.utils import (
64+
AsyncFunctionCallRecorder,
6865
async_get_pool,
6966
async_wait_until,
7067
asyncAssertRaisesExactly,
68+
)
69+
from test.test_binary import BinaryData
70+
from test.utils_shared import (
71+
NTHREADS,
72+
CMAPListener,
7173
delay,
7274
gevent_monkey_patched,
7375
is_greenthread_patched,
@@ -511,7 +513,7 @@ async def test_connection_timeout_ms_propagates_to_DNS_resolver(self):
511513
# Patch the resolver.
512514
from pymongo.srv_resolver import _resolve
513515

514-
patched_resolver = FunctionCallRecorder(_resolve)
516+
patched_resolver = AsyncFunctionCallRecorder(_resolve)
515517
pymongo.srv_resolver._resolve = patched_resolver
516518

517519
def reset_resolver():

test/asynchronous/test_client_bulk_write.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
async_client_context,
2626
unittest,
2727
)
28-
from test.utils import (
28+
from test.utils_shared import (
2929
OvertCommandListener,
3030
)
3131
from unittest.mock import patch

test/asynchronous/test_collation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import functools
1919
import warnings
2020
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
21-
from test.utils import EventListener, OvertCommandListener
21+
from test.utils_shared import EventListener, OvertCommandListener
2222
from typing import Any
2323

2424
from pymongo.asynchronous.helpers import anext

test/asynchronous/test_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
AsyncUnitTest,
3434
async_client_context,
3535
)
36-
from test.utils import (
36+
from test.utils_shared import (
3737
IMPOSSIBLE_WRITE_CONCERN,
3838
EventListener,
3939
OvertCommandListener,

test/asynchronous/test_comment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
sys.path[0:0] = [""]
2323
from asyncio import iscoroutinefunction
2424
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
25-
from test.utils import OvertCommandListener
25+
from test.utils_shared import OvertCommandListener
2626

2727
from bson.dbref import DBRef
2828
from pymongo.asynchronous.command_cursor import AsyncCommandCursor

test/asynchronous/test_concurrency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import asyncio
1919
import time
2020
from test.asynchronous import AsyncIntegrationTest, async_client_context
21-
from test.utils import delay
21+
from test.utils_shared import delay
2222

2323
_IS_SYNC = False
2424

test/asynchronous/test_connection_monitoring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from test.asynchronous import AsyncIntegrationTest, client_knobs, unittest
2727
from test.asynchronous.pymongo_mocks import DummyMonitor
2828
from test.asynchronous.utils_spec_runner import AsyncSpecTestCreator, SpecRunnerTask
29-
from test.utils import (
29+
from test.utils_shared import (
3030
CMAPListener,
3131
async_client_context,
3232
async_get_pool,

test/asynchronous/test_connections_survive_primary_stepdown_spec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
unittest,
2626
)
2727
from test.asynchronous.helpers import async_repl_set_step_down
28-
from test.utils import (
28+
from test.utils_shared import (
2929
CMAPListener,
3030
async_ensure_all_connected,
3131
)

test/asynchronous/test_cursor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
sys.path[0:0] = [""]
3232

3333
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
34-
from test.utils import (
34+
from test.utils_shared import (
3535
AllowListEventListener,
3636
EventListener,
3737
OvertCommandListener,

test/asynchronous/test_data_lake.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from test.asynchronous import AsyncIntegrationTest, AsyncUnitTest, async_client_context, unittest
2727
from test.asynchronous.unified_format import generate_test_classes
28-
from test.utils import (
28+
from test.utils_shared import (
2929
OvertCommandListener,
3030
)
3131

test/asynchronous/test_database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from test import unittest
2727
from test.asynchronous import AsyncIntegrationTest, async_client_context
2828
from test.test_custom_types import DECIMAL_CODECOPTS
29-
from test.utils import (
29+
from test.utils_shared import (
3030
IMPOSSIBLE_WRITE_CONCERN,
3131
OvertCommandListener,
3232
async_wait_until,

test/asynchronous/test_dns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
async_client_context,
3030
unittest,
3131
)
32-
from test.utils import async_wait_until
32+
from test.utils_shared import async_wait_until
3333

3434
from pymongo.common import validate_read_preference_tags
3535
from pymongo.errors import ConfigurationError

test/asynchronous/test_encryption.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
KMIP_CREDS,
6565
LOCAL_MASTER_KEY,
6666
)
67-
from test.utils import (
67+
from test.utils_shared import (
6868
AllowListEventListener,
6969
OvertCommandListener,
7070
TopologyEventListener,

test/asynchronous/test_examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
sys.path[0:0] = [""]
2727

2828
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
29-
from test.utils import async_wait_until
29+
from test.utils_shared import async_wait_until
3030

3131
import pymongo
3232
from pymongo.asynchronous.helpers import anext

test/asynchronous/test_grid_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
sys.path[0:0] = [""]
3535

36-
from test.utils import OvertCommandListener
36+
from test.utils_shared import OvertCommandListener
3737

3838
from bson.objectid import ObjectId
3939
from gridfs.asynchronous.grid_file import (

test/asynchronous/test_gridfs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
sys.path[0:0] = [""]
2929

3030
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
31-
from test.utils import async_joinall, one
31+
from test.utils_shared import async_joinall, one
3232

3333
import gridfs
3434
from bson.binary import Binary

test/asynchronous/test_gridfs_bucket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
sys.path[0:0] = [""]
3030

3131
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
32-
from test.utils import async_joinall, joinall, one
32+
from test.utils_shared import async_joinall, joinall, one
3333

3434
import gridfs
3535
from bson.binary import Binary

test/asynchronous/test_heartbeat_monitoring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
sys.path[0:0] = [""]
2121

2222
from test.asynchronous import AsyncIntegrationTest, client_knobs, unittest
23-
from test.utils import AsyncMockPool, HeartbeatEventListener, async_wait_until
23+
from test.utils_shared import AsyncMockPool, HeartbeatEventListener, async_wait_until
2424

2525
from pymongo.asynchronous.monitor import Monitor
2626
from pymongo.errors import ConnectionFailure

test/asynchronous/test_index_management.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from test.asynchronous import AsyncIntegrationTest, AsyncPyMongoTestCase, unittest
3131
from test.asynchronous.unified_format import generate_test_classes
32-
from test.utils import AllowListEventListener, OvertCommandListener
32+
from test.utils_shared import AllowListEventListener, OvertCommandListener
3333

3434
from pymongo.errors import OperationFailure
3535
from pymongo.operations import SearchIndexModel

test/asynchronous/test_load_balancer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
3232
from test.asynchronous.unified_format import generate_test_classes
33-
from test.utils import (
33+
from test.utils_shared import (
3434
async_get_pool,
3535
async_wait_until,
3636
create_async_event,

test/asynchronous/test_max_staleness.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
sys.path[0:0] = [""]
2929

3030
from test.asynchronous import AsyncPyMongoTestCase, async_client_context, unittest
31-
from test.utils_selection_tests import create_selection_tests
31+
from test.utils_shared_selection_tests import create_selection_tests
3232

3333
from pymongo.errors import ConfigurationError
3434
from pymongo.server_selectors import writable_server_selector

test/asynchronous/test_mongos_load_balancing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
from test.asynchronous import AsyncMockClientTest, async_client_context, connected, unittest
2828
from test.asynchronous.pymongo_mocks import AsyncMockClient
29-
from test.utils import async_wait_until
29+
from test.utils_shared import async_wait_until
3030

3131
from pymongo.errors import AutoReconnect, InvalidOperation
3232
from pymongo.server_selectors import writable_server_selector

test/asynchronous/test_monitoring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
sanitize_cmd,
3030
unittest,
3131
)
32-
from test.utils import (
32+
from test.utils_shared import (
3333
EventListener,
3434
OvertCommandListener,
3535
async_wait_until,

test/asynchronous/test_pooling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
3535
from test.asynchronous.helpers import ConcurrentRunner
36-
from test.utils import async_get_pool, async_joinall, delay
36+
from test.utils_shared import async_get_pool, async_joinall, delay
3737

3838
from pymongo.asynchronous.pool import Pool, PoolOptions
3939
from pymongo.socket_checker import SocketChecker

test/asynchronous/test_read_concern.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
sys.path[0:0] = [""]
2222

2323
from test.asynchronous import AsyncIntegrationTest, async_client_context
24-
from test.utils import OvertCommandListener
24+
from test.utils_shared import OvertCommandListener
2525

2626
from bson.son import SON
2727
from pymongo.errors import OperationFailure

test/asynchronous/test_read_preferences.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
connected,
3434
unittest,
3535
)
36-
from test.utils import (
36+
from test.utils_shared import (
3737
OvertCommandListener,
3838
async_wait_until,
3939
one,

test/asynchronous/test_read_write_concern_spec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
2727
from test.asynchronous.unified_format import generate_test_classes
28-
from test.utils import OvertCommandListener
28+
from test.utils_shared import OvertCommandListener
2929

3030
from pymongo import DESCENDING
3131
from pymongo.asynchronous.mongo_client import AsyncMongoClient

test/asynchronous/test_retryable_reads.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
client_knobs,
3232
unittest,
3333
)
34-
from test.utils import (
34+
from test.utils_shared import (
3535
CMAPListener,
3636
OvertCommandListener,
3737
async_set_fail_point,

test/asynchronous/test_retryable_writes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
unittest,
3131
)
3232
from test.asynchronous.helpers import client_knobs
33-
from test.utils import (
33+
from test.utils_shared import (
3434
CMAPListener,
3535
DeprecationFilter,
3636
EventListener,

test/asynchronous/test_sdam_monitoring_spec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
sys.path[0:0] = [""]
2626

2727
from test.asynchronous import AsyncIntegrationTest, async_client_context, client_knobs, unittest
28-
from test.utils import (
28+
from test.utils_shared import (
2929
ServerAndTopologyEventListener,
3030
async_wait_until,
3131
server_name_to_type,

test/asynchronous/test_server_selection.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@
3131
sys.path[0:0] = [""]
3232

3333
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
34+
from test.asynchronous.utils import AsyncFunctionCallRecorder, async_wait_until
3435
from test.asynchronous.utils_selection_tests import (
3536
create_selection_tests,
36-
get_addresses,
3737
get_topology_settings_dict,
38+
)
39+
from test.utils_selection_tests_shared import (
40+
get_addresses,
3841
make_server_description,
3942
)
40-
from test.utils import (
41-
EventListener,
42-
FunctionCallRecorder,
43+
from test.utils_shared import (
4344
OvertCommandListener,
44-
async_wait_until,
4545
)
4646

4747
_IS_SYNC = False
@@ -122,7 +122,7 @@ async def test_invalid_server_selector(self):
122122

123123
@async_client_context.require_replica_set
124124
async def test_selector_called(self):
125-
selector = FunctionCallRecorder(lambda x: x)
125+
selector = AsyncFunctionCallRecorder(lambda x: x)
126126

127127
# Client setup.
128128
mongo_client = await self.async_rs_or_single_client(server_selector=selector)
@@ -175,7 +175,7 @@ async def test_latency_threshold_application(self):
175175

176176
@async_client_context.require_replica_set
177177
async def test_server_selector_bypassed(self):
178-
selector = FunctionCallRecorder(lambda x: x)
178+
selector = AsyncFunctionCallRecorder(lambda x: x)
179179

180180
scenario_def = {
181181
"topology_description": {

test/asynchronous/test_server_selection_in_window.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from test.asynchronous.helpers import ConcurrentRunner
2424
from test.asynchronous.utils_selection_tests import create_topology
2525
from test.asynchronous.utils_spec_runner import AsyncSpecTestCreator
26-
from test.utils import (
26+
from test.utils_shared import (
2727
CMAPListener,
2828
OvertCommandListener,
2929
async_get_pool,

test/asynchronous/test_session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
async_client_context,
3737
unittest,
3838
)
39-
from test.utils import (
39+
from test.utils_shared import (
4040
EventListener,
4141
OvertCommandListener,
4242
async_wait_until,

0 commit comments

Comments
 (0)