-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Coverage for 'gcloud._apitools.buffered_stream' #1192
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# pylint: skip-file | ||
import unittest2 | ||
|
||
|
||
class Test_BufferedStream(unittest2.TestCase): | ||
|
||
def _getTargetClass(self): | ||
from gcloud._apitools.buffered_stream import BufferedStream | ||
return BufferedStream | ||
|
||
def _makeOne(self, *args, **kw): | ||
return self._getTargetClass()(*args, **kw) | ||
|
||
def test_ctor_start_zero_longer_than_buffer(self): | ||
from io import BytesIO | ||
CONTENT = b'CONTENT GOES HERE' | ||
START = 0 | ||
BUFSIZE = 4 | ||
stream = BytesIO(CONTENT) | ||
bufstream = self._makeOne(stream, START, BUFSIZE) | ||
self.assertTrue(bufstream._stream is stream) | ||
self.assertEqual(bufstream._start_pos, START) | ||
self.assertEqual(bufstream._buffer_pos, 0) | ||
self.assertEqual(bufstream._buffered_data, CONTENT[:BUFSIZE]) | ||
self.assertEqual(len(bufstream), BUFSIZE) | ||
self.assertFalse(bufstream.stream_exhausted) | ||
self.assertEqual(bufstream.stream_end_position, BUFSIZE) | ||
|
||
def test_ctor_start_nonzero_shorter_than_buffer(self): | ||
from io import BytesIO | ||
CONTENT = b'CONTENT GOES HERE' | ||
START = 8 | ||
BUFSIZE = 10 | ||
stream = BytesIO(CONTENT) | ||
stream.read(START) # already consumed | ||
bufstream = self._makeOne(stream, START, BUFSIZE) | ||
self.assertTrue(bufstream._stream is stream) | ||
self.assertEqual(bufstream._start_pos, START) | ||
self.assertEqual(bufstream._buffer_pos, 0) | ||
self.assertEqual(bufstream._buffered_data, CONTENT[START:]) | ||
self.assertEqual(len(bufstream), len(CONTENT) - START) | ||
self.assertTrue(bufstream.stream_exhausted) | ||
self.assertEqual(bufstream.stream_end_position, len(CONTENT)) | ||
|
||
def test__bytes_remaining_start_zero_longer_than_buffer(self): | ||
from io import BytesIO | ||
CONTENT = b'CONTENT GOES HERE' | ||
START = 0 | ||
BUFSIZE = 4 | ||
stream = BytesIO(CONTENT) | ||
bufstream = self._makeOne(stream, START, BUFSIZE) | ||
self.assertEqual(bufstream._bytes_remaining, BUFSIZE) | ||
|
||
def test__bytes_remaining_start_zero_shorter_than_buffer(self): | ||
from io import BytesIO | ||
CONTENT = b'CONTENT GOES HERE' | ||
START = 8 | ||
BUFSIZE = 10 | ||
stream = BytesIO(CONTENT) | ||
stream.read(START) # already consumed | ||
bufstream = self._makeOne(stream, START, BUFSIZE) | ||
self.assertEqual(bufstream._bytes_remaining, len(CONTENT) - START) | ||
|
||
def test_read_w_none(self): | ||
from io import BytesIO | ||
from gcloud._apitools.exceptions import NotYetImplementedError | ||
CONTENT = b'CONTENT GOES HERE' | ||
START = 0 | ||
BUFSIZE = 4 | ||
stream = BytesIO(CONTENT) | ||
bufstream = self._makeOne(stream, START, BUFSIZE) | ||
with self.assertRaises(NotYetImplementedError): | ||
bufstream.read(None) | ||
|
||
def test_read_w_negative_size(self): | ||
from io import BytesIO | ||
from gcloud._apitools.exceptions import NotYetImplementedError | ||
CONTENT = b'CONTENT GOES HERE' | ||
START = 0 | ||
BUFSIZE = 4 | ||
stream = BytesIO(CONTENT) | ||
bufstream = self._makeOne(stream, START, BUFSIZE) | ||
with self.assertRaises(NotYetImplementedError): | ||
bufstream.read(-2) | ||
|
||
def test_read_from_start(self): | ||
from io import BytesIO | ||
CONTENT = b'CONTENT GOES HERE' | ||
START = 0 | ||
BUFSIZE = 4 | ||
stream = BytesIO(CONTENT) | ||
bufstream = self._makeOne(stream, START, BUFSIZE) | ||
self.assertEqual(bufstream.read(4), CONTENT[:4]) | ||
|
||
def test_read_exhausted(self): | ||
from io import BytesIO | ||
CONTENT = b'CONTENT GOES HERE' | ||
START = len(CONTENT) | ||
BUFSIZE = 10 | ||
stream = BytesIO(CONTENT) | ||
stream.read(START) # already consumed | ||
bufstream = self._makeOne(stream, START, BUFSIZE) | ||
self.assertTrue(bufstream.stream_exhausted) | ||
self.assertEqual(bufstream.stream_end_position, len(CONTENT)) | ||
self.assertEqual(bufstream._bytes_remaining, 0) | ||
self.assertEqual(bufstream.read(10), b'') | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.