Merge "Fix extra new line that break from progress bar"

This commit is contained in:
Jenkins 2013-12-20 23:38:10 +00:00 committed by Gerrit Code Review
commit ac6c0d8742
3 changed files with 35 additions and 8 deletions

@ -58,8 +58,10 @@ class VerboseFileWrapper(_ProgressBarBase):
if data:
self._display_progress_bar(len(data))
else:
# Break to a new line from the progress bar for incoming output.
sys.stdout.write('\n')
if self._show_progress:
# Break to a new line from the progress bar for incoming
# output.
sys.stdout.write('\n')
return data
@ -82,6 +84,8 @@ class VerboseIteratorWrapper(_ProgressBarBase):
self._display_progress_bar(len(data))
return data
except StopIteration:
# Break to a new line from the progress bar for incoming output.
sys.stdout.write('\n')
if self._show_progress:
# Break to a new line from the progress bar for incoming
# output.
sys.stdout.write('\n')
raise

@ -34,8 +34,8 @@ class TestProgressBarWrapper(testtools.TestCase):
data = list(progressbar.VerboseIteratorWrapper(iterator, size))
self.assertEqual(data, ['X'] * 100)
self.assertEqual(
output.getvalue().strip(),
'[%s>] 100%%' % ('=' * 29)
output.getvalue(),
'[%s>] 100%%\n' % ('=' * 29)
)
finally:
sys.stdout = saved_stdout
@ -52,8 +52,24 @@ class TestProgressBarWrapper(testtools.TestCase):
while chunk:
chunk = file_obj.read(chunksize)
self.assertEqual(
output.getvalue().strip(),
'[%s>] 100%%' % ('=' * 29)
output.getvalue(),
'[%s>] 100%%\n' % ('=' * 29)
)
finally:
sys.stdout = saved_stdout
def test_iter_file_no_tty(self):
size = 98304
file_obj = StringIO.StringIO('X' * size)
saved_stdout = sys.stdout
try:
sys.stdout = output = test_utils.FakeNoTTYStdout()
file_obj = progressbar.VerboseFileWrapper(file_obj, size)
chunksize = 1024
chunk = file_obj.read(chunksize)
while chunk:
chunk = file_obj.read(chunksize)
# If stdout is not a tty progress bar should do nothing.
self.assertEqual(output.getvalue(), '')
finally:
sys.stdout = saved_stdout

@ -110,3 +110,10 @@ class FakeTTYStdout(StringIO.StringIO):
self.seek(0)
data = data[1:]
return StringIO.StringIO.write(self, data)
class FakeNoTTYStdout(FakeTTYStdout):
"""A Fake stdout that is not a TTY device."""
def isatty(self):
return False