Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweet: test pickle, unpickle, fix recursion #2060

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions tests/test_tweets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pickle
import unittest

from tweepy.tweet import Tweet


class TweepyTweetTests(unittest.TestCase):
def test_tweet(self):
t = Tweet(
data={
"edit_history_tweet_ids": ["16213149247090909"],
"id": "16213149247090909",
"text": "We're super excited to not only welcome the Flamingo Janes in...",
}
)

pickled_tweet = pickle.dumps(t)
t2 = pickle.loads(pickled_tweet)

self.assertDictEqual(t.data, t2.data)
10 changes: 7 additions & 3 deletions tweepy/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ class DataMapping(Mapping):
__slots__ = ()

def __contains__(self, item):
return item in self.data
data = DataMapping.__getattribute__(self, "data")
return item in data

def __getattr__(self, name):
data = DataMapping.__getattribute__(self, "data")
if name == "data":
return data
try:
return self.data[name]
return data[name]
except KeyError:
raise AttributeError from None

def __getitem__(self, key):
try:
return getattr(self, key)
return DataMapping.__getattribute__(self, key)
except AttributeError:
raise KeyError from None

Expand Down