Skip to content

RemoteOperations::listdir is corrected #217

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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions testgres/operations/remote_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,12 @@ def listdir(self, path):
Args:
path (str): The path to the directory.
"""
result = self.exec_command("ls {}".format(path))
return result.splitlines()
command = ["ls", path]
output = self.exec_command(cmd=command, encoding=get_default_encoding())
assert type(output) == str # noqa: E721
result = output.splitlines()
assert type(result) == list # noqa: E721
return result

def path_exists(self, path):
command = ["test", "-e", path]
Expand Down
11 changes: 11 additions & 0 deletions tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ def test_exec_command_failure__expect_error(self):
assert b"nonexistent_command" in error
assert b"not found" in error

def test_listdir(self):
"""
Test listdir for listing directory contents.
"""
path = "/etc"
files = self.operations.listdir(path)
assert isinstance(files, list)
for f in files:
assert f is not None
assert type(f) == str # noqa: E721

def test_read__text(self):
"""
Test LocalOperations::read for text data.
Expand Down
4 changes: 3 additions & 1 deletion tests/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,10 @@ def test_listdir(self):
"""
path = "/etc"
files = self.operations.listdir(path)

assert isinstance(files, list)
for f in files:
assert f is not None
assert type(f) == str # noqa: E721

def test_path_exists_true__directory(self):
"""
Expand Down