More tests, coverage, and excluding lines from being covered

There are some lines that will never be hit in tests, excluding those
from being covered!
This commit is contained in:
Mike Helmick 2013-06-27 22:37:02 -04:00
parent 00c0bd91a6
commit acdf73a04e
6 changed files with 45 additions and 10 deletions

View file

@ -169,13 +169,13 @@ class Twython(EndpointsMixin, object):
if errors and isinstance(errors, list):
error_message = errors[0]['message']
else:
error_message = errors
error_message = errors # pragma: no cover
self._last_call['api_error'] = error_message
ExceptionType = TwythonError
if response.status_code == 429:
# Twitter API 1.1, always return 429 when rate limit is exceeded
ExceptionType = TwythonRateLimitError
ExceptionType = TwythonRateLimitError # pragma: no cover
elif response.status_code == 401 or 'Bad Authentication data' in error_message:
# Twitter API 1.1, returns a 401 Unauthorized or
# a 400 "Bad Authentication data" for invalid/expired app keys/user tokens
@ -186,7 +186,7 @@ class Twython(EndpointsMixin, object):
retry_after=response.headers.get('retry-after'))
# if we have a json error here, then it's not an official Twitter API error
if json_error and not response.status_code in (200, 201, 202):
if json_error and not response.status_code in (200, 201, 202): # pragma: no cover
raise TwythonError('Response was not valid JSON, unable to decode.')
return content
@ -303,7 +303,7 @@ class Twython(EndpointsMixin, object):
if not authorized_tokens:
raise TwythonError('Unable to decode authorized tokens.')
return authorized_tokens
return authorized_tokens # pragma: no cover
def obtain_access_token(self):
"""Returns an OAuth 2 access token to make OAuth 2 authenticated read-only calls.
@ -387,7 +387,7 @@ class Twython(EndpointsMixin, object):
try:
if not 'since_id' in params:
params['since_id'] = (int(content['statuses'][0]['id_str']) + 1)
except (TypeError, ValueError):
except (TypeError, ValueError): # pragma: no cover
raise TwythonError('Unable to generate next page of search results, `page` is not a number.')
for tweet in self.search_gen(search_query, **params):

View file

@ -748,7 +748,7 @@ class EndpointsMixin(object):
return self.get('trends/closest', params=params)
# Spam Reporting
def report_spam(self, **params):
def report_spam(self, **params): # pragma: no cover
"""Report the specified user as a spam account to Twitter.
Docs: https://dev.twitter.com/docs/api/1.1/post/users/report_spam
@ -757,7 +757,7 @@ class EndpointsMixin(object):
return self.post('users/report_spam', params=params)
# OAuth
def invalidate_token(self, **params):
def invalidate_token(self, **params): # pragma: no cover
"""Allows a registered application to revoke an issued OAuth 2 Bearer
Token by presenting its client credentials.

View file

@ -132,13 +132,13 @@ class TwythonStreamer(object):
if is_py3:
line = line.decode('utf-8')
data = json.loads(line)
if self.on_success(data):
if self.on_success(data): # pragma: no cover
for message_type in self.handlers:
if message_type in data:
handler = getattr(self, 'on_' + message_type, None)
if handler and callable(handler) and not handler(data.get(message_type)):
break
except ValueError:
except ValueError: # pragma: no cover
self.on_error(response.status_code, 'Unable to decode response, not valid JSON.')
response.close()