Skip to content

Commit bca8b4b

Browse files
author
Nils Bars
committed
Fix Path.exists() method calls in assertion functions
The exists, is_file, and is_dir attributes were being referenced without calling them as methods, causing assertions to always pass.
1 parent 45c7772 commit bca8b4b

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

ref_utils/assertion.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
"""Exception-free assert functions"""
2-
from pathlib import Path
3-
from typing import Any, Union # pylint: disable = unused-import
4-
5-
from .error import RefUtilsAssertionError
6-
7-
import signal
82
import os
3+
from pathlib import Path
4+
from typing import Any, Union # pylint: disable = unused-import
95

106
from .utils import print_err
117

8+
129
def _assert(condition: bool, error_msg: str, silent: bool) -> bool:
1310
"""Custom 'assertion' that prints a warning rather than throwing AssertionError"""
1411
if not condition:
@@ -21,17 +18,17 @@ def assert_is_exec(executable: Union[str, 'os.PathLike[Any]', Path], silent: boo
2118
"""Assert file exists and is executable"""
2219
if not isinstance(executable, Path):
2320
return assert_is_exec(Path(executable))
24-
return _assert(executable.exists and executable.is_file() and os.access(executable, os.X_OK),
21+
return _assert(executable.exists() and executable.is_file() and os.access(executable, os.X_OK),
2522
f"Executable file {executable} not found or not executable", silent)
2623

2724
def assert_is_file(file_: Union[str, 'os.PathLike[Any]', Path], silent: bool = False) -> bool:
2825
"""Assert file exists"""
2926
if not isinstance(file_, Path):
3027
return assert_is_file(Path(file_))
31-
return _assert(file_.exists and file_.is_file(), f"File {file_} not found", silent)
28+
return _assert(file_.exists() and file_.is_file(), f"File {file_} not found", silent)
3229

3330
def assert_is_dir(directory: Union[str, 'os.PathLike[Any]', Path], silent: bool = False) -> bool:
3431
"""Assert directory exists"""
3532
if not isinstance(directory, Path):
3633
return assert_is_dir(Path(directory))
37-
return _assert(directory.exists and directory.is_dir(), f"Directory {directory} not found", silent)
34+
return _assert(directory.exists() and directory.is_dir(), f"Directory {directory} not found", silent)

0 commit comments

Comments
 (0)