Skip to content
This repository was archived by the owner on Aug 7, 2024. It is now read-only.

Commit dc32a98

Browse files
committed
serious flake8 lint cleanup; apologies for the extra large diffs
1 parent bc8dd1e commit dc32a98

18 files changed

+370
-382
lines changed

setup.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[check-manifest]
2+
ignore =
3+
.travis.yml
4+
violations.flake8.txt
5+
6+
[flake8]
7+
ignore = E111,E126,E201,E202,E221,E302,E501

tests/test_api.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# encoding: utf-8
22

3-
import twitter
3+
import os
44
import time
5+
import urllib
56
import unittest
7+
import twitter
68

79
from apikey import (CONSUMER_KEY,
810
CONSUMER_SECRET,
@@ -30,7 +32,7 @@ def testTwitterError(self):
3032
curry(self._OpenTestData, 'public_timeline_error.json'))
3133
# Manually try/catch so we can check the exception's value
3234
try:
33-
statuses = self._api.GetUserTimeline()
35+
self._api.GetUserTimeline()
3436
except twitter.TwitterError, error:
3537
# If the error message matches, the test passes
3638
self.assertEqual('test error', error.message)
@@ -48,7 +50,7 @@ def testGetUserTimeline(self):
4850
self.assertEqual(89512102, statuses[0].id)
4951
self.assertEqual(718443, statuses[0].user.id)
5052

51-
#def testGetFriendsTimeline(self):
53+
# def testGetFriendsTimeline(self):
5254
# '''Test the twitter.Api GetFriendsTimeline method'''
5355
# self._AddHandler('https://api.twitter.com/1.1/statuses/friends_timeline/kesuke.json',
5456
# curry(self._OpenTestData, 'friends_timeline-kesuke.json'))
@@ -101,7 +103,7 @@ def testPostUpdateLatLon(self):
101103
print 'Testing PostUpdateLatLon'
102104
self._AddHandler('https://api.twitter.com/1.1/statuses/update.json',
103105
curry(self._OpenTestData, 'update_latlong.json'))
104-
#test another update with geo parameters, again test somewhat arbitrary
106+
# test another update with geo parameters, again test somewhat arbitrary
105107
status = self._api.PostUpdate(u'Моё судно на воздушной подушке полно угрей'.encode('utf8'), latitude=54.2,
106108
longitude=-2)
107109
self.assertEqual(u'Моё судно на воздушной подушке полно угрей', status.text)
@@ -148,7 +150,7 @@ def testGetFollowers(self):
148150
alexkingorg = [u.status for u in users if u.screen_name == 'alexkingorg']
149151
self.assertEqual(89554432, alexkingorg[0].id)
150152

151-
#def testGetFeatured(self):
153+
# def testGetFeatured(self):
152154
# '''Test the twitter.Api GetFeatured method'''
153155
# self._AddHandler('https://api.twitter.com/1.1/statuses/featured.json',
154156
# curry(self._OpenTestData, 'featured.json'))
@@ -322,4 +324,3 @@ class MockHTTPBasicAuthHandler(object):
322324
def add_password(self, realm, uri, user, passwd):
323325
# TODO(dewitt): Add verification that the proper args are passed
324326
pass
325-

tests/test_parse_tweet.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,35 @@ class ParseTest(unittest.TestCase):
77
""" Test the ParseTweet class """
88

99
def testParseTweets(self):
10-
handles4 = u"""Do not use this word! Hurting me! @raja7727: @qadirbasha @manion @Jayks3 உடன்பிறப்பு”""";
10+
handles4 = u"""Do not use this word! Hurting me! @raja7727: @qadirbasha @manion @Jayks3 உடன்பிறப்பு”"""
1111

1212
data = twitter.ParseTweet("@twitter", handles4)
1313
self.assertEqual([data.RT, data.MT, len(data.UserHandles)], [False, False, 4])
1414

15-
hashtag_n_URL = u"மனதிற்கு மிகவும் நெருக்கமான பாடல்! உயிரையே கொடுக்கலாம் சார்! #KeladiKanmani https://www.youtube.com/watch?v=FHTiG_g2fM4 … #HBdayRajaSir";
15+
hashtag_n_URL = u"""மனதிற்கு மிகவும் நெருக்கமான பாடல்! உயிரையே கொடுக்கலாம் சார்! #KeladiKanmani https://www.youtube.com/watch?v=FHTiG_g2fM4 … #HBdayRajaSir"""
1616

1717
data = twitter.ParseTweet("@twitter", hashtag_n_URL)
1818
self.assertEqual([len(data.Hashtags), len(data.URLs)], [2, 1])
19-
self.assertEqual(len(data.Emoticon),0)
19+
self.assertEqual(len(data.Emoticon), 0)
2020

