Skip to content

Commit 6931da0

Browse files
author
Alejandro Gómez
committed
Repo, Issue, Gist and Account equality
1 parent 2acdaed commit 6931da0

9 files changed

Lines changed: 27 additions & 0 deletions

File tree

github3/gists/gist.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ def __init__(self, data, session=None):
7070
#: History of this gist, list of :class:`GistHistory <GistHistory>`
7171
self.history = [GistHistory(h, self) for h in data.get('history', [])]
7272

73+
def __eq__(self, gist):
74+
return self.id == gist.id
75+
7376
def __str__(self):
7477
return self.id
7578

github3/issues.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ def __init__(self, issue, session=None):
204204
#: :class:`User <github3.users.User>` who opened the issue.
205205
self.user = User(issue.get('user'), self._session)
206206

207+
def __eq__(self, issue):
208+
return self.id == issue.id
209+
207210
def __repr__(self):
208211
return '<Issue [{r[0]}/{r[1]} #{n}]>'.format(r=self.repository,
209212
n=self.number)

github3/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@ def __init__(self, acct, session):
346346
#: Markdown formatted biography
347347
self.bio = acct.get('bio')
348348

349+
def __eq__(self, acc):
350+
return self.id == acc.id
351+
349352
def __repr__(self):
350353
return '<{s.type} [{s.login}:{s.name}]>'.format(s=self)
351354

github3/repos/repo.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ def __init__(self, repo, session=None):
125125
#: default branch for the repository
126126
self.master_branch = repo.get('master_branch', '')
127127

128+
def __eq__(self, repo):
129+
return self.id == repo.id
130+
128131
def __repr__(self):
129132
return '<Repository [{0}]>'.format(self)
130133

tests/test_gists.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ def test_history(self):
165165

166166
expect(repr(hist).startswith('<Gist History')).is_True()
167167

168+
def test_equality(self):
169+
expect(self.gist) == gists.Gist(load('gist'))
170+
168171

169172
class TestGistComment(BaseCase):
170173
def __init__(self, methodName='runTest'):

tests/test_issues.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,6 @@ def test_reopen(self):
299299
ed.assert_called_once_with(
300300
self.i.title, self.i.body, u, 'open', n, self.i.labels
301301
)
302+
303+
def test_equality(self):
304+
expect(self.i) == github3.issues.Issue(load('issue'))

tests/test_orgs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,6 @@ def test_team(self):
373373

374374
expect(self.org.team(1)).isinstance(github3.orgs.Team)
375375
self.mock_assertions()
376+
377+
def test_equality(self):
378+
expect(self.org) == github3.orgs.Organization(load('org'))

tests/test_repos.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,9 @@ def test_update_label(self):
10001000

10011001
self.mock_assertions()
10021002

1003+
def test_equality(self):
1004+
expect(self.repo) == repos.Repository(load('repo'))
1005+
10031006

10041007
class TestContents(BaseCase):
10051008
def __init__(self, methodName='runTest'):

tests/test_users.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,6 @@ def test_update(self):
269269

270270
self.response('', 404)
271271
expect(self.user.update(**self.conf['data'])).is_False()
272+
273+
def test_equality(self):
274+
expect(self.user) == github3.users.User(load('user'))

0 commit comments

Comments
 (0)