Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

RemoteOperations::path_exists is updated #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions testgres/operations/remote_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
26 changes: 16 additions & 10 deletions tests/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down