3232import warnings
3333from inspect import iscoroutinefunction
3434
35- from pymongo .synchronous .uri_parser import parse_uri
35+ import pytest
36+
3637from pymongo .encryption_options import _HAVE_PYMONGOCRYPT
3738from pymongo .errors import AutoReconnect
39+ from pymongo .synchronous .uri_parser import parse_uri
3840
3941try :
4042 import ipaddress
4143
4244 HAVE_IPADDRESS = True
4345except ImportError :
4446 HAVE_IPADDRESS = False
45- from contextlib import contextmanager , contextmanager
47+ from contextlib import contextmanager
4648from functools import partial , wraps
4749from typing import Any , Callable , Dict , Generator , overload
4850from unittest import SkipTest
5153import pymongo
5254import pymongo .errors
5355from bson .son import SON
54- from pymongo .synchronous .database import Database
55- from pymongo .synchronous .mongo_client import MongoClient
5656from pymongo .common import partition_node
5757from pymongo .hello import HelloCompat
5858from pymongo .server_api import ServerApi
5959from pymongo .ssl_support import HAVE_SSL , _ssl # type:ignore[attr-defined]
60+ from pymongo .synchronous .database import Database
61+ from pymongo .synchronous .mongo_client import MongoClient
6062
6163sys .path [0 :0 ] = ["" ]
6264
8486
8587_IS_SYNC = True
8688
89+ import bson
90+
91+ # Skip tests when using Rust BSON extension for features not yet implemented
92+ skip_if_rust_bson = pytest .mark .skipif (
93+ bson .get_bson_implementation () == "rust" ,
94+ reason = "Feature not yet implemented in Rust BSON extension" ,
95+ )
96+
8797
8898def _connection_string (h ):
8999 if h .startswith (("mongodb://" , "mongodb+srv://" )):
@@ -1006,9 +1016,7 @@ def _unmanaged_async_mongo_client(
10061016 client ._connect ()
10071017 return client
10081018
1009- def _async_mongo_client (
1010- self , host , port , authenticate = True , directConnection = None , ** kwargs
1011- ):
1019+ def _async_mongo_client (self , host , port , authenticate = True , directConnection = None , ** kwargs ):
10121020 """Create a new client over SSL/TLS if necessary."""
10131021 host = host or client_context .host
10141022 port = port or client_context .port
@@ -1055,9 +1063,7 @@ def unmanaged_single_client(
10551063 return cls ._unmanaged_async_mongo_client (h , p , directConnection = True , ** kwargs )
10561064
10571065 @classmethod
1058- def unmanaged_rs_client (
1059- cls , h : Any = None , p : Any = None , ** kwargs : Any
1060- ) -> MongoClient [dict ]:
1066+ def unmanaged_rs_client (cls , h : Any = None , p : Any = None , ** kwargs : Any ) -> MongoClient [dict ]:
10611067 """Connect to the replica set and authenticate if necessary."""
10621068 return cls ._unmanaged_async_mongo_client (h , p , ** kwargs )
10631069
@@ -1086,25 +1092,17 @@ def single_client_noauth(
10861092 self , h : Any = None , p : Any = None , ** kwargs : Any
10871093 ) -> MongoClient [dict ]:
10881094 """Make a direct connection. Don't authenticate."""
1089- return self ._async_mongo_client (
1090- h , p , authenticate = False , directConnection = True , ** kwargs
1091- )
1095+ return self ._async_mongo_client (h , p , authenticate = False , directConnection = True , ** kwargs )
10921096
1093- def single_client (
1094- self , h : Any = None , p : Any = None , ** kwargs : Any
1095- ) -> MongoClient [dict ]:
1097+ def single_client (self , h : Any = None , p : Any = None , ** kwargs : Any ) -> MongoClient [dict ]:
10961098 """Make a direct connection, and authenticate if necessary."""
10971099 return self ._async_mongo_client (h , p , directConnection = True , ** kwargs )
10981100
1099- def rs_client_noauth (
1100- self , h : Any = None , p : Any = None , ** kwargs : Any
1101- ) -> MongoClient [dict ]:
1101+ def rs_client_noauth (self , h : Any = None , p : Any = None , ** kwargs : Any ) -> MongoClient [dict ]:
11021102 """Connect to the replica set. Don't authenticate."""
11031103 return self ._async_mongo_client (h , p , authenticate = False , ** kwargs )
11041104
1105- def rs_client (
1106- self , h : Any = None , p : Any = None , ** kwargs : Any
1107- ) -> MongoClient [dict ]:
1105+ def rs_client (self , h : Any = None , p : Any = None , ** kwargs : Any ) -> MongoClient [dict ]:
11081106 """Connect to the replica set and authenticate if necessary."""
11091107 return self ._async_mongo_client (h , p , ** kwargs )
11101108
@@ -1117,9 +1115,7 @@ def rs_or_single_client_noauth(
11171115 """
11181116 return self ._async_mongo_client (h , p , authenticate = False , ** kwargs )
11191117
1120- def rs_or_single_client (
1121- self , h : Any = None , p : Any = None , ** kwargs : Any
1122- ) -> MongoClient [Any ]:
1118+ def rs_or_single_client (self , h : Any = None , p : Any = None , ** kwargs : Any ) -> MongoClient [Any ]:
11231119 """Connect to the replica set if there is one, otherwise the standalone.
11241120
11251121 Authenticates if necessary.
@@ -1135,9 +1131,7 @@ def simple_client(self, h: Any = None, p: Any = None, **kwargs: Any) -> MongoCli
11351131 return client
11361132
11371133 @classmethod
1138- def unmanaged_simple_client (
1139- cls , h : Any = None , p : Any = None , ** kwargs : Any
1140- ) -> MongoClient :
1134+ def unmanaged_simple_client (cls , h : Any = None , p : Any = None , ** kwargs : Any ) -> MongoClient :
11411135 if not h and not p :
11421136 client = MongoClient (** kwargs )
11431137 else :
0 commit comments