Skip to content

Commit 230e562

Browse files
RemoteOperations::listdir is corrected (#217)
- It returns list[str] - New asserts are added Tests for listdir are updated.
1 parent e3eb6ae commit 230e562

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

Diff for: testgres/operations/remote_ops.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,12 @@ def listdir(self, path):
277277
Args:
278278
path (str): The path to the directory.
279279
"""
280-
result = self.exec_command("ls {}".format(path))
281-
return result.splitlines()
280+
command = ["ls", path]
281+
output = self.exec_command(cmd=command, encoding=get_default_encoding())
282+
assert type(output) == str # noqa: E721
283+
result = output.splitlines()
284+
assert type(result) == list # noqa: E721
285+
return result
282286

283287
def path_exists(self, path):
284288
command = ["test", "-e", path]

Diff for: tests/test_local.py

+11
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ def test_exec_command_failure__expect_error(self):
8787
assert b"nonexistent_command" in error
8888
assert b"not found" in error
8989

90+
def test_listdir(self):
91+
"""
92+
Test listdir for listing directory contents.
93+
"""
94+
path = "/etc"
95+
files = self.operations.listdir(path)
96+
assert isinstance(files, list)
97+
for f in files:
98+
assert f is not None
99+
assert type(f) == str # noqa: E721
100+
90101
def test_read__text(self):
91102
"""
92103
Test LocalOperations::read for text data.

Diff for: tests/test_remote.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,10 @@ def test_listdir(self):
222222
"""
223223
path = "/etc"
224224
files = self.operations.listdir(path)
225-
226225
assert isinstance(files, list)
226+
for f in files:
227+
assert f is not None
228+
assert type(f) == str # noqa: E721
227229

228230
def test_path_exists_true__directory(self):
229231
"""

0 commit comments

Comments
 (0)