Skip to content

Commit b4d5206

Browse files
committed
PR feedback
Signed-off-by: Bernát Gábor <[email protected]>
1 parent 8d297c9 commit b4d5206

File tree

7 files changed

+25
-33
lines changed

7 files changed

+25
-33
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ repos:
5454
- id: flake8
5555
additional_dependencies:
5656
- flake8-bugbear==23.3.23
57-
- flake8-comprehensions==3.11.1
57+
- flake8-comprehensions==3.12
5858
- flake8-pytest-style==1.7.2
5959
- flake8-spellcheck==0.28
6060
- flake8-unused-arguments==0.0.13

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ dynamic = [
3737
optional-dependencies.docs = [
3838
"furo>=2023.3.27",
3939
"sphinx>=6.1.3",
40-
"sphinx-autodoc-typehints!=1.23.4,>=1.22",
40+
"sphinx-autodoc-typehints!=1.23.4,>=1.23",
4141
]
4242
optional-dependencies.testing = [
4343
"covdefaults>=2.3",
4444
"coverage>=7.2.3",
4545
"diff-cover>=7.5",
46-
"pytest>=7.2.2",
46+
"pytest>=7.3.1",
4747
"pytest-cov>=4",
4848
"pytest-mock>=3.10",
4949
"pytest-timeout>=2.1",

src/filelock/_soft.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
from errno import EACCES, EEXIST
66

77
from ._api import BaseFileLock
8-
from ._util import raise_unwritable_file
8+
from ._util import raise_on_not_writable_file
99

1010

1111
class SoftFileLock(BaseFileLock):
1212
"""Simply watches the existence of the lock file."""
1313

1414
def _acquire(self) -> None:
15-
raise_unwritable_file(self._lock_file)
15+
raise_on_not_writable_file(self._lock_file)
1616
# first check for exists and read-only mode as the open will mask this case as EEXIST
1717
flags = (
1818
os.O_WRONLY # open for writing only

src/filelock/_util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from errno import EACCES, EISDIR
77

88

9-
def raise_unwritable_file(filename: str) -> None:
9+
def raise_on_not_writable_file(filename: str) -> None:
1010
"""
1111
Raise an exception if attempting to open the file for writing would fail.
1212
This is done so files that will never be writable can be separated from
@@ -33,5 +33,5 @@ def raise_unwritable_file(filename: str) -> None:
3333

3434

3535
__all__ = [
36-
"raise_unwritable_file",
36+
"raise_on_not_writable_file",
3737
]

src/filelock/_windows.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import cast
77

88
from ._api import BaseFileLock
9-
from ._util import raise_unwritable_file
9+
from ._util import raise_on_not_writable_file
1010

1111
if sys.platform == "win32": # pragma: win32 cover
1212
import msvcrt
@@ -15,7 +15,7 @@ class WindowsFileLock(BaseFileLock):
1515
"""Uses the :func:`msvcrt.locking` function to hard lock the lock file on windows systems."""
1616

1717
def _acquire(self) -> None:
18-
raise_unwritable_file(self._lock_file)
18+
raise_on_not_writable_file(self._lock_file)
1919
flags = (
2020
os.O_RDWR # open for read and write
2121
| os.O_CREAT # create file if not exists

tests/test_filelock.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -112,32 +112,25 @@ def test_ro_file(lock_type: type[BaseFileLock], tmp_file_ro: Path) -> None:
112112
lock.acquire()
113113

114114

115-
if sys.platform == "win32":
116-
# filenames that will raise errors
117-
bad_lock_file_errors: list[tuple[type[Exception], str, str]] = [
118-
(FileNotFoundError, "No such file or directory:", "a/b"), # non-existent directory
119-
(FileNotFoundError, "No such file or directory:", ""), # blank filename
120-
(PermissionError, "Permission denied:", "."), # current directory
121-
(PermissionError, "Permission denied:", "/"), # root directory
122-
(OSError, "Invalid argument", '<>:"/\\|?*\a'), # invalid characters
123-
(ValueError, "embedded null (byte|character)", "\0"), # null character
124-
]
125-
else:
126-
# filenames that will raise errors
127-
bad_lock_file_errors: list[tuple[type[Exception], str, str]] = [
128-
(FileNotFoundError, "No such file or directory:", "a/b"), # non-existent directory
129-
(FileNotFoundError, "No such file or directory:", ""), # blank filename
130-
(IsADirectoryError, "Is a directory", "."), # current directory
131-
(IsADirectoryError, "Is a directory", "/"), # root directory
132-
(ValueError, "embedded null (byte|character)", "\0"), # null byte
133-
]
134-
135-
136115
@pytest.mark.parametrize("lock_type", [FileLock, SoftFileLock])
137116
@pytest.mark.parametrize(
138117
("expected_error", "match", "bad_lock_file"),
139-
bad_lock_file_errors,
140-
ids=[e[0].__name__ for e in bad_lock_file_errors],
118+
[
119+
pytest.param(FileNotFoundError, "No such file or directory:", "a/b", id="non_existent_directory"),
120+
pytest.param(FileNotFoundError, "No such file or directory:", "", id="blank_filename"),
121+
pytest.param(ValueError, "embedded null (byte|character)", "\0", id="null_byte"),
122+
pytest.param(
123+
PermissionError if sys.platform == "win32" else IsADirectoryError,
124+
"Permission denied:" if sys.platform == "win32" else "Is a directory",
125+
".",
126+
id="current_directory",
127+
),
128+
]
129+
+ (
130+
[pytest.param(OSError, "Invalid argument", i, id=f"invalid_{i}") for i in '<>:"/\\|?*\a']
131+
if sys.platform == "win32"
132+
else []
133+
),
141134
)
142135
@pytest.mark.timeout(5) # timeout in case of infinite loop
143136
def test_bad_lock_file(

whitelist.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,4 @@ stacklevel
3636
trunc
3737
typehints
3838
unlck
39-
unwritable
4039
win32

0 commit comments

Comments
 (0)