|
2 | 2 |
|
3 | 3 | import inspect
|
4 | 4 | import logging
|
| 5 | +import os |
5 | 6 | import sys
|
6 | 7 | import threading
|
7 | 8 | from contextlib import contextmanager
|
8 | 9 | from inspect import getframeinfo, stack
|
9 | 10 | from pathlib import Path, PurePath
|
10 |
| -from stat import S_IWGRP, S_IWOTH, S_IWUSR |
| 11 | +from stat import S_IWGRP, S_IWOTH, S_IWUSR, filemode |
11 | 12 | from types import TracebackType
|
12 | 13 | from typing import Callable, Iterator, Tuple, Type, Union
|
13 | 14 |
|
@@ -418,6 +419,66 @@ def decorated_method() -> None:
|
418 | 419 | assert not lock.is_locked
|
419 | 420 |
|
420 | 421 |
|
| 422 | +def test_lock_mode(tmp_path: Path) -> None: |
| 423 | + lock_path = tmp_path / "a.lock" |
| 424 | + lock = FileLock(str(lock_path), mode=0o666) |
| 425 | + |
| 426 | + lock.acquire() |
| 427 | + assert lock.is_locked |
| 428 | + |
| 429 | + mode = filemode(os.stat(lock_path).st_mode) |
| 430 | + assert mode == "-rw-rw-rw-" |
| 431 | + |
| 432 | + lock.release() |
| 433 | + |
| 434 | + |
| 435 | +def test_lock_mode_soft(tmp_path: Path) -> None: |
| 436 | + lock_path = tmp_path / "a.lock" |
| 437 | + lock = SoftFileLock(str(lock_path), mode=0o666) |
| 438 | + |
| 439 | + lock.acquire() |
| 440 | + assert lock.is_locked |
| 441 | + |
| 442 | + mode = filemode(os.stat(lock_path).st_mode) |
| 443 | + assert mode == "-rw-rw-rw-" |
| 444 | + |
| 445 | + lock.release() |
| 446 | + |
| 447 | + |
| 448 | +def test_umask(tmp_path: Path) -> None: |
| 449 | + lock_path = tmp_path / "a.lock" |
| 450 | + lock = FileLock(str(lock_path), mode=0o666) |
| 451 | + |
| 452 | + initial_umask = os.umask(0) |
| 453 | + os.umask(initial_umask) |
| 454 | + |
| 455 | + lock.acquire() |
| 456 | + assert lock.is_locked |
| 457 | + |
| 458 | + current_umask = os.umask(0) |
| 459 | + os.umask(current_umask) |
| 460 | + assert initial_umask == current_umask |
| 461 | + |
| 462 | + lock.release() |
| 463 | + |
| 464 | + |
| 465 | +def test_umask_soft(tmp_path: Path) -> None: |
| 466 | + lock_path = tmp_path / "a.lock" |
| 467 | + lock = SoftFileLock(str(lock_path), mode=0o666) |
| 468 | + |
| 469 | + initial_umask = os.umask(0) |
| 470 | + os.umask(initial_umask) |
| 471 | + |
| 472 | + lock.acquire() |
| 473 | + assert lock.is_locked |
| 474 | + |
| 475 | + current_umask = os.umask(0) |
| 476 | + os.umask(current_umask) |
| 477 | + assert initial_umask == current_umask |
| 478 | + |
| 479 | + lock.release() |
| 480 | + |
| 481 | + |
421 | 482 | def test_wrong_platform(tmp_path: Path) -> None:
|
422 | 483 | assert not inspect.isabstract(UnixFileLock)
|
423 | 484 | assert not inspect.isabstract(WindowsFileLock)
|
|
0 commit comments