Skip to content

Commit e98c07f

Browse files
committed
added unit tests for git object equality and hashing
1 parent 9d252bf commit e98c07f

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/test_object.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,46 @@
4646

4747
class ObjectTest(utils.RepoTestCase):
4848

49+
def test_equality(self):
50+
# get a commit object twice and see if it equals itself
51+
commit_id = self.repo.lookup_reference('refs/heads/master').target
52+
commit_a = self.repo[commit_id]
53+
commit_b = self.repo[commit_id]
54+
55+
assert commit_a is not commit_b
56+
assert commit_a == commit_b
57+
assert not(commit_a != commit_b)
58+
59+
def test_hashing(self):
60+
# get a commit object twice and compare hashes
61+
commit_id = self.repo.lookup_reference('refs/heads/master').target
62+
commit_a = self.repo[commit_id]
63+
commit_b = self.repo[commit_id]
64+
65+
assert hash(commit_a)
66+
67+
assert commit_a is not commit_b
68+
assert commit_a == commit_b
69+
# if the commits are equal then their hash *must* be equal
70+
# but different objects can have the same commit
71+
assert hash(commit_a) == hash(commit_b)
72+
73+
# sanity check that python container types work as expected
74+
s = set()
75+
s.add(commit_a)
76+
s.add(commit_b)
77+
assert len(s) == 1
78+
assert commit_a in s
79+
assert commit_b in s
80+
81+
d = {}
82+
d[commit_a] = True
83+
assert commit_b in d
84+
assert d[commit_b]
85+
86+
l = [commit_a]
87+
assert commit_b in l
88+
4989
def test_peel_commit(self):
5090
# start by looking up the commit
5191
commit_id = self.repo.lookup_reference('refs/heads/master').target

0 commit comments

Comments
 (0)