Skip to content
Open
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
3 changes: 1 addition & 2 deletions TwitterSearch/TwitterSearch/TwitterSearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,7 @@ def getSearchResults(self, order):
"""
Temporary method just to demonstrate Java-like API naming for future refactoring
"""
results = TwitterSearchResults(self.search_tweets(order))
return results
return TwitterSearchResults(self.search_tweets(order))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TwitterSearch.getSearchResults refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)


def connect(self):
"""
Expand Down
5 changes: 1 addition & 4 deletions TwitterSearch/TwitterSearch/TwitterSearchException.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ class TwitterSearchException(Exception):

def __init__(self, code, msg=None):
self.code = code
if msg:
self.message = msg
else:
self.message = self._error_codes.get(code)
self.message = msg if msg else self._error_codes.get(code)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TwitterSearchException.__init__ refactored with the following changes:

  • Replace if statement with if expression (assign-if-exp)


def __str__(self):
return "Error %i: %s" % (self.code, self.message)
5 changes: 1 addition & 4 deletions TwitterSearch/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ def readme():
return f.read()

def requirements():
req = []
for line in open('requirements.txt','r'):
req.append(line.split()[0])
return req
return [line.split()[0] for line in open('requirements.txt','r')]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function requirements refactored with the following changes:

  • Convert for loop into list comprehension (list-comprehension)
  • Inline variable that is immediately returned (inline-immediately-returned-variable)


setup(name='TwitterSearch',
version='1.0.1',
Expand Down
7 changes: 3 additions & 4 deletions TwitterSearch/tests/test_ts.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def createTS(self):
def apiAnsweringMachine(self, filename):
""" Generates faked API responses by returing content of a given file """
f = open(filename, 'r')
for line in f:
yield line
yield from f
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TwitterSearchTest.apiAnsweringMachine refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)

f.close()

def setUp(self):
Expand Down Expand Up @@ -116,7 +115,7 @@ def test_TS_search_usertimeline_iterable(self):
tuo = self.createTUO()
tweet_cnt = 0

for tweet in ts.search_tweets_iterable(tuo):
for _ in ts.search_tweets_iterable(tuo):
Comment on lines -119 to +118
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TwitterSearchTest.test_TS_search_usertimeline_iterable refactored with the following changes:

  • Replace unused for index with underscore (for-index-underscore)

tweet_cnt += 1

# test statistics
Expand Down Expand Up @@ -176,7 +175,7 @@ def test_TS_search_tweets_iterable(self):
ts = self.createTS()

tweet_cnt = 0
for tweet in ts.search_tweets_iterable(tso):
for _ in ts.search_tweets_iterable(tso):
Comment on lines -179 to +178
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TwitterSearchTest.test_TS_search_tweets_iterable refactored with the following changes:

  • Replace unused for index with underscore (for-index-underscore)

tweet_cnt += 1

self.assertEqual( (cnt*4-1), tweet_cnt, "Wrong amount of tweets")
Expand Down
12 changes: 6 additions & 6 deletions TwitterSearch/tests/test_tso.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_TSO_maxID(self):
""" Tests TwitterSearchOrder.set_max_id() """

tso = self.getCopy()
correct_values = [ self.generateInt(1,999999999) for x in range(0,10) ]
correct_values = [self.generateInt(1,999999999) for x in range(10)]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TwitterSearchOrderTest.test_TSO_maxID refactored with the following changes:

  • Replace range(0, x) with range(x) (remove-zero-from-range)


for value in correct_values:
tso.set_max_id(value)
Expand All @@ -121,7 +121,7 @@ def test_TSO_sinceID(self):
""" Tests TwitterSearchOrder.set_since_id() """

tso = self.getCopy()
correct_values = [ self.generateInt(1,999999999) for x in range(0,10) ]
correct_values = [self.generateInt(1,999999999) for x in range(10)]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TwitterSearchOrderTest.test_TSO_sinceID refactored with the following changes:

  • Replace range(0, x) with range(x) (remove-zero-from-range)


for value in correct_values:
tso.set_since_id(value)
Expand Down Expand Up @@ -162,7 +162,7 @@ def test_TSO_geo(self):
tso.set_geocode( value, value, radius, imperial_metric=unit)
self.assertTrue(False, "Not raising exception for lat %s, lon %s, radius %s and metric %s" % (value,value,radius,unit))
except TwitterSearchException as e:
self.assertTrue((e.code == 1004 or e.code == 1005), "Wrong exception code")
self.assertTrue(e.code in [1004, 1005], "Wrong exception code")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TwitterSearchOrderTest.test_TSO_geo refactored with the following changes:

  • Replace multiple comparisons of same variable with in operator (merge-comparisons)


try:
tso.set_geocode(2.0,1.0,10, imperial_metric='foo')
Expand All @@ -178,7 +178,7 @@ def test_TSO_count(self):
""" Tests TwitterSearchOrder.set_count() """

tso = self.getCopy()
correct_values = [ self.generateInt(minimum=1,maximum=100) for x in range(0,10) ]
correct_values = [self.generateInt(minimum=1,maximum=100) for x in range(10)]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TwitterSearchOrderTest.test_TSO_count refactored with the following changes:

  • Replace range(0, x) with range(x) (remove-zero-from-range)


for value in correct_values:
tso.set_count(value)
Expand All @@ -198,7 +198,7 @@ def test_TSO_callback(self):
""" Tests TwitterSearchOrder.set_callback() """

tso = self.getCopy()
correct_values = [ self.generateString() for x in range(0,10) ]
correct_values = [self.generateString() for x in range(10)]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TwitterSearchOrderTest.test_TSO_callback refactored with the following changes:

  • Replace range(0, x) with range(x) (remove-zero-from-range)


for value in correct_values:
tso.set_callback(value)
Expand Down Expand Up @@ -417,10 +417,10 @@ def test_TSO_setURL(self):
def test_TO_exceptions(self):
""" Tests unimplemented TwitterOrder functions aiming for exceptions """

value = "foo"
exc_class = NotImplementedError
to = TwitterOrder()
with self.assertRaises(exc_class):
value = "foo"
Comment on lines -420 to +423
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TwitterSearchOrderTest.test_TO_exceptions refactored with the following changes:

  • Move assignments closer to their usage (move-assign)

to.set_search_url(value)
to.create_search_url()

3 changes: 1 addition & 2 deletions after/backends/ny_times.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ def _get_results(self):
return response.json()['results']

def _prepare_request_data(self):
data = {
return {
'query': self.movie,
'api-key': self.api_key
}
return data
Comment on lines -34 to -38
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function NYTimesReviews._prepare_request_data refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)



class Review(BaseReview):
Expand Down