-
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.util' #1190
Merged
tseaver
merged 1 commit into
googleapis:master
from
tseaver:coverage-gcloud__apitools_util
Oct 25, 2015
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# pylint: skip-file | ||
import unittest2 | ||
|
||
|
||
class Test_TypeCheck(unittest2.TestCase): | ||
|
||
def _callFUT(self, *args, **kw): | ||
from gcloud._apitools.util import Typecheck | ||
return Typecheck(*args, **kw) | ||
|
||
def test_pass(self): | ||
self.assertEqual(self._callFUT(123, int), 123) | ||
|
||
def test_fail_w_explicit_msg(self): | ||
from gcloud._apitools.exceptions import TypecheckError | ||
with self.assertRaises(TypecheckError) as err: | ||
self._callFUT(123, str, 'foo') | ||
self.assertEqual(err.exception.args, ('foo',)) | ||
|
||
def test_fail_w_single_type_no_msg(self): | ||
from gcloud._apitools.exceptions import TypecheckError | ||
with self.assertRaises(TypecheckError) as err: | ||
self._callFUT(123, str) | ||
|
||
def test_fail_w_tuple_no_msg(self): | ||
from gcloud._apitools.exceptions import TypecheckError | ||
with self.assertRaises(TypecheckError) as err: | ||
self._callFUT(123, (list, tuple)) | ||
|
||
|
||
class Test_CalculateWaitForRetry(unittest2.TestCase): | ||
|
||
def _callFUT(self, *args, **kw): | ||
from gcloud._apitools.util import CalculateWaitForRetry | ||
return CalculateWaitForRetry(*args, **kw) | ||
|
||
def test_w_negative_jitter_lt_max_wait(self): | ||
import random | ||
from gcloud._testing import _Monkey | ||
with _Monkey(random, uniform=lambda lower, upper: lower): | ||
self.assertEqual(self._callFUT(1, 60), 1.5) | ||
|
||
def test_w_positive_jitter_gt_max_wait(self): | ||
import random | ||
from gcloud._testing import _Monkey | ||
with _Monkey(random, uniform=lambda lower, upper: upper): | ||
self.assertEqual(self._callFUT(4, 10), 10) | ||
|
||
|
||
class Test_AcceptableMimeType(unittest2.TestCase): | ||
|
||
def _callFUT(self, *args, **kw): | ||
from gcloud._apitools.util import AcceptableMimeType | ||
return AcceptableMimeType(*args, **kw) | ||
|
||
def test_pattern_wo_slash(self): | ||
from gcloud._apitools.exceptions import InvalidUserInputError | ||
with self.assertRaises(InvalidUserInputError) as err: | ||
self._callFUT(['text/*'], 'BOGUS') | ||
self.assertEqual( | ||
err.exception.args, | ||
('Invalid MIME type: "BOGUS"',)) | ||
|
||
def test_accept_pattern_w_semicolon(self): | ||
from gcloud._apitools.exceptions import GeneratedClientError | ||
with self.assertRaises(GeneratedClientError) as err: | ||
self._callFUT(['text/*;charset=utf-8'], 'text/plain') | ||
self.assertEqual( | ||
err.exception.args, | ||
('MIME patterns with parameter unsupported: ' | ||
'"text/*;charset=utf-8"',)) | ||
|
||
def test_miss(self): | ||
self.assertFalse(self._callFUT(['image/*'], 'text/plain')) | ||
|
||
def test_hit(self): | ||
self.assertTrue(self._callFUT(['text/*'], 'text/plain')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.