ReSizeStream: reminder type
1. Change ReSizeStream.reminder type to bytes according to stream data type. 2. Add test for ReSizeStream 3. Also update ReSizeStream.read to use self.__next__() instead of nonexistent self.next(). Relates to change id I940841b94789d024d3b9447f96158963fe3e16ee where ReSizeStream.next() was renamed to ReSizeStream.__next__(). Story: 2010167 Task: 45860 Change-Id: I5eb70419d2ee795a18f67594e426b942e5390c7b
This commit is contained in:
parent
87a3daede5
commit
7a2a42c5af
freezer
@ -15,6 +15,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from io import BytesIO
|
||||
import os
|
||||
from unittest import mock
|
||||
|
||||
@ -211,7 +212,7 @@ class FakeGlanceClient(object):
|
||||
|
||||
@staticmethod
|
||||
def data(image):
|
||||
return glance_utils.IterableWithLength(iter("abc"), 3)
|
||||
return glance_utils.IterableWithLength(BytesIO(b"abc"), 3)
|
||||
|
||||
@staticmethod
|
||||
def delete(image):
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
import datetime
|
||||
import fixtures
|
||||
from io import BytesIO
|
||||
import os
|
||||
import time
|
||||
from unittest import mock
|
||||
@ -215,3 +216,30 @@ class TestDateTime(object):
|
||||
condition = mock.MagicMock(side_effect=[False, False, False])
|
||||
self.assertRaises(exception_utils.TimeoutException,
|
||||
utils.wait_for(condition, 0.1, 0.2))
|
||||
|
||||
|
||||
class TestReSizeStream(commons.FreezerBaseTestCase):
|
||||
def test_next(self):
|
||||
stream_data = b"12345"
|
||||
stream = BytesIO(stream_data)
|
||||
chunk_size = len(stream_data) - 1
|
||||
resize_stream = utils.ReSizeStream(
|
||||
stream=stream,
|
||||
length=len(stream_data),
|
||||
chunk_size=chunk_size,
|
||||
)
|
||||
next_result = next(resize_stream)
|
||||
self.assertEqual(chunk_size, len(next_result))
|
||||
self.assertEqual(stream_data[:chunk_size], next_result)
|
||||
self.assertIsInstance(next_result, bytes)
|
||||
|
||||
def test_read(self):
|
||||
stream_data = b"abcdef"
|
||||
chunk_size = 2
|
||||
resize_stream = utils.ReSizeStream(
|
||||
stream=BytesIO(stream_data),
|
||||
length=len(stream_data),
|
||||
chunk_size=chunk_size,
|
||||
)
|
||||
read_result = resize_stream.read(chunk_size)
|
||||
self.assertEqual(stream_data[:chunk_size], read_result)
|
||||
|
@ -254,7 +254,7 @@ class ReSizeStream(object):
|
||||
self.stream = stream
|
||||
self.length = length
|
||||
self.chunk_size = chunk_size
|
||||
self.reminder = ""
|
||||
self.reminder = bytes()
|
||||
self.transmitted = 0
|
||||
|
||||
def __len__(self):
|
||||
@ -287,7 +287,7 @@ class ReSizeStream(object):
|
||||
result = self.reminder
|
||||
if len(self.reminder) == 0:
|
||||
raise StopIteration()
|
||||
self.reminder = []
|
||||
self.reminder = bytes()
|
||||
self.transmitted += len(result)
|
||||
return result
|
||||
else:
|
||||
@ -298,7 +298,7 @@ class ReSizeStream(object):
|
||||
|
||||
def read(self, chunk_size):
|
||||
self.chunk_size = chunk_size
|
||||
return self.next()
|
||||
return self.__next__()
|
||||
|
||||
|
||||
def dequote(s):
|
||||
|
Loading…
x
Reference in New Issue
Block a user