Skip to content

Commit 54f3adf

Browse files
committed
add/update tests
1 parent b350801 commit 54f3adf

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,3 +814,12 @@ def __init__(self, file_path: str) -> None:
814814
lock_path = tmp_path / "a"
815815
lock = FilePathLock(str(lock_path))
816816
assert lock.lock_file == str(lock_path) + ".lock"
817+
818+
819+
@pytest.mark.parametrize("lock_type", [FileLock, SoftFileLock])
820+
def test_lock_is_removed(tmp_path: Path, lock_type: type[BaseFileLock]) -> None:
821+
lock_path = tmp_path / "test.lock"
822+
lock = lock_type(lock_path)
823+
with lock:
824+
assert Path.exists(lock_path)
825+
assert not Path.exists(lock_path)

0 commit comments

Comments
 (0)