21-
url_only = u"""The #Rainbow #Nebula, 544,667 #lightyears away. pic.twitter.com/2A4wSUK25A""";
21+
url_only = u"""The #Rainbow #Nebula, 544,667 #lightyears away. pic.twitter.com/2A4wSUK25A"""
2222
data = twitter.ParseTweet("@twitter", url_only)
2323
self.assertEqual([data.MT, len(data.Hashtags), len(data.URLs)], [False, 3, 1])
24-
self.assertEqual(len(data.Emoticon),0)
24+
self.assertEqual(len(data.Emoticon), 0)
2525

26-
url_handle = u"""RT ‏@BarackObama POTUS recommends Python-Twitter #unrelated picture pic.twitter.com/w8lFIfuUmI""";
26+
url_handle = u"""RT ‏@BarackObama POTUS recommends Python-Twitter #unrelated picture pic.twitter.com/w8lFIfuUmI"""
2727
data = twitter.ParseTweet("@twitter", url_handle)
2828
self.assertEqual([data.RT, len(data.Hashtags), len(data.URLs), len(data.UserHandles)], [True, 1, 1, 1])
29-
self.assertEqual(len(data.Emoticon),0)
29+
self.assertEqual(len(data.Emoticon), 0)
3030

3131
def testEmoticon(self):
32-
url_handle = u"""RT ‏@BarackObama POTUS recommends :-) Python-Twitter #unrelated picture pic.twitter.com/w8lFIfuUmI""";
32+
url_handle = u"""RT ‏@BarackObama POTUS recommends :-) Python-Twitter #unrelated picture pic.twitter.com/w8lFIfuUmI"""
3333
data = twitter.ParseTweet("@twitter", url_handle)
3434
self.assertEqual([data.RT, len(data.Hashtags), len(data.URLs), len(data.UserHandles)], [True, 1, 1, 1])
35-
self.assertEqual(len(data.Emoticon),1)
35+
self.assertEqual(len(data.Emoticon), 1)
3636

37-
url_handle = u"""RT @cats ^-^ cute! But kitty litter :-( #unrelated picture""";
37+
url_handle = u"""RT @cats ^-^ cute! But kitty litter :-( #unrelated picture"""
3838
data = twitter.ParseTweet("@cats", url_handle)
3939
self.assertEqual([data.RT, len(data.Hashtags), len(data.URLs), len(data.UserHandles)], [True, 1, 0, 1])
40-
self.assertEqual(len(data.Emoticon),2)
41-
self.assertEqual(data.Emoticon,['^-^',':-('])
40+
self.assertEqual(len(data.Emoticon), 2)
41+
self.assertEqual(data.Emoticon, ['^-^', ':-('])

tests/test_status.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ def _GetSampleUser(self):
1717
description=u'Canvas. JC Penny. Three ninety-eight.',
1818
location='Okinawa, Japan',
1919
url='https://twitter.com/kesuke',
20-
profile_image_url='https://twitter.com/system/user/pro'
21-
'file_image/718443/normal/kesuke.pn'
22-
'g')
20+
profile_image_url='https://twitter.com/system/user/profile_image/718443/normal/kesuke.png')
2321

2422
def _GetSampleStatus(self):
2523
return twitter.Status(created_at='Fri Jan 26 23:17:14 +0000 2007',
@@ -29,10 +27,10 @@ def _GetSampleStatus(self):
2927

3028
def testInit(self):
3129
'''Test the twitter.Status constructor'''
32-
status = twitter.Status(created_at='Fri Jan 26 23:17:14 +0000 2007',
33-
id=4391023,
34-
text=u'A légpárnás hajóm tele van angolnákkal.',
35-
user=self._GetSampleUser())
30+
twitter.Status(created_at='Fri Jan 26 23:17:14 +0000 2007',
31+
id=4391023,
32+
text=u'A légpárnás hajóm tele van angolnákkal.',
33+
user=self._GetSampleUser())
3634

3735
def testProperties(self):
3836
'''Test all of the twitter.Status properties'''
@@ -117,7 +115,7 @@ def testNewFromJsonDict(self):
117115
data = json.loads(StatusTest.SAMPLE_JSON)
118116
status = twitter.Status.NewFromJsonDict(data)
119117
self.assertEqual(self._GetSampleStatus(), status)
120-
118+
121119
def testStatusRepresentation(self):
122120
status = self._GetSampleStatus()
123-
self.assertEqual("Status(ID=4391023, screen_name='kesuke', created_at='Fri Jan 26 23:17:14 +0000 2007')", status.__repr__())
121+
self.assertEqual("Status(ID=4391023, screen_name='kesuke', created_at='Fri Jan 26 23:17:14 +0000 2007')", status.__repr__())

tests/test_trend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ def _GetSampleTrend(self):
1313

1414
def testInit(self):
1515
'''Test the twitter.Trend constructor'''
16-
trend = twitter.Trend(name='Kesuke Miyagi',
17-
query='Kesuke Miyagi',
18-
timestamp='Fri Jan 26 23:17:14 +0000 2007')
16+
twitter.Trend(name='Kesuke Miyagi',
17+
query='Kesuke Miyagi',
18+
timestamp='Fri Jan 26 23:17:14 +0000 2007')
1919

2020
def testProperties(self):
2121
'''Test all of the twitter.Trend properties'''

tests/test_user.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,15 @@ def _GetSampleUser(self):
2323
'ile_image/673483/normal/me.jpg',
2424
status=self._GetSampleStatus())
2525

