3
3
#
4
4
# This module is part of GitPython and is released under
5
5
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
6
-
7
- import os , sys
8
6
from test .testlib import *
9
7
from git import *
10
8
from git .util import join_path_native
9
+ from git .exc import BadObject
10
+ from gitdb .util import hex_to_bin
11
+
12
+ import os , sys
11
13
import tempfile
12
14
import shutil
13
15
from cStringIO import StringIO
14
- from git . exc import BadObject
16
+
15
17
16
18
class TestRepo (TestBase ):
17
19
18
20
@raises (InvalidGitRepositoryError )
19
- def _test_new_should_raise_on_invalid_repo_location (self ):
21
+ def test_new_should_raise_on_invalid_repo_location (self ):
20
22
Repo (tempfile .gettempdir ())
21
23
22
24
@raises (NoSuchPathError )
23
- def _test_new_should_raise_on_non_existant_path (self ):
25
+ def test_new_should_raise_on_non_existant_path (self ):
24
26
Repo ("repos/foobar" )
25
27
26
- def _test_repo_creation_from_different_paths (self ):
28
+ def test_repo_creation_from_different_paths (self ):
27
29
r_from_gitdir = Repo (self .rorepo .git_dir )
28
30
assert r_from_gitdir .git_dir == self .rorepo .git_dir
29
31
assert r_from_gitdir .git_dir .endswith ('.git' )
30
32
assert not self .rorepo .git .working_dir .endswith ('.git' )
31
33
assert r_from_gitdir .git .working_dir == self .rorepo .git .working_dir
32
34
33
- def _test_description (self ):
35
+ def test_description (self ):
34
36
txt = "Test repository"
35
37
self .rorepo .description = txt
36
38
assert_equal (self .rorepo .description , txt )
37
39
38
- def _test_heads_should_return_array_of_head_objects (self ):
40
+ def test_heads_should_return_array_of_head_objects (self ):
39
41
for head in self .rorepo .heads :
40
42
assert_equal (Head , head .__class__ )
41
43
42
- def _test_heads_should_populate_head_data (self ):
44
+ def test_heads_should_populate_head_data (self ):
43
45
for head in self .rorepo .heads :
44
46
assert head .name
45
47
assert isinstance (head .commit ,Commit )
@@ -48,7 +50,7 @@ def _test_heads_should_populate_head_data(self):
48
50
assert isinstance (self .rorepo .heads .master , Head )
49
51
assert isinstance (self .rorepo .heads ['master' ], Head )
50
52
51
- def _test_tree_from_revision (self ):
53
+ def test_tree_from_revision (self ):
52
54
tree = self .rorepo .tree ('0.1.6' )
53
55
assert len (tree .hexsha ) == 40
54
56
assert tree .type == "tree"
@@ -57,7 +59,7 @@ def _test_tree_from_revision(self):
57
59
# try from invalid revision that does not exist
58
60
self .failUnlessRaises (ValueError , self .rorepo .tree , 'hello world' )
59
61
60
- def _test_commits (self ):
62
+ def test_commits (self ):
61
63
mc = 10
62
64
commits = list (self .rorepo .iter_commits ('0.1.6' , max_count = mc ))
63
65
assert len (commits ) == mc
@@ -79,7 +81,7 @@ def _test_commits(self):
79
81
c = commits [1 ]
80
82
assert isinstance (c .parents , tuple )
81
83
82
- def _test_trees (self ):
84
+ def test_trees (self ):
83
85
mc = 30
84
86
num_trees = 0
85
87
for tree in self .rorepo .iter_trees ('0.1.5' , max_count = mc ):
@@ -89,7 +91,7 @@ def _test_trees(self):
89
91
assert num_trees == mc
90
92
91
93
92
- def _test_empty_repo (self , repo ):
94
+ def _assert_empty_repo (self , repo ):
93
95
# test all kinds of things with an empty, freshly initialized repo.
94
96
# It should throw good errors
95
97
@@ -117,7 +119,7 @@ def _test_empty_repo(self, repo):
117
119
# END test repos with working tree
118
120
119
121
120
- def _test_init (self ):
122
+ def test_init (self ):
121
123
prev_cwd = os .getcwd ()
122
124
os .chdir (tempfile .gettempdir ())
123
125
git_dir_rela = "repos/foo/bar.git"
@@ -131,12 +133,12 @@ def _test_init(self):
131
133
assert r .bare == True
132
134
assert os .path .isdir (r .git_dir )
133
135
134
- self ._test_empty_repo (r )
136
+ self ._assert_empty_repo (r )
135
137
136
138
# test clone
137
139
clone_path = path + "_clone"
138
140
rc = r .clone (clone_path )
139
- self ._test_empty_repo (rc )
141
+ self ._assert_empty_repo (rc )
140
142
141
143
shutil .rmtree (git_dir_abs )
142
144
try :
@@ -153,7 +155,7 @@ def _test_init(self):
153
155
r = Repo .init (bare = False )
154
156
r .bare == False
155
157
156
- self ._test_empty_repo (r )
158
+ self ._assert_empty_repo (r )
157
159
finally :
158
160
try :
159
161
shutil .rmtree (del_dir_abs )
@@ -162,17 +164,17 @@ def _test_init(self):
162
164
os .chdir (prev_cwd )
163
165
# END restore previous state
164
166
165
- def _test_bare_property (self ):
167
+ def test_bare_property (self ):
166
168
self .rorepo .bare
167
169
168
- def _test_daemon_export (self ):
170
+ def test_daemon_export (self ):
169
171
orig_val = self .rorepo .daemon_export
170
172
self .rorepo .daemon_export = not orig_val
171
173
assert self .rorepo .daemon_export == ( not orig_val )
172
174
self .rorepo .daemon_export = orig_val
173
175
assert self .rorepo .daemon_export == orig_val
174
176
175
- def _test_alternates (self ):
177
+ def test_alternates (self ):
176
178
cur_alternates = self .rorepo .alternates
177
179
# empty alternates
178
180
self .rorepo .alternates = []
@@ -182,15 +184,15 @@ def _test_alternates(self):
182
184
assert alts == self .rorepo .alternates
183
185
self .rorepo .alternates = cur_alternates
184
186
185
- def _test_repr (self ):
187
+ def test_repr (self ):
186
188
path = os .path .join (os .path .abspath (GIT_REPO ), '.git' )
187
189
assert_equal ('<git.Repo "%s">' % path , repr (self .rorepo ))
188
190
189
- def _test_is_dirty_with_bare_repository (self ):
191
+ def test_is_dirty_with_bare_repository (self ):
190
192
self .rorepo ._bare = True
191
193
assert_false (self .rorepo .is_dirty ())
192
194
193
- def _test_is_dirty (self ):
195
+ def test_is_dirty (self ):
194
196
self .rorepo ._bare = False
195
197
for index in (0 ,1 ):
196
198
for working_tree in (0 ,1 ):
@@ -202,23 +204,23 @@ def _test_is_dirty(self):
202
204
self .rorepo ._bare = True
203
205
assert self .rorepo .is_dirty () == False
204
206
205
- def _test_head (self ):
207
+ def test_head (self ):
206
208
assert self .rorepo .head .reference .object == self .rorepo .active_branch .object
207
209
208
- def _test_index (self ):
210
+ def test_index (self ):
209
211
index = self .rorepo .index
210
212
assert isinstance (index , IndexFile )
211
213
212
- def _test_tag (self ):
214
+ def test_tag (self ):
213
215
assert self .rorepo .tag ('refs/tags/0.1.5' ).commit
214
216
215
- def _test_archive (self ):
217
+ def test_archive (self ):
216
218
tmpfile = os .tmpfile ()
217
219
self .rorepo .archive (tmpfile , '0.1.5' )
218
220
assert tmpfile .tell ()
219
221
220
222
@patch_object (Git , '_call_process' )
221
- def _test_should_display_blame_information (self , git ):
223
+ def test_should_display_blame_information (self , git ):
222
224
git .return_value = fixture ('blame' )
223
225
b = self .rorepo .blame ( 'master' , 'lib/git.py' )
224
226
assert_equal (13 , len (b ))
@@ -244,7 +246,7 @@ def _test_should_display_blame_information(self, git):
244
246
assert_true ( isinstance ( tlist [0 ], basestring ) )
245
247
assert_true ( len ( tlist ) < sum ( len (t ) for t in tlist ) ) # test for single-char bug
246
248
247
- def _test_untracked_files (self ):
249
+ def test_untracked_files (self ):
248
250
base = self .rorepo .working_tree_dir
249
251
files = ( join_path_native (base , "__test_myfile" ),
250
252
join_path_native (base , "__test_other_file" ) )
@@ -270,13 +272,13 @@ def _test_untracked_files(self):
270
272
271
273
assert len (self .rorepo .untracked_files ) == (num_recently_untracked - len (files ))
272
274
273
- def _test_config_reader (self ):
275
+ def test_config_reader (self ):
274
276
reader = self .rorepo .config_reader () # all config files
275
277
assert reader .read_only
276
278
reader = self .rorepo .config_reader ("repository" ) # single config file
277
279
assert reader .read_only
278
280
279
- def _test_config_writer (self ):
281
+ def test_config_writer (self ):
280
282
for config_level in self .rorepo .config_level :
281
283
try :
282
284
writer = self .rorepo .config_writer (config_level )
@@ -287,7 +289,7 @@ def _test_config_writer(self):
287
289
pass
288
290
# END for each config level
289
291
290
- def _test_creation_deletion (self ):
292
+ def test_creation_deletion (self ):
291
293
# just a very quick test to assure it generally works. There are
292
294
# specialized cases in the test_refs module
293
295
head = self .rorepo .create_head ("new_head" , "HEAD~1" )
@@ -299,12 +301,12 @@ def _test_creation_deletion(self):
299
301
remote = self .rorepo .create_remote ("new_remote" , "git@server:repo.git" )
300
302
self .rorepo .delete_remote (remote )
301
303
302
- def _test_comparison_and_hash (self ):
304
+ def test_comparison_and_hash (self ):
303
305
# this is only a preliminary test, more testing done in test_index
304
306
assert self .rorepo == self .rorepo and not (self .rorepo != self .rorepo )
305
307
assert len (set ((self .rorepo , self .rorepo ))) == 1
306
308
307
- def _test_git_cmd (self ):
309
+ def test_git_cmd (self ):
308
310
# test CatFileContentStream, just to be very sure we have no fencepost errors
309
311
# last \n is the terminating newline that it expects
310
312
l1 = "0123456789\n "
@@ -442,6 +444,9 @@ def _assert_rev_parse(self, name):
442
444
def test_rev_parse (self ):
443
445
rev_parse = self .rorepo .rev_parse
444
446
447
+ # try special case: This one failed beforehand
448
+ assert self .rorepo .odb .partial_to_complete_sha_hex ("33ebe" ) == hex_to_bin ("33ebe7acec14b25c5f84f35a664803fcab2f7781" )
449
+
445
450
# start from reference
446
451
num_resolved = 0
447
452
for ref in Reference .iter_items (self .rorepo ):
0 commit comments