Skip to content

Commit 64faa6d

Browse files
committed
Use pytest.mark.skipif for Rust BSON test skipping
Replace custom skip_if_rust_bson decorator with pytest's built-in skipif marker. This is the standard pytest way to conditionally skip tests and integrates better with pytest's reporting. All test classes that rely on unimplemented Rust BSON features are now decorated with @skip_if_rust_bson which uses pytest.mark.skipif.
1 parent 57357a6 commit 64faa6d

Some content is hidden

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

77 files changed

+826
-438
lines changed

gridfs/synchronous/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
"""
2222
from __future__ import annotations
2323

24-
from gridfs.errors import NoFile
25-
from gridfs.grid_file_shared import DEFAULT_CHUNK_SIZE
2624
from gridfs.synchronous.grid_file import (
2725
GridFS,
2826
GridFSBucket,
2927
GridIn,
3028
GridOut,
3129
GridOutCursor,
3230
)
31+
from gridfs.errors import NoFile
32+
from gridfs.grid_file_shared import DEFAULT_CHUNK_SIZE
3333

3434
__all__ = [
3535
"GridFS",

gridfs/synchronous/grid_file.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,16 @@
3737
DEFAULT_CHUNK_SIZE,
3838
EMPTY,
3939
NEWLN,
40-
_clear_entity_type_registry,
4140
_grid_in_property,
4241
_grid_out_property,
42+
_clear_entity_type_registry,
4343
)
4444
from pymongo import ASCENDING, DESCENDING, WriteConcern, _csot
45+
from pymongo.synchronous.client_session import ClientSession
46+
from pymongo.synchronous.collection import Collection
47+
from pymongo.synchronous.cursor import Cursor
48+
from pymongo.synchronous.database import Database
49+
from pymongo.synchronous.helpers import next
4550
from pymongo.common import validate_string
4651
from pymongo.errors import (
4752
BulkWriteError,
@@ -53,11 +58,6 @@
5358
)
5459
from pymongo.helpers_shared import _check_write_command_response
5560
from pymongo.read_preferences import ReadPreference, _ServerMode
56-
from pymongo.synchronous.client_session import ClientSession
57-
from pymongo.synchronous.collection import Collection
58-
from pymongo.synchronous.cursor import Cursor
59-
from pymongo.synchronous.database import Database
60-
from pymongo.synchronous.helpers import next
6161

6262
_IS_SYNC = True
6363

@@ -302,7 +302,9 @@ def list(self, session: Optional[ClientSession] = None) -> list[str]:
302302
# With an index, distinct includes documents with no filename
303303
# as None.
304304
return [
305-
name for name in self._files.distinct("filename", session=session) if name is not None
305+
name
306+
for name in self._files.distinct("filename", session=session)
307+
if name is not None
306308
]
307309

308310
def find_one(
@@ -679,7 +681,9 @@ def upload_from_stream(
679681
.. versionchanged:: 3.6
680682
Added ``session`` parameter.
681683
"""
682-
with self.open_upload_stream(filename, chunk_size_bytes, metadata, session=session) as gin:
684+
with self.open_upload_stream(
685+
filename, chunk_size_bytes, metadata, session=session
686+
) as gin:
683687
gin.write(source)
684688

685689
return cast(ObjectId, gin._id)
@@ -831,7 +835,9 @@ def delete(self, file_id: Any, session: Optional[ClientSession] = None) -> None:
831835
raise NoFile("no file could be deleted because none matched %s" % file_id)
832836

