Merge "Fix extra new line that break from progress bar"
This commit is contained in:
commit
ac6c0d8742
@ -58,8 +58,10 @@ class VerboseFileWrapper(_ProgressBarBase):
|
|||||||
if data:
|
if data:
|
||||||
self._display_progress_bar(len(data))
|
self._display_progress_bar(len(data))
|
||||||
else:
|
else:
|
||||||
# Break to a new line from the progress bar for incoming output.
|
if self._show_progress:
|
||||||
sys.stdout.write('\n')
|
# Break to a new line from the progress bar for incoming
|
||||||
|
# output.
|
||||||
|
sys.stdout.write('\n')
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
@ -82,6 +84,8 @@ class VerboseIteratorWrapper(_ProgressBarBase):
|
|||||||
self._display_progress_bar(len(data))
|
self._display_progress_bar(len(data))
|
||||||
return data
|
return data
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
# Break to a new line from the progress bar for incoming output.
|
if self._show_progress:
|
||||||
sys.stdout.write('\n')
|
# Break to a new line from the progress bar for incoming
|
||||||
|
# output.
|
||||||
|
sys.stdout.write('\n')
|
||||||
raise
|
raise
|
||||||
|
@ -34,8 +34,8 @@ class TestProgressBarWrapper(testtools.TestCase):
|
|||||||
data = list(progressbar.VerboseIteratorWrapper(iterator, size))
|
data = list(progressbar.VerboseIteratorWrapper(iterator, size))
|
||||||
self.assertEqual(data, ['X'] * 100)
|
self.assertEqual(data, ['X'] * 100)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
output.getvalue().strip(),
|
output.getvalue(),
|
||||||
'[%s>] 100%%' % ('=' * 29)
|
'[%s>] 100%%\n' % ('=' * 29)
|
||||||
)
|
)
|
||||||
finally:
|
finally:
|
||||||
sys.stdout = saved_stdout
|
sys.stdout = saved_stdout
|
||||||
@ -52,8 +52,24 @@ class TestProgressBarWrapper(testtools.TestCase):
|
|||||||
while chunk:
|
while chunk:
|
||||||
chunk = file_obj.read(chunksize)
|
chunk = file_obj.read(chunksize)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
output.getvalue().strip(),
|
output.getvalue(),
|
||||||
'[%s>] 100%%' % ('=' * 29)
|
'[%s>] 100%%\n' % ('=' * 29)
|
||||||
)
|
)
|
||||||
finally:
|
finally:
|
||||||
sys.stdout = saved_stdout
|
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)
|
self.seek(0)
|
||||||
data = data[1:]
|
data = data[1:]
|
||||||
return StringIO.StringIO.write(self, data)
|
return StringIO.StringIO.write(self, data)
|
||||||
|
|
||||||
|
|
||||||
|
class FakeNoTTYStdout(FakeTTYStdout):
|
||||||
|
"""A Fake stdout that is not a TTY device."""
|
||||||
|
|
||||||
|
def isatty(self):
|
||||||
|
return False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user