Skip to content

Commit a68263e

Browse files
committed
add/update tests
1 parent b350801 commit a68263e

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/filelock/_unix.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ class UnixFileLock(BaseFileLock):
3838

3939
def _acquire(self) -> None:
4040
ensure_directory_exists(self.lock_file)
41-
open_flags = os.O_RDWR | os.O_TRUNC
42-
if not Path(self.lock_file).exists():
43-
open_flags |= os.O_CREAT
41+
open_flags = os.O_RDWR | os.O_TRUNC | os.O_CREAT
4442
fd = os.open(self.lock_file, open_flags, self._context.mode)
4543
with suppress(PermissionError): # This locked is not owned by this UID
4644
os.fchmod(fd, self._context.mode)

tests/test_filelock.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import pytest
2020

2121
from filelock import BaseFileLock, FileLock, SoftFileLock, Timeout, UnixFileLock, WindowsFileLock
22+
import filelock
2223

2324
if TYPE_CHECKING:
2425
from collections.abc import Iterator
@@ -814,3 +815,12 @@ def __init__(self, file_path: str) -> None:
814815
lock_path = tmp_path / "a"
815816
lock = FilePathLock(str(lock_path))
816817
assert lock.lock_file == str(lock_path) + ".lock"
818+
819+
820+
@pytest.mark.parametrize("lock_type", [FileLock, SoftFileLock])
821+
def test_lock_is_removed(tmp_path: Path, lock_type: type[BaseFileLock]) -> None:
822+
lock_path = tmp_path / "test.lock"
823+
lock = lock_type(lock_path)
824+
with lock:
825+
assert Path.exists(lock_path)
826+
assert not Path.exists(lock_path)

0 commit comments

Comments
 (0)