26-
2726
def testInit(self):
2827
'''Test the twitter.User constructor'''
29-
user = twitter.User(id=673483,
30-
name='DeWitt',
31-
screen_name='dewitt',
32-
description=u'Indeterminate things',
33-
url='https://twitter.com/dewitt',
34-
profile_image_url='https://twitter.com/system/user/prof'
35-
'ile_image/673483/normal/me.jpg',
36-
status=self._GetSampleStatus())
28+
twitter.User(id=673483,
29+
name='DeWitt',
30+
screen_name='dewitt',
31+
description=u'Indeterminate things',
32+
url='https://twitter.com/dewitt',
33+
profile_image_url='https://twitter.com/system/user/profile_image/673483/normal/me.jpg',
34+
status=self._GetSampleStatus())
3735

3836
def testProperties(self):
3937
'''Test all of the twitter.User properties'''
@@ -48,10 +46,8 @@ def testProperties(self):
4846
self.assertEqual('Indeterminate things', user.description)
4947
user.location = 'San Francisco, CA'
5048
self.assertEqual('San Francisco, CA', user.location)
51-
user.profile_image_url = 'https://twitter.com/system/user/profile_i' \
52-
'mage/673483/normal/me.jpg'
53-
self.assertEqual('https://twitter.com/system/user/profile_image/6734'
54-
'83/normal/me.jpg', user.profile_image_url)
49+
user.profile_image_url = 'https://twitter.com/system/user/profile_image/673483/normal/me.jpg'
50+
self.assertEqual('https://twitter.com/system/user/profile_image/673483/normal/me.jpg', user.profile_image_url)
5551
self.status = self._GetSampleStatus()
5652
self.assertEqual(4212713, self.status.id)
5753

twitter/__init__.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@
2121
__author__ = '[email protected]'
2222
__version__ = '2.3'
2323

24-
import json
24+
import json # noqa
2525

2626
try:
27-
from hashlib import md5
27+
from hashlib import md5 # noqa
2828
except ImportError:
29-
from md5 import md5
29+
from md5 import md5 # noqa
3030

31-
from ._file_cache import _FileCache
32-
from .error import TwitterError
33-
from .direct_message import DirectMessage
34-
from .hashtag import Hashtag
35-
from .parse_tweet import ParseTweet
36-
from .trend import Trend
37-
from .url import Url
38-
from .status import Status
39-
from .user import User, UserStatus
40-
from .category import Category
41-
from .media import Media
42-
from .list import List
43-
from .api import Api
31+
from ._file_cache import _FileCache # noqa
32+
from .error import TwitterError # noqa
33+
from .direct_message import DirectMessage # noqa
34+
from .hashtag import Hashtag # noqa
35+
from .parse_tweet import ParseTweet # noqa
36+
from .trend import Trend # noqa
37+
from .url import Url # noqa
38+
from .status import Status # noqa
39+
from .user import User, UserStatus # noqa
40+
from .category import Category # noqa
41+
from .media import Media # noqa
42+
from .list import List # noqa
43+
from .api import Api # noqa

twitter/_file_cache.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _GetUsername(self):
6565
os.getenv('USERNAME') or \
6666
os.getlogin() or \
6767
'nobody'
68-
except (AttributeError, IOError, OSError) as e:
68+
except (AttributeError, IOError, OSError):
6969
return 'nobody'
7070

7171
def _GetTmpCachePath(self):
@@ -131,17 +131,18 @@ def __init__(self, timeline_owner, tweet):
131131
def __str__(self):
132132
""" for display method """
133133
return "owner %s, urls: %d, hashtags %d, user_handles %d, len_tweet %d, RT = %s, MT = %s" % (
134-
self.Owner, len(self.URLs), len(self.Hashtags), len(self.UserHandles), len(self.tweet), self.RT, self.MT)
134+
self.Owner, len(self.URLs), len(self.Hashtags), len(self.UserHandles),
135+
len(self.tweet), self.RT, self.MT)
135136

136137
@staticmethod
137138
def getAttributeRT(tweet):
138139
""" see if tweet is a RT """
139-
return re.search(ParseTweet.regexp["RT"], tweet.strip()) != None
140+
return re.search(ParseTweet.regexp["RT"], tweet.strip()) is not None
140141

141142
@staticmethod
142143
def getAttributeMT(tweet):
143144
""" see if tweet is a MT """
144-
return re.search(ParseTweet.regexp["MT"], tweet.strip()) != None
145+
return re.search(ParseTweet.regexp["MT"], tweet.strip()) is not None
145146

146147
@staticmethod
147148
def getUserHandles(tweet):

0 commit comments

Comments
 (0)