From 2da2b90e6930023ec5739ae0b714bbdb30874583 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 15 Oct 2009 12:09:16 +0200 Subject: repo: removed a few methods because of redundancy or because it will be obsolete once the interface overhaul is finished. This commit is just intermediate --- test/git/test_commit.py | 3 +++ test/git/test_repo.py | 9 --------- 2 files changed, 3 insertions(+), 9 deletions(-) (limited to 'test/git') diff --git a/test/git/test_commit.py b/test/git/test_commit.py index a95fb675..46aff635 100644 --- a/test/git/test_commit.py +++ b/test/git/test_commit.py @@ -215,6 +215,9 @@ class TestCommit(object): for sha1, commit in zip(expected_ids, commits): assert_equal(sha1, commit.id) + def test_count(self): + assert Commit.count( self.repo, '0.1.5' ) == 141 + def test_str(self): commit = Commit(self.repo, id='abc') assert_equal ("abc", str(commit)) diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 918e4769..24a13ed1 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -65,15 +65,6 @@ class TestRepo(object): assert_true(git.called) - @patch_object(Git, '_call_process') - def test_commit_count(self, git): - git.return_value = fixture('rev_list_count') - - assert_equal(655, self.repo.commit_count('master')) - - assert_true(git.called) - assert_equal(git.call_args, (('rev_list', 'master', '--', ''), {})) - @patch_object(Git, '_call_process') def test_commit(self, git): git.return_value = ListProcessAdapter(fixture('rev_list_single')) -- cgit v1.2.3 From 9ce1193c851e98293a237ad3d2d87725c501e89f Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 15 Oct 2009 14:11:34 +0200 Subject: Added Commit.iter_parents to iterate all parents Renamed Commit.commits to iter_commits repo: assured proper use of the terms revision ( rev ) and reference ( ref ) --- test/git/test_base.py | 2 +- test/git/test_commit.py | 10 ++++++++++ test/git/test_performance.py | 2 +- test/git/test_repo.py | 4 +--- 4 files changed, 13 insertions(+), 5 deletions(-) (limited to 'test/git') diff --git a/test/git/test_base.py b/test/git/test_base.py index 48d628c3..04222e2e 100644 --- a/test/git/test_base.py +++ b/test/git/test_base.py @@ -62,7 +62,7 @@ class TestBase(object): ref_count = 0 for ref in chain(self.repo.tags, self.repo.heads): ref_count += 1 - assert isinstance(ref, refs.Ref) + assert isinstance(ref, refs.Reference) assert str(ref) == ref.name assert repr(ref) assert ref == ref diff --git a/test/git/test_commit.py b/test/git/test_commit.py index 46aff635..4e698ed0 100644 --- a/test/git/test_commit.py +++ b/test/git/test_commit.py @@ -233,3 +233,13 @@ class TestCommit(object): assert_equal(commit1, commit2) assert_not_equal(commit2, commit3) + def test_iter_parents(self): + # should return all but ourselves, even if skip is defined + c = self.repo.commit('0.1.5') + for skip in (0, 1): + piter = c.iter_parents(skip=skip) + first_parent = piter.next() + assert first_parent != c + assert first_parent == c.parents[0] + # END for each + diff --git a/test/git/test_performance.py b/test/git/test_performance.py index 96f13a2e..77567515 100644 --- a/test/git/test_performance.py +++ b/test/git/test_performance.py @@ -21,7 +21,7 @@ class TestPerformance(object): # return quite a lot of commits, we just take one and hence abort the operation st = time() - for c in self.repo.commits(): + for c in self.repo.iter_commits('0.1.6'): num_commits += 1 c.author c.authored_date diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 24a13ed1..5869fb6a 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -42,7 +42,7 @@ class TestRepo(object): def test_commits(self, git): git.return_value = ListProcessAdapter(fixture('rev_list')) - commits = self.repo.commits('master', max_count=10) + commits = list( self.repo.iter_commits('master', max_count=10) ) c = commits[0] assert_equal('4c8124ffcf4039d292442eeccabdeca5af5c5017', c.id) @@ -73,8 +73,6 @@ class TestRepo(object): assert_equal("4c8124ffcf4039d292442eeccabdeca5af5c5017", commit.id) - assert_true(git.called) - @patch_object(Repo, '__init__') @patch_object(Git, '_call_process') def test_init_bare(self, git, repo): -- cgit v1.2.3 From 39229db70e71a6be275dafb3dd9468930e40ae48 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 15 Oct 2009 15:42:00 +0200 Subject: Object can now create objects of the proper type in case one attempts to create an object directly - this feature is used in several places now, allowing for additional type-checking --- test/git/test_repo.py | 8 -------- 1 file changed, 8 deletions(-) (limited to 'test/git') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 5869fb6a..cefd1349 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -65,14 +65,6 @@ class TestRepo(object): assert_true(git.called) - @patch_object(Git, '_call_process') - def test_commit(self, git): - git.return_value = ListProcessAdapter(fixture('rev_list_single')) - - commit = self.repo.commit('4c8124ffcf4039d292442eeccabdeca5af5c5017') - - assert_equal("4c8124ffcf4039d292442eeccabdeca5af5c5017", commit.id) - @patch_object(Repo, '__init__') @patch_object(Git, '_call_process') def test_init_bare(self, git, repo): -- cgit v1.2.3 From 00c5497f190172765cc7a53ff9d8852a26b91676 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 15 Oct 2009 16:52:20 +0200 Subject: repo: made init and clone methods less specific, previously they wanted to do it 'barely' only. New method names closely follow the default git command names --- test/git/test_repo.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'test/git') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index cefd1349..cbfc27c4 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -67,55 +67,53 @@ class TestRepo(object): @patch_object(Repo, '__init__') @patch_object(Git, '_call_process') - def test_init_bare(self, git, repo): + def test_init(self, git, repo): git.return_value = True repo.return_value = None - Repo.init_bare("repos/foo/bar.git") + r = Repo.init("repos/foo/bar.git", bare=True) + assert isinstance(r, Repo) assert_true(git.called) - assert_equal(git.call_args, (('init', '--bare'), {})) assert_true(repo.called) - assert_equal(repo.call_args, (('repos/foo/bar.git',), {})) @patch_object(Repo, '__init__') @patch_object(Git, '_call_process') - def test_init_bare_with_options(self, git, repo): + def test_init_with_options(self, git, repo): git.return_value = True repo.return_value = None - Repo.init_bare("repos/foo/bar.git", **{'template': "/baz/sweet"}) + r = Repo.init("repos/foo/bar.git", **{'bare' : True,'template': "/baz/sweet"}) + assert isinstance(r, Repo) assert_true(git.called) - assert_equal(git.call_args, (('init', '--bare'), {'template': '/baz/sweet'})) assert_true(repo.called) - assert_equal(repo.call_args, (('repos/foo/bar.git',), {})) @patch_object(Repo, '__init__') @patch_object(Git, '_call_process') - def test_fork_bare(self, git, repo): + def test_clone(self, git, repo): git.return_value = None repo.return_value = None - self.repo.fork_bare("repos/foo/bar.git") + self.repo.clone("repos/foo/bar.git") assert_true(git.called) path = os.path.join(absolute_project_path(), '.git') - assert_equal(git.call_args, (('clone', path, 'repos/foo/bar.git'), {'bare': True})) + assert_equal(git.call_args, (('clone', path, 'repos/foo/bar.git'), {})) assert_true(repo.called) @patch_object(Repo, '__init__') @patch_object(Git, '_call_process') - def test_fork_bare_with_options(self, git, repo): + def test_clone_with_options(self, git, repo): git.return_value = None repo.return_value = None - self.repo.fork_bare("repos/foo/bar.git", **{'template': '/awesome'}) + self.repo.clone("repos/foo/bar.git", **{'template': '/awesome'}) assert_true(git.called) path = os.path.join(absolute_project_path(), '.git') assert_equal(git.call_args, (('clone', path, 'repos/foo/bar.git'), - {'bare': True, 'template': '/awesome'})) + { 'template': '/awesome'})) assert_true(repo.called) @patch_object(Git, '_call_process') -- cgit v1.2.3 From b67bd4c730273a9b6cce49a8444fb54e654de540 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 15 Oct 2009 18:05:28 +0200 Subject: Improved archive function by allowing it to directly write to an output stream - previously it would cache everything to memory and try to provide zipping functionality itself gitcmd: allows the output stream to be set explicitly which is mainly useful for archiving operations --- test/git/test_repo.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'test/git') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index cbfc27c4..96d08b91 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -141,11 +141,14 @@ class TestRepo(object): assert_equal(15, len(diffs)) assert_true(git.called) - def test_archive_tar(self): - assert self.repo.archive_tar() - - def test_archive_tar_gz(self): - assert self.repo.archive_tar_gz() + def test_archive(self): + args = ( tuple(), (self.repo.heads[-1],),(None,"hello") ) + for arg_list in args: + ftmp = os.tmpfile() + self.repo.archive(ftmp, *arg_list) + ftmp.seek(0,2) + assert ftmp.tell() + # END for each arg-list @patch('git.utils.touch') def test_enable_daemon_serve(self, touch): -- cgit v1.2.3