Skip to content

Commit 3a1d08b

Browse files
RemoteOperations::path_exists is updated (#206)
- command is passed through list - we process all the result codes of test
1 parent e1a5bb4 commit 3a1d08b

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

testgres/operations/remote_ops.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,30 @@ def listdir(self, path):
247247
return result.splitlines()
248248

249249
def path_exists(self, path):
250-
result = self.exec_command("test -e {}; echo $?".format(path), encoding=get_default_encoding())
251-
return int(result.strip()) == 0
250+
command = ["test", "-e", path]
251+
252+
exit_status, output, error = self.exec_command(cmd=command, encoding=get_default_encoding(), ignore_errors=True, verbose=True)
253+
254+
assert type(output) == str # noqa: E721
255+
assert type(error) == str # noqa: E721
256+
257+
if exit_status == 0:
258+
return True
259+
260+
if exit_status == 1:
261+
return False
262+
263+
errMsg = "Test operation returns an unknown result code: {0}. Path is [{1}].".format(
264+
exit_status,
265+
path)
266+
267+
RaiseError.CommandExecutionError(
268+
cmd=command,
269+
exit_code=exit_status,
270+
msg_arg=errMsg,
271+
error=error,
272+
out=output
273+
)
252274

253275
@property
254276
def pathsep(self):

tests/test_remote.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,23 +130,29 @@ def test_listdir(self):
130130

131131
assert isinstance(files, list)
132132

133-
def test_path_exists_true(self):
133+
def test_path_exists_true__directory(self):
134134
"""
135-
Test path_exists for an existing path.
135+
Test path_exists for an existing directory.
136136
"""
137-
path = "/etc"
138-
response = self.operations.path_exists(path)
137+
assert self.operations.path_exists("/etc") is True
139138

140-
assert response is True
139+
def test_path_exists_true__file(self):
140+
"""
141+
Test path_exists for an existing file.
142+
"""
143+
assert self.operations.path_exists(__file__) is True
141144

142-
def test_path_exists_false(self):
145+
def test_path_exists_false__directory(self):
143146
"""
144-
Test path_exists for a non-existing path.
147+
Test path_exists for a non-existing directory.
145148
"""
146-
path = "/nonexistent_path"
147-
response = self.operations.path_exists(path)
149+
assert self.operations.path_exists("/nonexistent_path") is False
148150

149-
assert response is False
151+
def test_path_exists_false__file(self):
152+
"""
153+
Test path_exists for a non-existing file.
154+
"""
155+
assert self.operations.path_exists("/etc/nonexistent_path.txt") is False
150156

151157
def test_write_text_file(self):
152158
"""

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy