Skip to content

Commit 85fb722

Browse files
authored
PYTHON-5886 - Fix synchro bug caused by ruff upgrade (mongodb#2878)
1 parent f69cc44 commit 85fb722

7 files changed

Lines changed: 18 additions & 30 deletions

File tree

test/asynchronous/test_encryption.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2922,7 +2922,7 @@ async def encrypt_and_cast(i):
29222922
EncryptionError, "expected matching 'min' and value type. Got range option"
29232923
):
29242924
await self.client_encryption.encrypt(
2925-
6 if cast_func is int else float(6),
2925+
6 if cast_func is not int else float(6),
29262926
key_id=self.key1_id,
29272927
algorithm=Algorithm.RANGE,
29282928
contention_factor=0,

test/asynchronous/test_pooling.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,13 @@ async def test_no_wait_queue_timeout(self):
346346
async with pool.checkout() as s1:
347347
t = SocketGetter(self.c, pool)
348348
await t.start()
349-
while t.state != "get_socket": # noqa: ASYNC110
349+
while t.state != "get_socket": # noqa: ASYNC110, RUF100
350350
await asyncio.sleep(0.1)
351351

352352
await asyncio.sleep(1)
353353
self.assertEqual(t.state, "get_socket")
354354

355-
while t.state != "connection": # noqa: ASYNC110
355+
while t.state != "connection": # noqa: ASYNC110, RUF100
356356
await asyncio.sleep(0.1)
357357

358358
self.assertEqual(t.state, "connection")
@@ -521,7 +521,7 @@ async def test_pool_backpressure_preserves_existing_connections(self):
521521
await coll.insert_many([{"x": 1} for _ in range(10)])
522522
t = SocketGetter(self.c, pool)
523523
await t.start()
524-
while t.state != "connection": # noqa: ASYNC110
524+
while t.state != "connection": # noqa: ASYNC110, RUF100
525525
await asyncio.sleep(0.1)
526526

527527
assert not t.sock.conn_closed()

test/asynchronous/utils_spec_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ async def _create_tests(self):
160160
dirname = os.path.split(dirpath)[-1]
161161

162162
for filename in filenames:
163-
with open(os.path.join(dirpath, filename)) as scenario_stream: # noqa: ASYNC230
163+
with open(os.path.join(dirpath, filename)) as scenario_stream: # noqa: ASYNC230, RUF100
164164
# Use tz_aware=False to match how CodecOptions decodes
165165
# dates.
166166
opts = json_util.JSONOptions(tz_aware=False)

test/test_client_metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def test_doesnt_update_established_connections(self):
193193
)
194194

195195
# send initial metadata
196-
name, version, platform, _ = self.send_ping_and_get_metadata(client, True)
196+
name, version, platform, _metadata = self.send_ping_and_get_metadata(client, True)
197197
self.assertIsNotNone(name)
198198
self.assertIsNotNone(version)
199199
self.assertIsNotNone(platform)

test/test_pooling.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,13 @@ def test_no_wait_queue_timeout(self):
346346
with pool.checkout() as s1:
347347
t = SocketGetter(self.c, pool)
348348
t.start()
349-
while t.state != "get_socket":
349+
while t.state != "get_socket": # noqa: ASYNC110, RUF100
350350
time.sleep(0.1)
351351

352352
time.sleep(1)
353353
self.assertEqual(t.state, "get_socket")
354354

355-
while t.state != "connection":
355+
while t.state != "connection": # noqa: ASYNC110, RUF100
356356
time.sleep(0.1)
357357

358358
self.assertEqual(t.state, "connection")
@@ -519,7 +519,7 @@ def test_pool_backpressure_preserves_existing_connections(self):
519519
coll.insert_many([{"x": 1} for _ in range(10)])
520520
t = SocketGetter(self.c, pool)
521521
t.start()
522-
while t.state != "connection":
522+
while t.state != "connection": # noqa: ASYNC110, RUF100
523523
time.sleep(0.1)
524524

525525
assert not t.sock.conn_closed()

test/utils_spec_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def _create_tests(self):
160160
dirname = os.path.split(dirpath)[-1]
161161

162162
for filename in filenames:
163-
with open(os.path.join(dirpath, filename)) as scenario_stream: # noqa: RUF100
163+
with open(os.path.join(dirpath, filename)) as scenario_stream: # noqa: ASYNC230, RUF100
164164
# Use tz_aware=False to match how CodecOptions decodes
165165
# dates.
166166
opts = json_util.JSONOptions(tz_aware=False)

tools/synchro.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -171,22 +171,14 @@
171171
if not Path.exists(Path(_gridfs_dest_base)):
172172
Path.mkdir(Path(_gridfs_dest_base))
173173

174-
async_files = [
175-
_pymongo_base + str(f)
176-
for f in Path.iterdir(Path(_pymongo_base))
177-
if (Path(_pymongo_base) / f).is_file()
178-
]
174+
async_files = [_pymongo_base + f.name for f in Path(_pymongo_base).iterdir() if f.is_file()]
179175

180-
gridfs_files = [
181-
_gridfs_base + str(f)
182-
for f in Path.iterdir(Path(_gridfs_base))
183-
if (Path(_gridfs_base) / f).is_file()
184-
]
176+
gridfs_files = [_gridfs_base + f.name for f in Path(_gridfs_base).iterdir() if f.is_file()]
185177

186178

187179
def async_only_test(f: Path) -> bool:
188180
"""Return True for async tests that should not be converted to sync."""
189-
return str(f) in [
181+
return f.name in [
190182
"test_locks.py",
191183
"test_concurrency.py",
192184
"test_async_cancellation.py",
@@ -197,9 +189,9 @@ def async_only_test(f: Path) -> bool:
197189

198190

199191
test_files = [
200-
_test_base + str(f)
201-
for f in Path.iterdir(Path(_test_base))
202-
if (Path(_test_base) / f).is_file() and not async_only_test(f)
192+
_test_base + f.name
193+
for f in Path(_test_base).iterdir()
194+
if f.is_file() and not async_only_test(f)
203195
]
204196

205197
# Add each asynchronized test here as part of the converting PR
@@ -453,15 +445,11 @@ def main() -> None:
453445
unasync_directory(test_files, _test_base, _test_dest_base, replacements)
454446

455447
sync_files = [
456-
_pymongo_dest_base + str(f)
457-
for f in Path.iterdir(Path(_pymongo_dest_base))
458-
if (Path(_pymongo_dest_base) / f).is_file()
448+
_pymongo_dest_base + f.name for f in Path(_pymongo_dest_base).iterdir() if f.is_file()
459449
]
460450

461451
sync_gridfs_files = [
462-
_gridfs_dest_base + str(f)
463-
for f in Path.iterdir(Path(_gridfs_dest_base))
464-
if (Path(_gridfs_dest_base) / f).is_file()
452+
_gridfs_dest_base + f.name for f in Path(_gridfs_dest_base).iterdir() if f.is_file()
465453
]
466454
sync_test_files = [
467455
_test_dest_base + f for f in converted_tests if (Path(_test_dest_base) / f).is_file()

0 commit comments

Comments
 (0)