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
82import os
3+ from pathlib import Path
4+ from typing import Any , Union # pylint: disable = unused-import
95
106from .utils import print_err
117
8+
129def _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
2724def 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
3330def 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