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

Add __repr__ for status #246

Merged
merged 2 commits into from
Sep 25, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add __repr__ for status
  • Loading branch information
era committed Sep 24, 2015
commit fe98ceae6924a328f4f245820a281ba2e1b9814f
4 changes: 4 additions & 0 deletions tests/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,7 @@ def testNewFromJsonDict(self):
data = json.loads(StatusTest.SAMPLE_JSON)
status = twitter.Status.NewFromJsonDict(data)
self.assertEqual(self._GetSampleStatus(), status)

def testStatusRepresentation(self):
status = self._GetSampleStatus()
self.assertEqual("Status(ID=4391023, screen_name='kesuke', created_at='Fri Jan 26 23:17:14 +0000 2007')", status.__repr__())
9 changes: 9 additions & 0 deletions twitter/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,15 @@ def __str__(self):
"""
return self.AsJsonString()

def __repr__(self):
if self.user:
representation = "Status(ID=%s, screen_name='%s', created_at='%s')" % (
self.id, self.user.screen_name, self.created_at)
else:
representation = "Status(ID=%s, created_at='%s')" % (
self.id, self.created_at)
return representation

def AsJsonString(self, allow_non_ascii=False):
"""A JSON string representation of this twitter.Status instance.
To output non-ascii, set keyword allow_non_ascii=True.
Expand Down