Skip to content

Commit 7e36cff

Browse files
Add File.is_executable (#688)
* Add File.is_executable * Add missing documentation for File properties
1 parent a51062b commit 7e36cff

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

test/test_modules.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,10 @@ def test_file(host):
363363
host.check_output("rm -f /d/p && mkfifo /d/p")
364364
assert host.file("/d/p").is_pipe
365365

366+
host.check_output("chmod 700 /d/f")
367+
assert f.is_executable
368+
assert f.mode == 0o700
369+
366370

367371
def test_ansible_unavailable(host):
368372
expected = "Ansible module is only available with " "ansible connection backend"

testinfra/modules/file.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,32 @@ def exists(self):
3636

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

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

47+
@property
48+
def is_executable(self):
49+
"""Test if the path exists and permission to execute is granted"""
50+
return self.run_test("test -x %s", self.path).rc == 0
51+
4552
@property
4653
def is_pipe(self):
54+
"""Test if the path exists and is a pipe"""
4755
return self.run_test("test -p %s", self.path).rc == 0
4856

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

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

5767
@property
@@ -86,10 +96,12 @@ def uid(self):
8696

8797
@property
8898
def group(self):
99+
"""Return file group name as string"""
89100
raise NotImplementedError
90101

91102
@property
92103
def gid(self):
104+
"""Return file group id as integer"""
93105
raise NotImplementedError
94106

95107
@property
@@ -124,10 +136,12 @@ def contains(self, pattern):
124136

125137
@property
126138
def md5sum(self):
139+
"""Compute the MD5 message digest of the file content"""
127140
raise NotImplementedError
128141

129142
@property
130143
def sha256sum(self):
144+
"""Compute the SHA256 message digest of the file content"""
131145
raise NotImplementedError
132146

133147
def _get_content(self, decode):

0 commit comments

Comments
 (0)