diff --git a/testgres/operations/remote_ops.py b/testgres/operations/remote_ops.py index dc392bee..60d5265c 100644 --- a/testgres/operations/remote_ops.py +++ b/testgres/operations/remote_ops.py @@ -247,8 +247,30 @@ def listdir(self, path): return result.splitlines() def path_exists(self, path): - result = self.exec_command("test -e {}; echo $?".format(path), encoding=get_default_encoding()) - return int(result.strip()) == 0 + command = ["test", "-e", path] + + exit_status, output, error = self.exec_command(cmd=command, encoding=get_default_encoding(), ignore_errors=True, verbose=True) + + assert type(output) == str # noqa: E721 + assert type(error) == str # noqa: E721 + + if exit_status == 0: + return True + + if exit_status == 1: + return False + + errMsg = "Test operation returns an unknown result code: {0}. Path is [{1}].".format( + exit_status, + path) + + RaiseError.CommandExecutionError( + cmd=command, + exit_code=exit_status, + msg_arg=errMsg, + error=error, + out=output + ) @property def pathsep(self): diff --git a/tests/test_remote.py b/tests/test_remote.py index 6114e29e..85e65c24 100755 --- a/tests/test_remote.py +++ b/tests/test_remote.py @@ -130,23 +130,29 @@ def test_listdir(self): assert isinstance(files, list) - def test_path_exists_true(self): + def test_path_exists_true__directory(self): """ - Test path_exists for an existing path. + Test path_exists for an existing directory. """ - path = "/etc" - response = self.operations.path_exists(path) + assert self.operations.path_exists("/etc") is True - assert response is True + def test_path_exists_true__file(self): + """ + Test path_exists for an existing file. + """ + assert self.operations.path_exists(__file__) is True - def test_path_exists_false(self): + def test_path_exists_false__directory(self): """ - Test path_exists for a non-existing path. + Test path_exists for a non-existing directory. """ - path = "/nonexistent_path" - response = self.operations.path_exists(path) + assert self.operations.path_exists("/nonexistent_path") is False - assert response is False + def test_path_exists_false__file(self): + """ + Test path_exists for a non-existing file. + """ + assert self.operations.path_exists("/etc/nonexistent_path.txt") is False def test_write_text_file(self): """ 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