10000 Merge pull request #582 from itsmemattchung/issue/567 · pythonthings/github3.py@584b2cd · GitHub
[go: up one dir, main page]

Skip to content

Commit 584b2cd

Browse files
committed
Merge pull request sigmavirus24#582 from itsmemattchung/issue/567
Added __eq__ and __ne__ to Tree object
2 parents 96726db + 5991dac commit 584b2cd

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

github3/git.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ def _update_attributes(self, tree):
206206
def _repr(self):
207207
return '<Tree [{0}]>'.format(self.sha)
208208

209+
def __eq__(self, other):
210+
return self.as_dict() == other.as_dict()
211+
212+
def __ne__(self, other):
213+
return self.as_dict() != other.as_dict()
214+
209215
def recurse(self):
210216
"""Recurse into the tree.
211217

tests/cassettes/Tree_ne.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

tests/integration/test_git.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ class TestTree(IntegrationHelper):
77

88
"""Integration tests for methods on the Test class."""
99

10+
def test_inequality(self):
11+
"""Test that a tree and its recursed tree are not equal."""
12+
cassette_name = self.cassette_name('ne')
13+
with self.recorder.use_cassette(cassette_name):
14+
repository = self.gh.repository('sigmavirus24', 'github3.py')
15+
tree = repository.tree(
16+
'96726db07528a87b7c1f266ed42cd321070470c2'
17+
)
18+
recursed = tree.recurse()
19+
assert tree != recursed
20+
1021
def test_recurse(self):
1122
"""Test recurse on tree"""
1223
cassette_name = self.cassette_name('recurse')

tests/unit/test_git.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ class TestTree(UnitHelper):
2020
described_class = github3.git.Tree
2121
example_data = get_example_data()
2222

23+
def test_eq(self):
24+
"""Assert that two trees are equal."""
25+
tree = github3.git.Tree(get_example_data())
26+
assert self.instance == tree
27+
28+
def test_ne(self):
29+
"""Assert that two trees are not equal."""
30+
tree = github3.git.Tree(get_example_data())
31+
tree._json_data['truncated'] = True
32+
assert self.instance != tree
33+
2334
def test_repr(self):
2435
"""Assert Tree in in the repr."""
2536
assert isinstance(self.instance, github3.git.Tree)
@@ -36,7 +47,7 @@ def test_recurse(self):
3647

3748
class TestCommit(UnitHelper):
3849

39-
"Commit unit test."""
50+
"""Commit unit test."""
4051

4152
described_class = github3.git.Commit
4253
example_data = get_commit_example_data()

0 commit comments

Comments
 (0)
0