mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Handle case when executable is not executable
- Changed error message if executable is not executable Closes:[1159](https://github.com/pre-commit/pre-commit/issues/1159)
This commit is contained in:
parent
bb108bf00e
commit
95dbf1190a
2 changed files with 12 additions and 2 deletions
|
|
@ -51,10 +51,12 @@ def normexe(orig):
|
||||||
if exe is None:
|
if exe is None:
|
||||||
_error('not found')
|
_error('not found')
|
||||||
return exe
|
return exe
|
||||||
elif not os.access(orig, os.X_OK):
|
|
||||||
_error('not found')
|
|
||||||
elif os.path.isdir(orig):
|
elif os.path.isdir(orig):
|
||||||
_error('is a directory')
|
_error('is a directory')
|
||||||
|
elif not os.path.isfile(orig):
|
||||||
|
_error('not found')
|
||||||
|
elif not os.access(orig, os.X_OK): # pragma: windows no cover
|
||||||
|
_error('is not executable')
|
||||||
else:
|
else:
|
||||||
return orig
|
return orig
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,14 @@ def test_normexe_does_not_exist_sep():
|
||||||
assert excinfo.value.args == ('Executable `./i-dont-exist-lol` not found',)
|
assert excinfo.value.args == ('Executable `./i-dont-exist-lol` not found',)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.xfail(os.name == 'nt', reason='posix only',)
|
||||||
|
def test_normexe_not_executable(tmpdir): # pragma: windows no cover
|
||||||
|
tmpdir.join('exe').ensure()
|
||||||
|
with tmpdir.as_cwd(), pytest.raises(OSError) as excinfo:
|
||||||
|
parse_shebang.normexe('./exe')
|
||||||
|
assert excinfo.value.args == ('Executable `./exe` is not executable',)
|
||||||
|
|
||||||
|
|
||||||
def test_normexe_is_a_directory(tmpdir):
|
def test_normexe_is_a_directory(tmpdir):
|
||||||
with tmpdir.as_cwd():
|
with tmpdir.as_cwd():
|
||||||
tmpdir.join('exe').ensure_dir()
|
tmpdir.join('exe').ensure_dir()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue