Skip to content
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

Fix branch coverage miss in 'gcloud.streaming.transfer'. #1994

Merged
merged 1 commit into from
Jul 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion gcloud/streaming/test_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1429,7 +1429,7 @@ def test_stream_file_already_complete_w_seekable_stream_unsynced(self):
with self.assertRaises(CommunicationError):
upload.stream_file()

def test_stream_file_already_complete_w_seekable_stream_synced(self):
def test_stream_file_already_complete_wo_seekable_method_synced(self):
import os
from gcloud.streaming.transfer import RESUMABLE_UPLOAD
CONTENT = b'ABCDEFGHIJ'
Expand All @@ -1445,6 +1445,38 @@ def test_stream_file_already_complete_w_seekable_stream_synced(self):
upload._complete = True
self.assertTrue(upload.stream_file(use_chunks=False) is response)

def test_stream_file_already_complete_w_seekable_method_true_synced(self):
import os
from gcloud.streaming.transfer import RESUMABLE_UPLOAD
CONTENT = b'ABCDEFGHIJ'
http = object()
stream = _StreamWithSeekableMethod(CONTENT, True)
stream.seek(0, os.SEEK_END)
response = object()
upload = self._makeOne(stream, chunksize=1024)
upload.strategy = RESUMABLE_UPLOAD
upload._server_chunk_granularity = 128
upload._initialize(http, _Request.URL)
upload._final_response = response
upload._complete = True
self.assertTrue(upload.stream_file(use_chunks=False) is response)

def test_stream_file_already_complete_w_seekable_method_false(self):
import os
from gcloud.streaming.transfer import RESUMABLE_UPLOAD
CONTENT = b'ABCDEFGHIJ'
http = object()
stream = _StreamWithSeekableMethod(CONTENT, False)
stream.seek(0, os.SEEK_END)
response = object()
upload = self._makeOne(stream, chunksize=1024)
upload.strategy = RESUMABLE_UPLOAD
upload._server_chunk_granularity = 128
upload._initialize(http, _Request.URL)
upload._final_response = response
upload._complete = True
self.assertTrue(upload.stream_file(use_chunks=False) is response)

def test_stream_file_incomplete(self):
from six.moves import http_client
from gcloud._testing import _Monkey
Expand Down Expand Up @@ -1835,6 +1867,16 @@ def close(self):
self._closed = True


class _StreamWithSeekableMethod(_Stream):

def __init__(self, to_read=b'', seekable=True):
super(_StreamWithSeekableMethod, self).__init__(to_read)
self._seekable = seekable

def seekable(self):
return self._seekable


class _Request(object):
__slots__ = ('url', 'http_method', 'body', 'headers', 'loggable_body')
URL = 'http://example.com/api'
Expand Down
2 changes: 1 addition & 1 deletion scripts/run_pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
}
TEST_RC_REPLACEMENTS = {
'FORMAT': {
'max-module-lines': 1900,
'max-module-lines': 1950,
},
}

Expand Down