Skip to content

Commit

Permalink
Add File.is_executable (#688)
Browse files Browse the repository at this point in the history
* Add File.is_executable

* Add missing documentation for File properties
  • Loading branch information
CarstenGrohmann committed May 19, 2023
1 parent a51062b commit 7e36cff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ def test_file(host):
host.check_output("rm -f /d/p && mkfifo /d/p")
assert host.file("/d/p").is_pipe

host.check_output("chmod 700 /d/f")
assert f.is_executable
assert f.mode == 0o700


def test_ansible_unavailable(host):
expected = "Ansible module is only available with " "ansible connection backend"
Expand Down
14 changes: 14 additions & 0 deletions testinfra/modules/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,32 @@ def exists(self):

@property
def is_file(self):
"""Test if the path is a regular file"""
return self.run_test("test -f %s", self.path).rc == 0

@property
def is_directory(self):
"""Test if the path exists and a directory"""
return self.run_test("test -d %s", self.path).rc == 0

@property
def is_executable(self):
"""Test if the path exists and permission to execute is granted"""
return self.run_test("test -x %s", self.path).rc == 0

@property
def is_pipe(self):
"""Test if the path exists and is a pipe"""
return self.run_test("test -p %s", self.path).rc == 0

@property
def is_socket(self):
"""Test if the path exists and is a socket"""
return self.run_test("test -S %s", self.path).rc == 0

@property
def is_symlink(self):
"""Test if the path exists and is a symbolic link"""
return self.run_test("test -L %s", self.path).rc == 0

@property
Expand Down Expand Up @@ -86,10 +96,12 @@ def uid(self):

@property
def group(self):
"""Return file group name as string"""
raise NotImplementedError

@property
def gid(self):
"""Return file group id as integer"""
raise NotImplementedError

@property
Expand Down Expand Up @@ -124,10 +136,12 @@ def contains(self, pattern):

@property
def md5sum(self):
"""Compute the MD5 message digest of the file content"""
raise NotImplementedError

@property
def sha256sum(self):
"""Compute the SHA256 message digest of the file content"""
raise NotImplementedError

def _get_content(self, decode):
Expand Down

0 comments on commit 7e36cff

Please sign in to comment.