Skip to content

Commit ed5fcdc

Browse files
committed
Reorganize the git tests.
1 parent d77e049 commit ed5fcdc

3 files changed

Lines changed: 124 additions & 34 deletions

File tree

github3/git.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class Reference(GitHubCore):
9292
"""
9393
def __init__(self, ref, session=None):
9494
super(Reference, self).__init__(ref, session)
95+
self._api = ref.get('url')
9596
#: The reference path, e.g., refs/heads/sc/featureA
9697
self.ref = ref.get('ref')
9798
#: :class:`GitObject <GitObject>` the reference points to
@@ -126,7 +127,7 @@ def update(self, sha, force=False):
126127
if json:
127128
self._update_(json)
128129
return True
129-
return False
130+
return False # (No coverage)
130131

131132

132133
class GitObject(GitData):

tests/base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,8 @@ def is_False(var):
6767
str_test = (str, bytes)
6868
else:
6969
str_test = (str, unicode)
70+
71+
72+
def expect_str(val):
73+
expect(val).isinstance(str_test)
74+
expect(val) != ''

tests/test_git.py

Lines changed: 117 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
1-
import base
2-
from expecter import expect
1+
from base import BaseTest, expect, expect_str
32
import github3
4-
from github3.git import Commit, Blob, Reference, Tag, Tree, Hash
3+
from github3.git import (Commit, Blob, Reference, Tag, Tree, Hash, GitObject)
54

65

7-
class TestGit(base.BaseTest):
6+
class TestGit(BaseTest):
87
def setUp(self):
98
super(TestGit, self).setUp()
109
self.todor = self.g.repository(self.sigm, self.todo)
1110
self.gh3r = self.g.repository(self.sigm, 'github3.py')
1211

12+
13+
class TestBlob(BaseTest):
14+
def __init__(self, methodName='runTest'):
15+
super(TestBlob, self).__init__(methodName)
16+
self.r = self.g.repository(self.sigm, self.todo)
17+
self.blob = self.r.blob('f737918b90118a6aea991f89f444b150a2360393')
18+
1319
def test_blob(self):
14-
r = self.todor
15-
blob = r.blob('f737918b90118a6aea991f89f444b150a2360393')
16-
expect(blob).isinstance(Blob)
17-
self.assertAreNotNone(blob, 'content', 'decoded', 'encoding', 'sha',
18-
'size')
20+
expect(self.blob).isinstance(Blob)
21+
expect_str(repr(self.blob))
1922

20-
with expect.raises(github3.GitHubError):
21-
r.create_blob('Foo bar bogus', 'utf-8')
23+
def test_content(self):
24+
expect_str(self.blob.content)
25+
26+
def test_decoded(self):
27+
expect_str(self.blob.decoded)
28+
29+
def test_encoding(self):
30+
expect_str(self.blob.encoding)
31+
32+
def test_sha(self):
33+
expect_str(self.blob.sha)
34+
35+
def test_size(self):
36+
expect_str(self.blob.size)
2237

2338
def test_commit(self):
2439
r = self.todor
@@ -27,31 +42,100 @@ def test_commit(self):
2742
self.assertAreNotNone(commit, 'author', 'committer', 'tree', 'message',
2843
'parents', 'sha')
2944

45+
46+
class TestTag(BaseTest):
47+
def __init__(self, methodName='runTest'):
48+
super(TestTag, self).__init__(methodName)
49+
r = self.g.repository(self.sigm, 'github3.py')
50+
self.tag = r.tag('495404cbf4918f46a428b268104de37893dad449')
51+
3052
def test_tag(self):
31-
r = self.gh3r
32-
tag = r.tag('495404cbf4918f46a428b268104de37893dad449')
33-
expect(tag).isinstance(Tag)
34-
self.assertAreNotNone(tag, 'message', 'object', 'tag', 'tagger',
35-
'sha')
53+
expect(self.tag).isinstance(Tag)
54+
expect_str(repr(self.tag))
3655

37-
def test_tree_and_hash(self):
38-
r = self.todor
39-
tree = r.tree('31e862095dffa60744f1ce16a431ea040381f053')
40-
expect(tree).isinstance(Tree)
41-
self.assertAreNotNone(tree, 'sha', 'tree')
42-
expect(tree.recurse()).isinstance(Tree)
43-
hashes = tree.tree # Odd access, right?
44-
for h in hashes:
56+
def test_message(self):
57+
expect_str(self.tag.message)
58+
59+
def test_object(self):
60+
expect(self.tag.object).isinstance(GitObject)
61+
62+
def test_tagname(self):
63+
expect_str(self.tag.tag)
64+
65+
def test_tagger(self):
66+
expect(self.tag.tagger).isinstance(dict)
67+
68+
def test_sha(self):
69+
expect_str(self.tag.sha)
70+
71+
72+
class TestTreeHash(BaseTest):
73+
def __init__(self, methodName='runTest'):
74+
super(TestTreeHash, self).__init__(methodName)
75+
r = self.g.repository(self.sigm, self.todo)
76+
self.tree = r.tree('31e862095dffa60744f1ce16a431ea040381f053')
77+
78+
def test_tree(self):
79+
expect(self.tree).isinstance(Tree)
80+
expect_str(repr(self.tree))
81+
82+
def test_tree_sha(self):
83+
expect_str(self.sha)
84+
85+
def test_tree_recurse(self):
86+
expect(self.tree.recurse()).isinstance(Tree)
87+
88+
def test_hash(self):
89+
self.hashes = self.tree.tree
90+
for h in self.hashes:
4591
expect(h).isinstance(Hash)
46-
self.assertAreNotNone(h, 'mode', 'path', 'sha', 'size', 'type',
47-
'url')
92+
self.hash = self.hashes[0]
4893

49-
def test_refs(self):
50-
r = self.todor
51-
ref = r.ref('heads/development')
52-
expect(ref).isinstance(Reference)
53-
self.assertAreNotNone(ref, 'object', 'ref')
94+
def test_hash_mode(self):
95+
expect_str(self.hash.mode)
96+
97+
def test_hash_path(self):
98+
expect_str(self.hash.path)
99+
100+
def test_hash_size(self):
101+
expect(self.hash.size) >= 0
54102

103+
def test_hash_type(self):
104+
expect_str(self.hash.type)
105+
106+
def test_hash_url(self):
107+
expect_str(self.hash.url)
108+
109+
110+
class TestReference(BaseTest):
111+
def __init__(self, methodName='runTest'):
112+
super(TestReference, self).__init__(methodName)
113+
r = self.g.repository(self.sigm, self.todo)
114+
self.ref = r.ref('heads/development')
115+
116+
def test_reference(self):
117+
expect(self.ref).isinstance(Reference)
118+
expect_str(repr(self.ref))
119+
120+
def test_object(self):
121+
expect(self.ref.object).isinstance(GitObject)
122+
expect_str(repr(self.ref.object))
123+
124+
def test_ref(self):
125+
expect_str(self.ref.ref)
126+
127+
def test_requires_auth(self):
55128
with expect.raises(github3.GitHubError):
56-
ref.delete()
57-
ref.update('31e862095dffa60744f1ce16a431ea040381f053')
129+
self.ref.delete()
130+
self.ref.update('31e862095dffa60744f1ce16a431ea040381f053')
131+
132+
def test_with_auth(self):
133+
if not self.auth:
134+
return
135+
r = self._g.repository(self.gh3py, self.test_repo)
136+
ref = r.create_ref('refs/tags/test_refs',
137+
'5bd14b07155cf555bda5b8081ba6dc4ac5e645dd')
138+
expect(ref.update(
139+
'82b8dd20e95ea34f3d46349a8731d6f18866f8af'
140+
)).isinstance(bool)
141+
expect(ref.delete()).is_True()

0 commit comments

Comments
 (0)