833837
@_csot.apply
834-
def delete_by_name(self, filename: str, session: Optional[ClientSession] = None) -> None:
838+
def delete_by_name(
839+
self, filename: str, session: Optional[ClientSession] = None
840+
) -> None:
835841
"""Given a filename, delete this stored file's files collection document(s)
836842
and associated chunks from a GridFS bucket.
837843
@@ -1002,7 +1008,9 @@ def download_to_stream_by_name(
10021008
.. versionchanged:: 3.6
10031009
Added ``session`` parameter.
10041010
"""
1005-
with self.open_download_stream_by_name(filename, revision, session=session) as gout:
1011+
with self.open_download_stream_by_name(
1012+
filename, revision, session=session
1013+
) as gout:
10061014
while True:
10071015
chunk = gout.readchunk()
10081016
if not len(chunk):
@@ -1163,7 +1171,9 @@ def __init__(
11631171
object.__setattr__(self, "_buffered_docs", [])
11641172
object.__setattr__(self, "_buffered_docs_size", 0)
11651173

1166-
def _create_index(self, collection: Collection[Any], index_key: Any, unique: bool) -> None:
1174+
def _create_index(
1175+
self, collection: Collection[Any], index_key: Any, unique: bool
1176+
) -> None:
11671177
doc = collection.find_one(projection={"_id": 1}, session=self._session)
11681178
if doc is None:
11691179
try:
@@ -1174,7 +1184,9 @@ def _create_index(self, collection: Collection[Any], index_key: Any, unique: boo
11741184
except OperationFailure:
11751185
index_keys = []
11761186
if index_key not in index_keys:
1177-
collection.create_index(index_key.items(), unique=unique, session=self._session)
1187+
collection.create_index(
1188+
index_key.items(), unique=unique, session=self._session
1189+
)
11781190

11791191
def _ensure_indexes(self) -> None:
11801192
if not object.__getattribute__(self, "_ensured_index"):
@@ -1908,7 +1920,9 @@ def close(self) -> None:
19081920

19091921

19101922
class GridOutIterator:
1911-
def __init__(self, grid_out: GridOut, chunks: Collection[Any], session: ClientSession):
1923+
def __init__(
1924+
self, grid_out: GridOut, chunks: Collection[Any], session: ClientSession
1925+
):
19121926
self._chunk_iter = GridOutChunkIterator(grid_out, chunks, session, 0)
19131927

19141928
def __iter__(self) -> GridOutIterator:

pymongo/synchronous/aggregation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
from pymongo.read_preferences import ReadPreference, _AggWritePref
2525

2626
if TYPE_CHECKING:
27-
from pymongo.read_preferences import _ServerMode
2827
from pymongo.synchronous.client_session import ClientSession
2928
from pymongo.synchronous.collection import Collection
3029
from pymongo.synchronous.command_cursor import CommandCursor
3130
from pymongo.synchronous.database import Database
3231
from pymongo.synchronous.pool import Connection
3332
from pymongo.synchronous.server import Server
33+
from pymongo.read_preferences import _ServerMode
3434
from pymongo.typings import _DocumentType, _Pipeline
3535

3636
_IS_SYNC = True

pymongo/synchronous/auth.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
TYPE_CHECKING,
2525
Any,
2626
Callable,
27+
Coroutine,
2728
Mapping,
2829
MutableMapping,
2930
Optional,
@@ -32,6 +33,12 @@
3233
from urllib.parse import quote
3334

3435
from bson.binary import Binary
36+
from pymongo.synchronous.auth_aws import _authenticate_aws
37+
from pymongo.synchronous.auth_oidc import (
38+
_authenticate_oidc,
39+
_get_authenticator,
40+
)
41+
from pymongo.synchronous.helpers import _getaddrinfo
3542
from pymongo.auth_shared import (
3643
MongoCredential,
3744
_authenticate_scram_start,
@@ -40,16 +47,10 @@
4047
)
4148
from pymongo.errors import ConfigurationError, OperationFailure
4249
from pymongo.saslprep import saslprep
43-
from pymongo.synchronous.auth_aws import _authenticate_aws
44-
from pymongo.synchronous.auth_oidc import (
45-
_authenticate_oidc,
46-
_get_authenticator,
47-
)
48-
from pymongo.synchronous.helpers import _getaddrinfo
4950

5051
if TYPE_CHECKING:
51-
from pymongo.hello import Hello
5252
from pymongo.synchronous.pool import Connection
53+
from pymongo.hello import Hello
5354

5455
HAVE_KERBEROS = True
5556
_USE_PRINCIPAL = False
@@ -68,7 +69,9 @@
6869
_IS_SYNC = True
6970

7071

71-
def _authenticate_scram(credentials: MongoCredential, conn: Connection, mechanism: str) -> None:
72+
def _authenticate_scram(
73+
credentials: MongoCredential, conn: Connection, mechanism: str
74+
) -> None:
7275
"""Authenticate using SCRAM."""
7376
username = credentials.username
7477
if mechanism == "SCRAM-SHA-256":
@@ -348,7 +351,9 @@ def _authenticate_default(credentials: MongoCredential, conn: Connection) -> Non
348351
source = credentials.source
349352
cmd = conn.hello_cmd()
350353
cmd["saslSupportedMechs"] = source + "." + credentials.username
351-
mechs = (conn.command(source, cmd, publish_events=False)).get("saslSupportedMechs", [])
354+
mechs = (conn.command(source, cmd, publish_events=False)).get(
355+
"saslSupportedMechs", []
356+
)
352357
if "SCRAM-SHA-256" in mechs:
353358
return _authenticate_scram(credentials, conn, "SCRAM-SHA-256")
354359
else:

pymongo/synchronous/auth_aws.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
if TYPE_CHECKING:
2525
from bson.typings import _ReadableBuffer
26-
from pymongo.auth_shared import MongoCredential
2726
from pymongo.synchronous.pool import Connection
27+
from pymongo.auth_shared import MongoCredential
2828

2929
_IS_SYNC = True
3030

pymongo/synchronous/auth_oidc.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
from pymongo.lock import Lock, _create_lock
4141

4242
if TYPE_CHECKING:
43-
from pymongo.auth_shared import MongoCredential
4443
from pymongo.synchronous.pool import Connection
44+
from pymongo.auth_shared import MongoCredential
4545

4646
_IS_SYNC = True
4747

@@ -231,7 +231,9 @@ def _get_access_token(self) -> Optional[str]:
231231

232232
return self.access_token
233233

234-
def _run_command(self, conn: Connection, cmd: MutableMapping[str, Any]) -> Mapping[str, Any]:
234+
def _run_command(
235+
self, conn: Connection, cmd: MutableMapping[str, Any]
236+
) -> Mapping[str, Any]:
235237
try:
236238
return conn.command("$external", cmd, no_reauth=True) # type: ignore[call-arg]
237239
except OperationFailure as e:

pymongo/synchronous/bulk.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
from bson.objectid import ObjectId
3737
from bson.raw_bson import RawBSONDocument
3838
from pymongo import _csot, common
39+
from pymongo.synchronous.client_session import ClientSession, _validate_session_write_concern
40+
from pymongo.synchronous.helpers import _handle_reauth
3941
from pymongo.bulk_shared import (
4042
_COMMANDS,
4143
_DELETE_ALL,
@@ -67,8 +69,6 @@
6769
_randint,
6870
)
6971
from pymongo.read_preferences import ReadPreference
70-
from pymongo.synchronous.client_session import ClientSession, _validate_session_write_concern
71-
from pymongo.synchronous.helpers import _handle_reauth
7272
from pymongo.write_concern import WriteConcern
7373

7474
if TYPE_CHECKING:
@@ -614,7 +614,9 @@ def retryable_bulk(
614614
_raise_bulk_write_error(full_result)
615615
return full_result
616616

617-
def execute_op_msg_no_results(self, conn: Connection, generator: Iterator[Any]) -> None:
617+
def execute_op_msg_no_results(
618+
self, conn: Connection, generator: Iterator[Any]
619+
) -> None:
618620
"""Execute write commands with OP_MSG and w=0 writeConcern, unordered."""
619621
db_name = self.collection.database.name
620622
client = self.collection.database.client

pymongo/synchronous/change_stream.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
from bson.raw_bson import RawBSONDocument
2323
from bson.timestamp import Timestamp
2424
from pymongo import _csot, common
25+
from pymongo.synchronous.aggregation import (
26+
_AggregationCommand,
27+
_CollectionAggregationCommand,
28+
_DatabaseAggregationCommand,
29+
)
30+
from pymongo.synchronous.command_cursor import CommandCursor
2531
from pymongo.collation import validate_collation_or_none
2632
from pymongo.errors import (
2733
ConnectionFailure,
@@ -31,12 +37,6 @@
3137
PyMongoError,
3238
)
3339
from pymongo.operations import _Op
34-
from pymongo.synchronous.aggregation import (
35-
_AggregationCommand,
36-
_CollectionAggregationCommand,
37-
_DatabaseAggregationCommand,
38-
)
39-
from pymongo.synchronous.command_cursor import CommandCursor
4040
from pymongo.typings import _CollationIn, _DocumentType, _Pipeline
4141

4242
_IS_SYNC = True
@@ -235,7 +235,9 @@ def _process_result(self, result: Mapping[str, Any], conn: Connection) -> None:
235235
f"response : {result!r}"
236236
)
237237

238-
def _run_aggregation_cmd(self, session: Optional[ClientSession]) -> CommandCursor: # type: ignore[type-arg]
238+
def _run_aggregation_cmd(
239+
self, session: Optional[ClientSession]
240+
) -> CommandCursor: # type: ignore[type-arg]
239241
"""Run the full aggregation pipeline for this ChangeStream and return
240242
the corresponding CommandCursor.
241243
"""

pymongo/synchronous/client_bulk.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,9 @@ def _execute_batch(
426426
) -> tuple[dict[str, Any], list[Mapping[str, Any]], list[Mapping[str, Any]]]:
427427
"""Executes a batch of bulkWrite server commands (ack)."""
428428
request_id, msg, to_send_ops, to_send_ns = bwc.batch_command(cmd, ops, namespaces)
429-
result = self.write_command(bwc, cmd, request_id, msg, to_send_ops, to_send_ns, self.client) # type: ignore[arg-type]
429+
result = self.write_command(
430+
bwc, cmd, request_id, msg, to_send_ops, to_send_ns, self.client
431+
) # type: ignore[arg-type]
430432
return result, to_send_ops, to_send_ns # type: ignore[return-value]
431433

432434
def _process_results_cursor(

pymongo/synchronous/client_session.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@
142142
from typing import (
143143
TYPE_CHECKING,
144144
Any,
145-
Callable,
146145
ContextManager,
146+
Awaitable,
147+
Callable,
147148
Mapping,
148149
MutableMapping,
149150
NoReturn,
@@ -156,6 +157,7 @@
156157
from bson.int64 import Int64
157158
from bson.timestamp import Timestamp
158159
from pymongo import _csot
160+
from pymongo.synchronous.cursor_base import _ConnectionManager
159161
from pymongo.errors import (
160162
ConfigurationError,
161163
ConnectionFailure,
@@ -168,7 +170,6 @@
168170
from pymongo.read_concern import ReadConcern
169171
from pymongo.read_preferences import ReadPreference, _ServerMode
170172
from pymongo.server_type import SERVER_TYPE
171-
from pymongo.synchronous.cursor_base import _ConnectionManager
172173
from pymongo.write_concern import WriteConcern
173174

174175
if TYPE_CHECKING:
@@ -703,7 +704,9 @@ def callback(session, custom_arg, custom_kwarg=None):
703704
"""
704705
start_time = time.monotonic()
705706
while True:
706-
self.start_transaction(read_concern, write_concern, read_preference, max_commit_time_ms)
707+
self.start_transaction(
708+
read_concern, write_concern, read_preference, max_commit_time_ms
709+
)
707710
try:
708711
ret = callback(self)
709712
# Catch KeyboardInterrupt, CancelledError, etc. and cleanup.

0 commit comments

Comments
 (0)