Merge pull request #453 from clayadavis/master
Raise TypeError when cursor is not provided a callable
This commit is contained in:
commit
97f78fd89b
2 changed files with 17 additions and 0 deletions
|
|
@ -356,3 +356,15 @@ class TwythonAPITestCase(unittest.TestCase):
|
||||||
tweet_text = self.api.html_for_tweet(test_tweet_extended_object)
|
tweet_text = self.api.html_for_tweet(test_tweet_extended_object)
|
||||||
# full tweet rendered with suffix
|
# full tweet rendered with suffix
|
||||||
self.assertEqual(test_tweet_extended_html, tweet_text)
|
self.assertEqual(test_tweet_extended_html, tweet_text)
|
||||||
|
|
||||||
|
def test_cursor_requires_twython_function(self):
|
||||||
|
"""Test that cursor() raises when called without a Twython function"""
|
||||||
|
def init_and_iterate_cursor(*args, **kwargs):
|
||||||
|
cursor = self.api.cursor(*args, **kwargs)
|
||||||
|
return next(cursor)
|
||||||
|
|
||||||
|
non_function = object()
|
||||||
|
non_twython_function = lambda x: x
|
||||||
|
|
||||||
|
self.assertRaises(TypeError, init_and_iterate_cursor, non_function)
|
||||||
|
self.assertRaises(TwythonError, init_and_iterate_cursor, non_twython_function)
|
||||||
|
|
|
||||||
|
|
@ -470,6 +470,11 @@ class Twython(EndpointsMixin, object):
|
||||||
>>> print result
|
>>> print result
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
if not callable(function):
|
||||||
|
raise TypeError('.cursor() takes a Twython function as its first \
|
||||||
|
argument. Did you provide the result of a \
|
||||||
|
function call?')
|
||||||
|
|
||||||
if not hasattr(function, 'iter_mode'):
|
if not hasattr(function, 'iter_mode'):
|
||||||
raise TwythonError('Unable to create generator for Twython \
|
raise TwythonError('Unable to create generator for Twython \
|
||||||
method "%s"' % function.__name__)
|
method "%s"' % function.__name__)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue