Merge "Downloading image with --progress fails for python3"
This commit is contained in:
@@ -471,6 +471,9 @@ class IterableWithLength(object):
|
|||||||
def next(self):
|
def next(self):
|
||||||
return next(self.iterable)
|
return next(self.iterable)
|
||||||
|
|
||||||
|
# In Python 3, __next__() has replaced next().
|
||||||
|
__next__ = next
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return self.length
|
return self.length
|
||||||
|
|
||||||
|
@@ -19,6 +19,7 @@ import six
|
|||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
from glanceclient.common import progressbar
|
from glanceclient.common import progressbar
|
||||||
|
from glanceclient.common import utils
|
||||||
from glanceclient.tests import utils as test_utils
|
from glanceclient.tests import utils as test_utils
|
||||||
|
|
||||||
|
|
||||||
@@ -26,12 +27,13 @@ class TestProgressBarWrapper(testtools.TestCase):
|
|||||||
|
|
||||||
def test_iter_iterator_display_progress_bar(self):
|
def test_iter_iterator_display_progress_bar(self):
|
||||||
size = 100
|
size = 100
|
||||||
iterator = iter('X' * 100)
|
iterator_with_len = utils.IterableWithLength(iter('X' * 100), size)
|
||||||
saved_stdout = sys.stdout
|
saved_stdout = sys.stdout
|
||||||
try:
|
try:
|
||||||
sys.stdout = output = test_utils.FakeTTYStdout()
|
sys.stdout = output = test_utils.FakeTTYStdout()
|
||||||
# Consume iterator.
|
# Consume iterator.
|
||||||
data = list(progressbar.VerboseIteratorWrapper(iterator, size))
|
data = list(progressbar.VerboseIteratorWrapper(iterator_with_len,
|
||||||
|
size))
|
||||||
self.assertEqual(['X'] * 100, data)
|
self.assertEqual(['X'] * 100, data)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'[%s>] 100%%\n' % ('=' * 29),
|
'[%s>] 100%%\n' % ('=' * 29),
|
||||||
|
Reference in New Issue
Block a user