File tree Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Original file line number Diff line number Diff 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 ]
Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff 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 """
You can’t perform that action at this time.
0 commit comments