Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.

Commit 23fe329

Browse files
author
ekmartin
committed
fix(run): Remove whitespace removal from run()
BREAKING CHANGE: Removal of whitespace prefix and suffix from stdout and stderr is removed.
1 parent e3cd556 commit 23fe329

3 files changed

Lines changed: 23 additions & 12 deletions

File tree

docker/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def execute(cmd, stdin=''):
3434
)
3535

3636
(stdout, stderr) = process.communicate(str.encode(stdin))
37-
result.out = stdout.decode('utf-8').strip() if stdout else ''
38-
result.err = stderr.decode('utf-8').strip() if stderr else ''
37+
result.out = stdout.decode('utf-8') if stdout else ''
38+
result.err = stderr.decode('utf-8') if stderr else ''
3939
result.return_code = process.returncode
4040
logger.debug('Finished running of: {0}'.format(result.__dict__))
4141
return result

docker/manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def list_files(self, path):
187187

188188
raise errors.DockerWrapperBaseError(result.err)
189189

190-
return result.out.split('\n')
190+
return result.out.strip().split('\n')
191191

192192
def list_directories(self, path, include_trailing_slash=True):
193193
"""
@@ -211,7 +211,7 @@ def list_directories(self, path, include_trailing_slash=True):
211211

212212
raise errors.DockerWrapperBaseError(result.err)
213213

214-
for file_path in result.out.split(', '):
214+
for file_path in result.out.strip().split(', '):
215215
if include_trailing_slash:
216216
files.append(file_path)
217217
else:

tests/test_manager.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,8 @@ def test_create_and_list_files_in_sub_directory(self):
207207

208208
def test_read_file_with_content(self):
209209
file_name = 'readme.txt'
210-
file_content = 'this is a test file {0}'.format(randint(5000, 5500))
211-
self.docker.run('echo \"{0}\" > ~/{1}; cat readme.txt'.format(file_content, file_name))
212-
210+
file_content = 'this is a test file {0}\n'.format(randint(5000, 5500))
211+
self.docker.write_file(file_name, file_content)
213212
self.assertEqual(self.docker.read_file(file_name), file_content)
214213

215214
def test_read_file_that_dont_exist(self):
@@ -221,6 +220,17 @@ def test_read_file_that_dont_exist(self):
221220
path
222221
)
223222

223+
def test_read_file_eof_newline(self):
224+
path = '/etc/hostname'
225+
content = self.docker.read_file(path)
226+
self.assertTrue(content.endswith('\n'))
227+
228+
def test_write_file_read_file(self):
229+
path = 'testfile'
230+
content = 'this is a nice file\n'
231+
self.docker.write_file(path, content)
232+
self.assertEqual(content, self.docker.read_file(path))
233+
224234
def test_directory_exist(self):
225235
self.assertTrue(self.docker.directory_exist('~/'))
226236
self.assertFalse(self.docker.directory_exist('does-not-exist'))
@@ -234,15 +244,16 @@ def test_combine_output(self):
234244
self.docker.combine_outputs = True
235245
result = self.docker.run('ls does-not-exist')
236246
self.assertEqual(result.err, '')
237-
self.assertEqual(result.out, 'ls: cannot access does-not-exist: No such file or directory')
247+
self.assertEqual(result.out,
248+
'ls: cannot access does-not-exist: No such file or directory\n')
238249

239250
def test_privilege(self):
240251
Docker(privilege=True).start()
241252

242253
def test_write_file_append(self):
243254
path = 'readme.txt'
244-
old_content = 'hi'
245-
content = 'this is a readme'
255+
old_content = 'hi\n'
256+
content = 'this is a readme\n'
246257
self.docker.run('echo "{0}" > {1}'.format(old_content, path))
247258

248259
self.docker.write_file(path, content, append=True)
@@ -252,7 +263,7 @@ def test_write_file_append(self):
252263
def test_write_file_no_append(self):
253264
path = 'readme.txt'
254265
old_content = 'hi'
255-
content = 'this is a readme'
266+
content = 'this is a readme\n'
256267
self.docker.run('echo "{0}" > {1}'.format(old_content, path))
257268

258269
self.docker.write_file(path, content, append=False)
@@ -261,7 +272,7 @@ def test_write_file_no_append(self):
261272

262273
def test_write_file_quotes(self):
263274
path = 'readme.txt'
264-
content = 'this is a "readme"'
275+
content = 'this is a "readme"\n'
265276

266277
self.docker.write_file(path, content, append=False)
267278
written_content = self.docker.read_file(path)

0 commit comments

Comments
 (0)