X Tutup
Skip to content

Commit 26d2297

Browse files
committed
Merge branch 'master' into python-v3
2 parents b6ee6d9 + dc32a98 commit 26d2297

File tree

17 files changed

+392
-391
lines changed

17 files changed

+392
-391
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: 8 additions & 7 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,8 +32,8 @@ 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()
34-
except twitter.TwitterError as error:
35+
self._api.GetUserTimeline()
36+
except twitter.TwitterError, error:
3537
# If the error message matches, the test passes
3638
self.assertEqual('test error', error.message)
3739
else:
@@ -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: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ def _GetSampleUser(self):
1818
description=u'Canvas. JC Penny. Three ninety-eight.',
1919
location='Okinawa, Japan',
2020
url='https://twitter.com/kesuke',
21-
profile_image_url='https://twitter.com/system/user/pro'
22-
'file_image/718443/normal/kesuke.pn'
23-
'g')
21+
profile_image_url='https://twitter.com/system/user/profile_image/718443/normal/kesuke.png')
2422

2523
def _GetSampleStatus(self):
2624
return twitter.Status(created_at='Fri Jan 26 23:17:14 +0000 2007',
@@ -30,10 +28,10 @@ def _GetSampleStatus(self):
3028

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

3836
def testProperties(self):
3937
'''Test all of the twitter.Status properties'''
@@ -119,7 +117,7 @@ def testNewFromJsonDict(self):
119117
data = json.loads(StatusTest.SAMPLE_JSON)
120118
status = twitter.Status.NewFromJsonDict(data)
121119
self.assertEqual(self._GetSampleStatus(), status)
122-
120+
123121
def testStatusRepresentation(self):
124122
status = self._GetSampleStatus()
125123
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
@@ -22,23 +22,23 @@
2222
__author__ = 'python-twitter@googlegroups.com'
2323
__version__ = '2.3'
2424

25-
import json
25+
import json # noqa
2626

2727
try:
28-
from hashlib import md5
28+
from hashlib import md5 # noqa
2929
except ImportError:
30-
from md5 import md5
30+
from md5 import md5 # noqa
3131

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

twitter/_file_cache.py

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

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

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

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

147148
@staticmethod
148149
def getUserHandles(tweet):

0 commit comments

Comments
 (0)
X Tutup