12
12
from pathlib import Path , PurePath
13
13
from stat import S_IWGRP , S_IWOTH , S_IWUSR , filemode
14
14
from types import TracebackType
15
- from typing import TYPE_CHECKING , Any , Callable , Iterator , Tuple , Type , Union
15
+ from typing import TYPE_CHECKING , Any , Callable , Union
16
16
from uuid import uuid4
17
17
from weakref import WeakValueDictionary
18
18
21
21
from filelock import BaseFileLock , FileLock , SoftFileLock , Timeout , UnixFileLock , WindowsFileLock
22
22
23
23
if TYPE_CHECKING :
24
+ from collections .abc import Iterator
25
+
24
26
from pytest_mock import MockerFixture
25
27
26
28
@@ -218,7 +220,7 @@ def test_nested_contruct(lock_type: type[BaseFileLock], tmp_path: Path) -> None:
218
220
assert not lock_1 .is_locked
219
221
220
222
221
- _ExcInfoType = Union [Tuple [ Type [BaseException ], BaseException , TracebackType ], Tuple [None , None , None ]]
223
+ _ExcInfoType = Union [tuple [ type [BaseException ], BaseException , TracebackType ], tuple [None , None , None ]]
222
224
223
225
224
226
class ExThread (threading .Thread ):
@@ -304,7 +306,7 @@ def test_timeout(lock_type: type[BaseFileLock], tmp_path: Path) -> None:
304
306
assert not lock_2 .is_locked
305
307
306
308
# try to acquire lock 2
307
- with pytest .raises (Timeout , match = "The file lock '.*' could not be acquired." ):
309
+ with pytest .raises (Timeout , match = r "The file lock '.*' could not be acquired." ):
308
310
lock_2 .acquire (timeout = 0.1 )
309
311
assert not lock_2 .is_locked
310
312
assert lock_1 .is_locked
@@ -333,44 +335,44 @@ def test_non_blocking(lock_type: type[BaseFileLock], tmp_path: Path) -> None:
333
335
assert not lock_5 .is_locked
334
336
335
337
# try to acquire lock 2
336
- with pytest .raises (Timeout , match = "The file lock '.*' could not be acquired." ):
338
+ with pytest .raises (Timeout , match = r "The file lock '.*' could not be acquired." ):
337
339
lock_2 .acquire (blocking = False )
338
340
assert not lock_2 .is_locked
339
341
assert lock_1 .is_locked
340
342
341
343
# try to acquire pre-parametrized `blocking=False` lock 3 with `acquire`
342
- with pytest .raises (Timeout , match = "The file lock '.*' could not be acquired." ):
344
+ with pytest .raises (Timeout , match = r "The file lock '.*' could not be acquired." ):
343
345
lock_3 .acquire ()
344
346
assert not lock_3 .is_locked
345
347
assert lock_1 .is_locked
346
348
347
349
# try to acquire pre-parametrized `blocking=False` lock 3 with context manager
348
- with pytest .raises (Timeout , match = "The file lock '.*' could not be acquired." ), lock_3 :
350
+ with pytest .raises (Timeout , match = r "The file lock '.*' could not be acquired." ), lock_3 :
349
351
pass
350
352
assert not lock_3 .is_locked
351
353
assert lock_1 .is_locked
352
354
353
355
# try to acquire pre-parametrized `timeout=0` lock 4 with `acquire`
354
- with pytest .raises (Timeout , match = "The file lock '.*' could not be acquired." ):
356
+ with pytest .raises (Timeout , match = r "The file lock '.*' could not be acquired." ):
355
357
lock_4 .acquire ()
356
358
assert not lock_4 .is_locked
357
359
assert lock_1 .is_locked
358
360
359
361
# try to acquire pre-parametrized `timeout=0` lock 4 with context manager
360
- with pytest .raises (Timeout , match = "The file lock '.*' could not be acquired." ), lock_4 :
362
+ with pytest .raises (Timeout , match = r "The file lock '.*' could not be acquired." ), lock_4 :
361
363
pass
362
364
assert not lock_4 .is_locked
363
365
assert lock_1 .is_locked
364
366
365
367
# blocking precedence over timeout
366
368
# try to acquire pre-parametrized `timeout=-1,blocking=False` lock 5 with `acquire`
367
- with pytest .raises (Timeout , match = "The file lock '.*' could not be acquired." ):
369
+ with pytest .raises (Timeout , match = r "The file lock '.*' could not be acquired." ):
368
370
lock_5 .acquire ()
369
371
assert not lock_5 .is_locked
370
372
assert lock_1 .is_locked
371
373
372
374
# try to acquire pre-parametrized `timeout=-1,blocking=False` lock 5 with context manager
373
- with pytest .raises (Timeout , match = "The file lock '.*' could not be acquired." ), lock_5 :
375
+ with pytest .raises (Timeout , match = r "The file lock '.*' could not be acquired." ), lock_5 :
374
376
pass
375
377
assert not lock_5 .is_locked
376
378
assert lock_1 .is_locked
@@ -397,15 +399,15 @@ def test_default_timeout(lock_type: type[BaseFileLock], tmp_path: Path) -> None:
397
399
assert not lock_2 .is_locked
398
400
399
401
# try to acquire lock 2
400
- with pytest .raises (Timeout , match = "The file lock '.*' could not be acquired." ):
402
+ with pytest .raises (Timeout , match = r "The file lock '.*' could not be acquired." ):
401
403
lock_2 .acquire ()
402
404
assert not lock_2 .is_locked
403
405
assert lock_1 .is_locked
404
406
405
407
lock_2 .timeout = 0
406
408
assert lock_2 .timeout == 0
407
409
408
- with pytest .raises (Timeout , match = "The file lock '.*' could not be acquired." ):
410
+ with pytest .raises (Timeout , match = r "The file lock '.*' could not be acquired." ):
409
411
lock_2 .acquire ()
410
412
assert not lock_2 .is_locked
411
413
assert lock_1 .is_locked
@@ -459,7 +461,7 @@ def test_del(lock_type: type[BaseFileLock], tmp_path: Path) -> None:
459
461
assert not lock_2 .is_locked
460
462
461
463
# try to acquire lock 2
462
- with pytest .raises (Timeout , match = "The file lock '.*' could not be acquired." ):
464
+ with pytest .raises (Timeout , match = r "The file lock '.*' could not be acquired." ):
463
465
lock_2 .acquire (timeout = 0.1 )
464
466
465
467
# delete lock 1 and try to acquire lock 2 again
0 commit comments