From f963881e53a9f0a2746a11cb9cdfa82eb1f90d8c Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 6 Jul 2010 00:35:30 +0200 Subject: Initial version of the rev-parse routine, which doesn't work too bad, but its still rather slow and many tests are not yet implemented --- test/git/test_repo.py | 151 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 125 insertions(+), 26 deletions(-) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 11c7c2e6..f1609266 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -11,34 +11,35 @@ from git.util import join_path_native import tempfile import shutil from cStringIO import StringIO +from git.exc import BadObject class TestRepo(TestBase): @raises(InvalidGitRepositoryError) - def test_new_should_raise_on_invalid_repo_location(self): + def _test_new_should_raise_on_invalid_repo_location(self): Repo(tempfile.gettempdir()) @raises(NoSuchPathError) - def test_new_should_raise_on_non_existant_path(self): + def _test_new_should_raise_on_non_existant_path(self): Repo("repos/foobar") - def test_repo_creation_from_different_paths(self): + def _test_repo_creation_from_different_paths(self): r_from_gitdir = Repo(self.rorepo.git_dir) assert r_from_gitdir.git_dir == self.rorepo.git_dir assert r_from_gitdir.git_dir.endswith('.git') assert not self.rorepo.git.working_dir.endswith('.git') assert r_from_gitdir.git.working_dir == self.rorepo.git.working_dir - def test_description(self): + def _test_description(self): txt = "Test repository" self.rorepo.description = txt assert_equal(self.rorepo.description, txt) - def test_heads_should_return_array_of_head_objects(self): + def _test_heads_should_return_array_of_head_objects(self): for head in self.rorepo.heads: assert_equal(Head, head.__class__) - def test_heads_should_populate_head_data(self): + def _test_heads_should_populate_head_data(self): for head in self.rorepo.heads: assert head.name assert isinstance(head.commit,Commit) @@ -47,7 +48,7 @@ class TestRepo(TestBase): assert isinstance(self.rorepo.heads.master, Head) assert isinstance(self.rorepo.heads['master'], Head) - def test_tree_from_revision(self): + def _test_tree_from_revision(self): tree = self.rorepo.tree('0.1.6') assert len(tree.hexsha) == 40 assert tree.type == "tree" @@ -56,7 +57,7 @@ class TestRepo(TestBase): # try from invalid revision that does not exist self.failUnlessRaises(ValueError, self.rorepo.tree, 'hello world') - def test_commits(self): + def _test_commits(self): mc = 10 commits = list(self.rorepo.iter_commits('0.1.6', max_count=mc)) assert len(commits) == mc @@ -78,7 +79,7 @@ class TestRepo(TestBase): c = commits[1] assert isinstance(c.parents, tuple) - def test_trees(self): + def _test_trees(self): mc = 30 num_trees = 0 for tree in self.rorepo.iter_trees('0.1.5', max_count=mc): @@ -116,7 +117,7 @@ class TestRepo(TestBase): # END test repos with working tree - def test_init(self): + def _test_init(self): prev_cwd = os.getcwd() os.chdir(tempfile.gettempdir()) git_dir_rela = "repos/foo/bar.git" @@ -161,17 +162,17 @@ class TestRepo(TestBase): os.chdir(prev_cwd) # END restore previous state - def test_bare_property(self): + def _test_bare_property(self): self.rorepo.bare - def test_daemon_export(self): + def _test_daemon_export(self): orig_val = self.rorepo.daemon_export self.rorepo.daemon_export = not orig_val assert self.rorepo.daemon_export == ( not orig_val ) self.rorepo.daemon_export = orig_val assert self.rorepo.daemon_export == orig_val - def test_alternates(self): + def _test_alternates(self): cur_alternates = self.rorepo.alternates # empty alternates self.rorepo.alternates = [] @@ -181,15 +182,15 @@ class TestRepo(TestBase): assert alts == self.rorepo.alternates self.rorepo.alternates = cur_alternates - def test_repr(self): + def _test_repr(self): path = os.path.join(os.path.abspath(GIT_REPO), '.git') assert_equal('' % path, repr(self.rorepo)) - def test_is_dirty_with_bare_repository(self): + def _test_is_dirty_with_bare_repository(self): self.rorepo._bare = True assert_false(self.rorepo.is_dirty()) - def test_is_dirty(self): + def _test_is_dirty(self): self.rorepo._bare = False for index in (0,1): for working_tree in (0,1): @@ -201,23 +202,23 @@ class TestRepo(TestBase): self.rorepo._bare = True assert self.rorepo.is_dirty() == False - def test_head(self): + def _test_head(self): assert self.rorepo.head.reference.object == self.rorepo.active_branch.object - def test_index(self): + def _test_index(self): index = self.rorepo.index assert isinstance(index, IndexFile) - def test_tag(self): + def _test_tag(self): assert self.rorepo.tag('refs/tags/0.1.5').commit - def test_archive(self): + def _test_archive(self): tmpfile = os.tmpfile() self.rorepo.archive(tmpfile, '0.1.5') assert tmpfile.tell() @patch_object(Git, '_call_process') - def test_should_display_blame_information(self, git): + def _test_should_display_blame_information(self, git): git.return_value = fixture('blame') b = self.rorepo.blame( 'master', 'lib/git.py') assert_equal(13, len(b)) @@ -243,7 +244,7 @@ class TestRepo(TestBase): assert_true( isinstance( tlist[0], basestring ) ) assert_true( len( tlist ) < sum( len(t) for t in tlist ) ) # test for single-char bug - def test_untracked_files(self): + def _test_untracked_files(self): base = self.rorepo.working_tree_dir files = ( join_path_native(base, "__test_myfile"), join_path_native(base, "__test_other_file") ) @@ -269,7 +270,7 @@ class TestRepo(TestBase): assert len(self.rorepo.untracked_files) == (num_recently_untracked - len(files)) - def test_config_reader(self): + def _test_config_reader(self): reader = self.rorepo.config_reader() # all config files assert reader.read_only reader = self.rorepo.config_reader("repository") # single config file @@ -286,7 +287,7 @@ class TestRepo(TestBase): pass # END for each config level - def test_creation_deletion(self): + def _test_creation_deletion(self): # just a very quick test to assure it generally works. There are # specialized cases in the test_refs module head = self.rorepo.create_head("new_head", "HEAD~1") @@ -298,12 +299,12 @@ class TestRepo(TestBase): remote = self.rorepo.create_remote("new_remote", "git@server:repo.git") self.rorepo.delete_remote(remote) - def test_comparison_and_hash(self): + def _test_comparison_and_hash(self): # this is only a preliminary test, more testing done in test_index assert self.rorepo == self.rorepo and not (self.rorepo != self.rorepo) assert len(set((self.rorepo, self.rorepo))) == 1 - def test_git_cmd(self): + def _test_git_cmd(self): # test CatFileContentStream, just to be very sure we have no fencepost errors # last \n is the terminating newline that it expects l1 = "0123456789\n" @@ -376,3 +377,101 @@ class TestRepo(TestBase): assert s._stream.tell() == 2 assert s.read() == l1[2:ts] assert s._stream.tell() == ts+1 + + def _assert_rev_parse_types(self, name, rev_obj): + rev_parse = self.rorepo.rev_parse + + # tree and blob type + obj = rev_parse(name + '^{tree}') + assert obj == rev_obj.tree + + obj = rev_parse(name + ':CHANGES') + assert obj.type == 'blob' and obj.path == 'CHANGES' + assert rev_obj.tree['CHANGES'] == obj + + + def _assert_rev_parse(self, name): + """tries multiple different rev-parse syntaxes with the given name + :return: parsed object""" + rev_parse = self.rorepo.rev_parse + obj = rev_parse(name) + + # try history + rev = name + "~" + obj2 = rev_parse(rev) + assert obj2 == obj.parents[0] + self._assert_rev_parse_types(rev, obj2) + + # history with number + ni = 11 + history = list() + citer = obj.traverse() + for pn in range(ni): + history.append(citer.next()) + # END get given amount of commits + + for pn in range(11): + rev = name + "~%i" % (pn+1) + obj2 = rev_parse(rev) + assert obj2 == history[pn] + self._assert_rev_parse_types(rev, obj2) + # END history check + + # parent ( default ) + rev = name + "^" + obj2 = rev_parse(rev) + assert obj2 == obj.parents[0] + self._assert_rev_parse_types(rev, obj2) + + # parent with number + for pn, parent in enumerate(obj.parents): + rev = name + "^%i" % (pn+1) + assert rev_parse(rev) == parent + self._assert_rev_parse_types(rev, obj2) + # END for each parent + + return obj + + def test_rev_parse(self): + rev_parse = self.rorepo.rev_parse + + # start from reference + num_resolved = 0 + for ref in Reference.iter_items(self.rorepo): + path_tokens = ref.path.split("/") + for pt in range(len(path_tokens)): + path_section = '/'.join(path_tokens[-(pt+1):]) + try: + obj = self._assert_rev_parse(path_section) + assert obj.type == ref.object.type + num_resolved += 1 + except BadObject: + print "failed on %s" % path_section + raise + # is fine, in case we have something like 112, which belongs to remotes/rname/merge-requests/112 + pass + # END exception handling + # END for each token + # END for each reference + assert num_resolved + + # try full sha directly ( including type conversion ) + + + # multiple tree types result in the same tree: HEAD^{tree}^{tree}:CHANGES + + # try to get parents from first revision - it should fail as no such revision + # exists + + # todo: dereference tag into a blob 0.1.7^{blob} - quite a special one + + # dereference tag using ^{} notation + + # missing closing brace commit^{tree + + # missing starting brace + + # not enough parents ^10 + + # cannot handle rev-log for now + self.failUnlessRaises(ValueError, rev_parse, "hi@there") -- cgit v1.2.1 From 1c6d7830d9b87f47a0bfe82b3b5424a32e3164ad Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 6 Jul 2010 10:46:02 +0200 Subject: RevParse now generally works, but there are still some more specialized tests missing --- test/git/test_repo.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index f1609266..89c7f6b5 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -394,7 +394,12 @@ class TestRepo(TestBase): """tries multiple different rev-parse syntaxes with the given name :return: parsed object""" rev_parse = self.rorepo.rev_parse - obj = rev_parse(name) + orig_obj = rev_parse(name) + if orig_obj.type == 'tag': + obj = orig_obj.object + else: + obj = orig_obj + # END deref tags by default # try history rev = name + "~" @@ -404,10 +409,9 @@ class TestRepo(TestBase): # history with number ni = 11 - history = list() - citer = obj.traverse() + history = [obj.parents[0]] for pn in range(ni): - history.append(citer.next()) + history.append(history[-1].parents[0]) # END get given amount of commits for pn in range(11): @@ -430,11 +434,14 @@ class TestRepo(TestBase): self._assert_rev_parse_types(rev, obj2) # END for each parent - return obj + return orig_obj def test_rev_parse(self): rev_parse = self.rorepo.rev_parse + # it works with tags ! + self._assert_rev_parse('0.1.4') + # start from reference num_resolved = 0 for ref in Reference.iter_items(self.rorepo): @@ -447,7 +454,6 @@ class TestRepo(TestBase): num_resolved += 1 except BadObject: print "failed on %s" % path_section - raise # is fine, in case we have something like 112, which belongs to remotes/rname/merge-requests/112 pass # END exception handling @@ -467,6 +473,12 @@ class TestRepo(TestBase): # dereference tag using ^{} notation + # ref^0 returns commit being pointed to, same with ref~0 + tag = rev_parse('0.1.4') + for token in ('~^'): + assert tag.object == rev_parse('0.1.4%s0' % token) + # END handle multiple tokens + # missing closing brace commit^{tree # missing starting brace -- cgit v1.2.1 From 73959f3a2d4f224fbda03c8a8850f66f53d8cb3b Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 6 Jul 2010 12:09:11 +0200 Subject: Implemented main rev-parsing, including long hexshas, tags and refs. Short Shas still to be done --- test/git/test_repo.py | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 89c7f6b5..b2891378 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -381,6 +381,9 @@ class TestRepo(TestBase): def _assert_rev_parse_types(self, name, rev_obj): rev_parse = self.rorepo.rev_parse + if rev_obj.type == 'tag': + rev_obj = rev_obj.object + # tree and blob type obj = rev_parse(name + '^{tree}') assert obj == rev_obj.tree @@ -439,9 +442,6 @@ class TestRepo(TestBase): def test_rev_parse(self): rev_parse = self.rorepo.rev_parse - # it works with tags ! - self._assert_rev_parse('0.1.4') - # start from reference num_resolved = 0 for ref in Reference.iter_items(self.rorepo): @@ -461,29 +461,53 @@ class TestRepo(TestBase): # END for each reference assert num_resolved + # it works with tags ! + tag = self._assert_rev_parse('0.1.4') + assert tag.type == 'tag' + # try full sha directly ( including type conversion ) + assert tag.object == rev_parse(tag.object.hexsha) + self._assert_rev_parse_types(tag.object.hexsha, tag.object) # multiple tree types result in the same tree: HEAD^{tree}^{tree}:CHANGES + rev = '0.1.4^{tree}^{tree}' + assert rev_parse(rev) == tag.object.tree + assert rev_parse(rev+':CHANGES') == tag.object.tree['CHANGES'] + # try to get parents from first revision - it should fail as no such revision # exists + first_rev = "33ebe7acec14b25c5f84f35a664803fcab2f7781" + commit = rev_parse(first_rev) + assert len(commit.parents) == 0 + assert commit.hexsha == first_rev + self.failUnlessRaises(BadObject, rev_parse, first_rev+"~") + self.failUnlessRaises(BadObject, rev_parse, first_rev+"^") + + # short SHA1 + commit2 = rev_parse(first_rev[:20]) + assert commit2 == commit + commit2 = rev_parse(first_rev[:5]) + assert commit2 == commit + # todo: dereference tag into a blob 0.1.7^{blob} - quite a special one + # needs a tag which points to a blob - # dereference tag using ^{} notation - # ref^0 returns commit being pointed to, same with ref~0 + # ref^0 returns commit being pointed to, same with ref~0, and ^{} tag = rev_parse('0.1.4') - for token in ('~^'): - assert tag.object == rev_parse('0.1.4%s0' % token) + for token in (('~0', '^0', '^{}')): + assert tag.object == rev_parse('0.1.4%s' % token) # END handle multiple tokens # missing closing brace commit^{tree + self.failUnlessRaises(ValueError, rev_parse, '0.1.4^{tree') # missing starting brace + self.failUnlessRaises(ValueError, rev_parse, '0.1.4^tree}') - # not enough parents ^10 # cannot handle rev-log for now self.failUnlessRaises(ValueError, rev_parse, "hi@there") -- cgit v1.2.1 From f068cdc5a1a13539c4a1d756ae950aab65f5348b Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 7 Jul 2010 12:16:13 +0200 Subject: Initially working implementation of short-sha parsing and interpretation, thanks to new gitdb functionality --- test/git/test_repo.py | 73 +++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 34 deletions(-) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index b2891378..5f663d6f 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -3,43 +3,45 @@ # # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php - -import os, sys from test.testlib import * from git import * from git.util import join_path_native +from git.exc import BadObject +from gitdb.util import hex_to_bin + +import os, sys import tempfile import shutil from cStringIO import StringIO -from git.exc import BadObject + class TestRepo(TestBase): @raises(InvalidGitRepositoryError) - def _test_new_should_raise_on_invalid_repo_location(self): + def test_new_should_raise_on_invalid_repo_location(self): Repo(tempfile.gettempdir()) @raises(NoSuchPathError) - def _test_new_should_raise_on_non_existant_path(self): + def test_new_should_raise_on_non_existant_path(self): Repo("repos/foobar") - def _test_repo_creation_from_different_paths(self): + def test_repo_creation_from_different_paths(self): r_from_gitdir = Repo(self.rorepo.git_dir) assert r_from_gitdir.git_dir == self.rorepo.git_dir assert r_from_gitdir.git_dir.endswith('.git') assert not self.rorepo.git.working_dir.endswith('.git') assert r_from_gitdir.git.working_dir == self.rorepo.git.working_dir - def _test_description(self): + def test_description(self): txt = "Test repository" self.rorepo.description = txt assert_equal(self.rorepo.description, txt) - def _test_heads_should_return_array_of_head_objects(self): + def test_heads_should_return_array_of_head_objects(self): for head in self.rorepo.heads: assert_equal(Head, head.__class__) - def _test_heads_should_populate_head_data(self): + def test_heads_should_populate_head_data(self): for head in self.rorepo.heads: assert head.name assert isinstance(head.commit,Commit) @@ -48,7 +50,7 @@ class TestRepo(TestBase): assert isinstance(self.rorepo.heads.master, Head) assert isinstance(self.rorepo.heads['master'], Head) - def _test_tree_from_revision(self): + def test_tree_from_revision(self): tree = self.rorepo.tree('0.1.6') assert len(tree.hexsha) == 40 assert tree.type == "tree" @@ -57,7 +59,7 @@ class TestRepo(TestBase): # try from invalid revision that does not exist self.failUnlessRaises(ValueError, self.rorepo.tree, 'hello world') - def _test_commits(self): + def test_commits(self): mc = 10 commits = list(self.rorepo.iter_commits('0.1.6', max_count=mc)) assert len(commits) == mc @@ -79,7 +81,7 @@ class TestRepo(TestBase): c = commits[1] assert isinstance(c.parents, tuple) - def _test_trees(self): + def test_trees(self): mc = 30 num_trees = 0 for tree in self.rorepo.iter_trees('0.1.5', max_count=mc): @@ -89,7 +91,7 @@ class TestRepo(TestBase): assert num_trees == mc - def _test_empty_repo(self, repo): + def _assert_empty_repo(self, repo): # test all kinds of things with an empty, freshly initialized repo. # It should throw good errors @@ -117,7 +119,7 @@ class TestRepo(TestBase): # END test repos with working tree - def _test_init(self): + def test_init(self): prev_cwd = os.getcwd() os.chdir(tempfile.gettempdir()) git_dir_rela = "repos/foo/bar.git" @@ -131,12 +133,12 @@ class TestRepo(TestBase): assert r.bare == True assert os.path.isdir(r.git_dir) - self._test_empty_repo(r) + self._assert_empty_repo(r) # test clone clone_path = path + "_clone" rc = r.clone(clone_path) - self._test_empty_repo(rc) + self._assert_empty_repo(rc) shutil.rmtree(git_dir_abs) try: @@ -153,7 +155,7 @@ class TestRepo(TestBase): r = Repo.init(bare=False) r.bare == False - self._test_empty_repo(r) + self._assert_empty_repo(r) finally: try: shutil.rmtree(del_dir_abs) @@ -162,17 +164,17 @@ class TestRepo(TestBase): os.chdir(prev_cwd) # END restore previous state - def _test_bare_property(self): + def test_bare_property(self): self.rorepo.bare - def _test_daemon_export(self): + def test_daemon_export(self): orig_val = self.rorepo.daemon_export self.rorepo.daemon_export = not orig_val assert self.rorepo.daemon_export == ( not orig_val ) self.rorepo.daemon_export = orig_val assert self.rorepo.daemon_export == orig_val - def _test_alternates(self): + def test_alternates(self): cur_alternates = self.rorepo.alternates # empty alternates self.rorepo.alternates = [] @@ -182,15 +184,15 @@ class TestRepo(TestBase): assert alts == self.rorepo.alternates self.rorepo.alternates = cur_alternates - def _test_repr(self): + def test_repr(self): path = os.path.join(os.path.abspath(GIT_REPO), '.git') assert_equal('' % path, repr(self.rorepo)) - def _test_is_dirty_with_bare_repository(self): + def test_is_dirty_with_bare_repository(self): self.rorepo._bare = True assert_false(self.rorepo.is_dirty()) - def _test_is_dirty(self): + def test_is_dirty(self): self.rorepo._bare = False for index in (0,1): for working_tree in (0,1): @@ -202,23 +204,23 @@ class TestRepo(TestBase): self.rorepo._bare = True assert self.rorepo.is_dirty() == False - def _test_head(self): + def test_head(self): assert self.rorepo.head.reference.object == self.rorepo.active_branch.object - def _test_index(self): + def test_index(self): index = self.rorepo.index assert isinstance(index, IndexFile) - def _test_tag(self): + def test_tag(self): assert self.rorepo.tag('refs/tags/0.1.5').commit - def _test_archive(self): + def test_archive(self): tmpfile = os.tmpfile() self.rorepo.archive(tmpfile, '0.1.5') assert tmpfile.tell() @patch_object(Git, '_call_process') - def _test_should_display_blame_information(self, git): + def test_should_display_blame_information(self, git): git.return_value = fixture('blame') b = self.rorepo.blame( 'master', 'lib/git.py') assert_equal(13, len(b)) @@ -244,7 +246,7 @@ class TestRepo(TestBase): assert_true( isinstance( tlist[0], basestring ) ) assert_true( len( tlist ) < sum( len(t) for t in tlist ) ) # test for single-char bug - def _test_untracked_files(self): + def test_untracked_files(self): base = self.rorepo.working_tree_dir files = ( join_path_native(base, "__test_myfile"), join_path_native(base, "__test_other_file") ) @@ -270,13 +272,13 @@ class TestRepo(TestBase): assert len(self.rorepo.untracked_files) == (num_recently_untracked - len(files)) - def _test_config_reader(self): + def test_config_reader(self): reader = self.rorepo.config_reader() # all config files assert reader.read_only reader = self.rorepo.config_reader("repository") # single config file assert reader.read_only - def _test_config_writer(self): + def test_config_writer(self): for config_level in self.rorepo.config_level: try: writer = self.rorepo.config_writer(config_level) @@ -287,7 +289,7 @@ class TestRepo(TestBase): pass # END for each config level - def _test_creation_deletion(self): + def test_creation_deletion(self): # just a very quick test to assure it generally works. There are # specialized cases in the test_refs module head = self.rorepo.create_head("new_head", "HEAD~1") @@ -299,12 +301,12 @@ class TestRepo(TestBase): remote = self.rorepo.create_remote("new_remote", "git@server:repo.git") self.rorepo.delete_remote(remote) - def _test_comparison_and_hash(self): + def test_comparison_and_hash(self): # this is only a preliminary test, more testing done in test_index assert self.rorepo == self.rorepo and not (self.rorepo != self.rorepo) assert len(set((self.rorepo, self.rorepo))) == 1 - def _test_git_cmd(self): + def test_git_cmd(self): # test CatFileContentStream, just to be very sure we have no fencepost errors # last \n is the terminating newline that it expects l1 = "0123456789\n" @@ -442,6 +444,9 @@ class TestRepo(TestBase): def test_rev_parse(self): rev_parse = self.rorepo.rev_parse + # try special case: This one failed beforehand + assert self.rorepo.odb.partial_to_complete_sha_hex("33ebe") == hex_to_bin("33ebe7acec14b25c5f84f35a664803fcab2f7781") + # start from reference num_resolved = 0 for ref in Reference.iter_items(self.rorepo): -- cgit v1.2.1 From bc31651674648f026464fd4110858c4ffeac3c18 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 7 Jul 2010 17:30:47 +0200 Subject: Adjusted previous object creators to use the rev_parse method directly. rev_parse could be adjusted not to return Objects anymore, providing better performance for those who just want a sha only. On the other hand, the method is high-level and should be convenient to use as well, its a starting point for more usually, hence its unlikely to call it in tight loops --- test/git/test_repo.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 5f663d6f..53829556 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -7,7 +7,7 @@ from test.testlib import * from git import * from git.util import join_path_native from git.exc import BadObject -from gitdb.util import hex_to_bin +from gitdb.util import hex_to_bin, bin_to_hex import os, sys import tempfile @@ -57,7 +57,12 @@ class TestRepo(TestBase): assert self.rorepo.tree(tree) == tree # try from invalid revision that does not exist - self.failUnlessRaises(ValueError, self.rorepo.tree, 'hello world') + self.failUnlessRaises(BadObject, self.rorepo.tree, 'hello world') + + def test_commit_from_revision(self): + commit = self.rorepo.commit('0.1.4') + assert commit.type == 'commit' + assert self.rorepo.commit(commit) == commit def test_commits(self): mc = 10 @@ -445,7 +450,7 @@ class TestRepo(TestBase): rev_parse = self.rorepo.rev_parse # try special case: This one failed beforehand - assert self.rorepo.odb.partial_to_complete_sha_hex("33ebe") == hex_to_bin("33ebe7acec14b25c5f84f35a664803fcab2f7781") + assert rev_parse("33ebe").hexsha == "33ebe7acec14b25c5f84f35a664803fcab2f7781" # start from reference num_resolved = 0 @@ -507,6 +512,16 @@ class TestRepo(TestBase): assert tag.object == rev_parse('0.1.4%s' % token) # END handle multiple tokens + # try partial parsing + max_items = 40 + for i, binsha in enumerate(self.rorepo.odb.sha_iter()): + assert rev_parse(bin_to_hex(binsha)[:8-(i%2)]).binsha == binsha + if i > max_items: + # this is rather slow currently, as rev_parse returns an object + # which requires accessing packs, it has some additional overhead + break + # END for each binsha in repo + # missing closing brace commit^{tree self.failUnlessRaises(ValueError, rev_parse, '0.1.4^{tree') -- cgit v1.2.1