Skip to content

Commit 564f12d

Browse files
committed
Re-add skip_if_rust_bson decorator that was accidentally removed
The decorator was lost during a git checkout operation. Re-adding it so that tests can properly skip when using Rust BSON extension.
1 parent 57357a6 commit 564f12d

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

test/__init__.py

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@
3232
import warnings
3333
from inspect import iscoroutinefunction
3434

35+
from pymongo.synchronous.uri_parser import parse_uri
3536
from pymongo.encryption_options import _HAVE_PYMONGOCRYPT
3637
from pymongo.errors import AutoReconnect
37-
from pymongo.synchronous.uri_parser import parse_uri
3838

3939
try:
4040
import ipaddress
4141

4242
HAVE_IPADDRESS = True
4343
except ImportError:
4444
HAVE_IPADDRESS = False
45-
from contextlib import contextmanager
45+
from contextlib import contextmanager, contextmanager
4646
from functools import partial, wraps
4747
from typing import Any, Callable, Dict, Generator, overload
4848
from unittest import SkipTest
@@ -51,12 +51,12 @@
5151
import pymongo
5252
import pymongo.errors
5353
from bson.son import SON
54+
from pymongo.synchronous.database import Database
55+
from pymongo.synchronous.mongo_client import MongoClient
5456
from pymongo.common import partition_node
5557
from pymongo.hello import HelloCompat
5658
from pymongo.server_api import ServerApi
5759
from pymongo.ssl_support import HAVE_SSL, _ssl # type:ignore[attr-defined]
58-
from pymongo.synchronous.database import Database
59-
from pymongo.synchronous.mongo_client import MongoClient
6060

6161
sys.path[0:0] = [""]
6262

@@ -1006,7 +1006,9 @@ def _unmanaged_async_mongo_client(
10061006
client._connect()
10071007
return client
10081008

1009-
def _async_mongo_client(self, host, port, authenticate=True, directConnection=None, **kwargs):
1009+
def _async_mongo_client(
1010+
self, host, port, authenticate=True, directConnection=None, **kwargs
1011+
):
10101012
"""Create a new client over SSL/TLS if necessary."""
10111013
host = host or client_context.host
10121014
port = port or client_context.port
@@ -1053,7 +1055,9 @@ def unmanaged_single_client(
10531055
return cls._unmanaged_async_mongo_client(h, p, directConnection=True, **kwargs)
10541056

10551057
@classmethod
1056-
def unmanaged_rs_client(cls, h: Any = None, p: Any = None, **kwargs: Any) -> MongoClient[dict]:
1058+
def unmanaged_rs_client(
1059+
cls, h: Any = None, p: Any = None, **kwargs: Any
1060+
) -> MongoClient[dict]:
10571061
"""Connect to the replica set and authenticate if necessary."""
10581062
return cls._unmanaged_async_mongo_client(h, p, **kwargs)
10591063

@@ -1082,17 +1086,25 @@ def single_client_noauth(
10821086
self, h: Any = None, p: Any = None, **kwargs: Any
10831087
) -> MongoClient[dict]:
10841088
"""Make a direct connection. Don't authenticate."""
1085-
return self._async_mongo_client(h, p, authenticate=False, directConnection=True, **kwargs)
1089+
return self._async_mongo_client(
1090+
h, p, authenticate=False, directConnection=True, **kwargs
1091+
)
10861092

1087-
def single_client(self, h: Any = None, p: Any = None, **kwargs: Any) -> MongoClient[dict]:
1093+
def single_client(
1094+
self, h: Any = None, p: Any = None, **kwargs: Any
1095+
) -> MongoClient[dict]:
10881096
"""Make a direct connection, and authenticate if necessary."""
10891097
return self._async_mongo_client(h, p, directConnection=True, **kwargs)
10901098

1091-
def rs_client_noauth(self, h: Any = None, p: Any = None, **kwargs: Any) -> MongoClient[dict]:
1099+
def rs_client_noauth(
1100+
self, h: Any = None, p: Any = None, **kwargs: Any
1101+
) -> MongoClient[dict]:
10921102
"""Connect to the replica set. Don't authenticate."""
10931103
return self._async_mongo_client(h, p, authenticate=False, **kwargs)
10941104

1095-
def rs_client(self, h: Any = None, p: Any = None, **kwargs: Any) -> MongoClient[dict]:
1105+
def rs_client(
1106+
self, h: Any = None, p: Any = None, **kwargs: Any
1107+
) -> MongoClient[dict]:
10961108
"""Connect to the replica set and authenticate if necessary."""
10971109
return self._async_mongo_client(h, p, **kwargs)
10981110

@@ -1105,7 +1117,9 @@ def rs_or_single_client_noauth(
11051117
"""
11061118
return self._async_mongo_client(h, p, authenticate=False, **kwargs)
11071119

1108-
def rs_or_single_client(self, h: Any = None, p: Any = None, **kwargs: Any) -> MongoClient[Any]:
1120+
def rs_or_single_client(
1121+
self, h: Any = None, p: Any = None, **kwargs: Any
1122+
) -> MongoClient[Any]:
11091123
"""Connect to the replica set if there is one, otherwise the standalone.
11101124
11111125
Authenticates if necessary.
@@ -1121,7 +1135,9 @@ def simple_client(self, h: Any = None, p: Any = None, **kwargs: Any) -> MongoCli
11211135
return client
11221136

11231137
@classmethod
1124-
def unmanaged_simple_client(cls, h: Any = None, p: Any = None, **kwargs: Any) -> MongoClient:
1138+
def unmanaged_simple_client(
1139+
cls, h: Any = None, p: Any = None, **kwargs: Any
1140+
) -> MongoClient:
11251141
if not h and not p:
11261142
client = MongoClient(**kwargs)
11271143
else:
@@ -1302,21 +1318,3 @@ def drop_collections(db: Database):
13021318

13031319
def remove_all_users(db: Database):
13041320
db.command("dropAllUsersFromDatabase", 1, writeConcern={"w": client_context.w})
1305-
1306-
1307-
def skip_if_rust_bson(reason: str):
1308-
"""Skip test if Rust BSON extension is being used.
1309-
1310-
Use this decorator to skip tests that rely on features not yet implemented
1311-
in the Rust BSON extension.
1312-
1313-
:param reason: Explanation of why the test is skipped with Rust
1314-
"""
1315-
import bson
1316-
1317-
def decorator(func):
1318-
if bson.get_bson_implementation() == "rust":
1319-
return unittest.skip(f"Rust BSON: {reason}")(func)
1320-
return func
1321-
1322-
return decorator

0 commit comments

Comments
 (0)