From 92a97480edcc0f0de787a752bf90feed0445dd39 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 9 Oct 2009 11:57:48 +0200 Subject: Blob|Tree: renamed 'name' member to 'path', updated tests and changelog as it would make existing code incompatible in some places --- test/git/test_blob.py | 2 +- test/git/test_commit.py | 20 ++++++++++---------- test/git/test_tree.py | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) (limited to 'test/git') diff --git a/test/git/test_blob.py b/test/git/test_blob.py index 5bd74ff7..8741fc1d 100644 --- a/test/git/test_blob.py +++ b/test/git/test_blob.py @@ -57,7 +57,7 @@ class TestBlob(object): assert_equal(git.call_args, (('cat_file', 'abc'), {'s': True})) def test_mime_type_should_return_mime_type_for_known_types(self): - blob = Blob(self.repo, **{'id': 'abc', 'name': 'foo.png'}) + blob = Blob(self.repo, **{'id': 'abc', 'path': 'foo.png'}) assert_equal("image/png", blob.mime_type) def test_mime_type_should_return_text_plain_for_unknown_types(self): diff --git a/test/git/test_commit.py b/test/git/test_commit.py index d6bd6120..fb376b02 100644 --- a/test/git/test_commit.py +++ b/test/git/test_commit.py @@ -37,8 +37,8 @@ class TestCommit(object): assert_equal(15, len(diffs)) - assert_equal('.gitignore', diffs[0].a_blob.name) - assert_equal('.gitignore', diffs[0].b_blob.name) + assert_equal('.gitignore', diffs[0].a_blob.path) + assert_equal('.gitignore', diffs[0].b_blob.path) assert_equal('4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diffs[0].a_blob.id) assert_equal('2dd02534615434d88c51307beb0f0092f21fd103', diffs[0].b_blob.id) assert_equal('100644', diffs[0].b_blob.mode) @@ -46,7 +46,7 @@ class TestCommit(object): assert_equal(False, diffs[0].deleted_file) assert_equal("--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg", diffs[0].diff) - assert_equal('lib/grit/actor.rb', diffs[5].b_blob.name) + assert_equal('lib/grit/actor.rb', diffs[5].b_blob.path) assert_equal(None, diffs[5].a_blob) assert_equal('f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_blob.id) assert_equal( None, diffs[5].a_mode ) @@ -89,7 +89,7 @@ class TestCommit(object): diffs = Commit.diff(self.repo, '59ddc32', ['lib']) assert_equal(1, len(diffs)) - assert_equal('lib/grit/diff.rb', diffs[0].a_blob.name) + assert_equal('lib/grit/diff.rb', diffs[0].a_blob.path) assert_true(git.called) assert_equal(git.call_args, (('diff', '-M', '59ddc32', '--', 'lib'), {'full_index': True})) @@ -101,7 +101,7 @@ class TestCommit(object): diffs = Commit.diff(self.repo, '59ddc32', '13d27d5', ['lib']) assert_equal(1, len(diffs)) - assert_equal('lib/grit/commit.rb', diffs[0].a_blob.name) + assert_equal('lib/grit/commit.rb', diffs[0].a_blob.path) assert_true(git.called) assert_equal(git.call_args, (('diff', '-M', '59ddc32', '13d27d5', '--', 'lib'), {'full_index': True})) @@ -115,8 +115,8 @@ class TestCommit(object): assert_equal(15, len(diffs)) - assert_equal('.gitignore', diffs[0].a_blob.name) - assert_equal('.gitignore', diffs[0].b_blob.name) + assert_equal('.gitignore', diffs[0].a_blob.path) + assert_equal('.gitignore', diffs[0].b_blob.path) assert_equal('4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diffs[0].a_blob.id) assert_equal('2dd02534615434d88c51307beb0f0092f21fd103', diffs[0].b_blob.id) assert_equal('100644', diffs[0].b_blob.mode) @@ -124,7 +124,7 @@ class TestCommit(object): assert_equal(False, diffs[0].deleted_file) assert_equal("--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg", diffs[0].diff) - assert_equal('lib/grit/actor.rb', diffs[5].b_blob.name) + assert_equal('lib/grit/actor.rb', diffs[5].b_blob.path) assert_equal(None, diffs[5].a_blob) assert_equal('f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_blob.id) assert_equal(True, diffs[5].new_file) @@ -145,7 +145,7 @@ class TestCommit(object): assert_equal(10, len(diffs)) - assert_equal('History.txt', diffs[0].b_blob.name) + assert_equal('History.txt', diffs[0].b_blob.path) assert_equal(None, diffs[0].a_blob) assert_equal('100644', diffs[0].b_blob.mode) assert_equal('81d2c27608b352814cbe979a6acd678d30219678', diffs[0].b_blob.id) @@ -153,7 +153,7 @@ class TestCommit(object): assert_equal(False, diffs[0].deleted_file) assert_equal("--- /dev/null\n+++ b/History.txt\n@@ -0,0 +1,5 @@\n+== 1.0.0 / 2007-10-09\n+\n+* 1 major enhancement\n+ * Birthday!\n+", diffs[0].diff) - assert_equal('lib/grit.rb', diffs[5].b_blob.name) + assert_equal('lib/grit.rb', diffs[5].b_blob.path) assert_equal(None, diffs[5].a_blob) assert_equal('32cec87d1e78946a827ddf6a8776be4d81dcf1d1', diffs[5].b_blob.id) assert_equal(True, diffs[5].new_file) diff --git a/test/git/test_tree.py b/test/git/test_tree.py index 947b0ffb..3946a33c 100644 --- a/test/git/test_tree.py +++ b/test/git/test_tree.py @@ -32,7 +32,7 @@ class TestTree(object): assert_equal(Tree, tree.__class__) assert_equal("650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44", tree.id) assert_equal("040000", tree.mode) - assert_equal("test", tree.name) + assert_equal("test", tree.path) def test_content_from_string_tree_should_return_blob(self): text = fixture('ls_tree_b').split("\n")[0] @@ -42,7 +42,7 @@ class TestTree(object): assert_equal(Blob, tree.__class__) assert_equal("aa94e396335d2957ca92606f909e53e7beaf3fbb", tree.id) assert_equal("100644", tree.mode) - assert_equal("grit.rb", tree.name) + assert_equal("grit.rb", tree.path) def test_content_from_string_tree_should_return_commit(self): text = fixture('ls_tree_commit').split("\n")[1] -- cgit v1.2.3 From 9ee31065abea645cbc2cf3e54b691d5983a228b2 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Oct 2009 11:01:12 +0200 Subject: Intermediate commit: commit,tree and blob objects now derive from object - test is in place which still fails on purpose. Need to integrate tags which can be objects or just a special form of a ref --- test/git/test_base.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test/git/test_base.py (limited to 'test/git') diff --git a/test/git/test_base.py b/test/git/test_base.py new file mode 100644 index 00000000..46869f63 --- /dev/null +++ b/test/git/test_base.py @@ -0,0 +1,36 @@ +# test_base.py +# Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors +# +# This module is part of GitPython and is released under +# the BSD License: http://www.opensource.org/licenses/bsd-license.php + +import time +from test.testlib import * +from git import * + +class TestBase(object): + + type_tuples = ( ("blob", "8741fc1d09d61f02ffd8cded15ff603eff1ec070"), + ("tree", "3a6a5e3eeed3723c09f1ef0399f81ed6b8d82e79"), + ("commit", "4251bd59fb8e11e40c40548cba38180a9536118c") ) + + def setup(self): + self.repo = Repo(GIT_REPO) + + def test_base(self): + # test interface of base classes + fcreators = (self.repo.blob, self.repo.tree, self.repo.commit ) + assert len(fcreators) == len(self.type_tuples) + for fcreator, (typename, hexsha) in zip(fcreators, self.type_tuples): + item = fcreator(hexsha) + assert item.id == hexsha + assert item.type == typename + assert item.size + # END for each object type to create + + assert False,"TODO: Test for all types" + + def test_tags(self): + # tag refs can point to tag objects or to commits + assert False, "TODO: Tag handling" + -- cgit v1.2.3 From 20f202d83bdf1f332a3cb8f010bcf8bf3c2807bd Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Oct 2009 16:36:51 +0200 Subject: Re-designed the tag testing - it does not use fixtures anymore but dyamically checks the existance of tags within the repository - it basically tests the interface and checks that expected return types are actually returned --- test/git/test_base.py | 8 ++++++++ test/git/test_tag.py | 45 ++++++++++++++++++++++----------------------- 2 files changed, 30 insertions(+), 23 deletions(-) (limited to 'test/git') diff --git a/test/git/test_base.py b/test/git/test_base.py index 46869f63..787b92b6 100644 --- a/test/git/test_base.py +++ b/test/git/test_base.py @@ -7,6 +7,7 @@ import time from test.testlib import * from git import * +import git.base as base class TestBase(object): @@ -33,4 +34,11 @@ class TestBase(object): def test_tags(self): # tag refs can point to tag objects or to commits assert False, "TODO: Tag handling" + + def test_get_type_by_name(self): + for tname in base.Object.TYPES: + assert base.Object in base.Object.get_type_by_name(tname).mro() + # END for each known type + + assert_raises( ValueError, base.Object.get_type_by_name, "doesntexist" ) diff --git a/test/git/test_tag.py b/test/git/test_tag.py index 732bbd45..52f7898c 100644 --- a/test/git/test_tag.py +++ b/test/git/test_tag.py @@ -7,30 +7,29 @@ from mock import * from test.testlib import * from git import * +from git.tag import TagObject +import time class TestTag(object): - def setup(self): - self.repo = Repo(GIT_REPO) + def setup(self): + self.repo = Repo(GIT_REPO) - @patch_object(Git, '_call_process') - def test_list_from_string(self, git): - git.return_value = fixture('for_each_ref_tags') - - tags = self.repo.tags - - assert_equal(1, len(tags)) - assert_equal('v0.7.1', tags[0].name) - assert_equal('634396b2f541a9f2d58b00be1a07f0c358b999b3', tags[0].commit.id) - - assert_true(git.called) - assert_equal(git.call_args, (('for_each_ref', 'refs/tags'), {'sort': 'committerdate', 'format': '%(refname)%00%(objectname)'})) + def test_tag_base(self): + tag_object_refs = list() + for tag in self.repo.tags: + assert "refs/tags" in tag.path + assert "/" not in tag.name + assert isinstance( tag.commit, Commit ) + if tag.tag is not None: + tag_object_refs.append( tag ) + tagobj = tag.tag + assert isinstance( tagobj, TagObject ) + assert tagobj.tag == tag.name + assert isinstance( tagobj.tagger, Actor ) + assert isinstance( tagobj.tagged_date, time.struct_time ) + assert tagobj.message + # END if we have a tag object + # END for tag in repo-tags + assert tag_object_refs + - @patch_object(Git, '_call_process') - def test_repr(self, git): - git.return_value = fixture('for_each_ref') - - tag = self.repo.tags[0] - assert_equal('' % tag.name, repr(tag)) - - assert_true(git.called) - assert_equal(git.call_args, (('for_each_ref', 'refs/tags'), {'sort': 'committerdate', 'format': '%(refname)%00%(objectname)'})) -- cgit v1.2.3 From 9374a916588d9fe7169937ba262c86ad710cfa74 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Oct 2009 16:49:05 +0200 Subject: converted all spaces to tabs ( 4 spaces = 1 tab ) just to allow me and my editor to work with the files properly. Can convert it back for releaes --- test/git/test_actor.py | 28 ++-- test/git/test_blob.py | 158 +++++++++---------- test/git/test_commit.py | 394 +++++++++++++++++++++++------------------------ test/git/test_diff.py | 30 ++-- test/git/test_git.py | 94 +++++------ test/git/test_head.py | 38 ++--- test/git/test_repo.py | 402 ++++++++++++++++++++++++------------------------ test/git/test_stats.py | 34 ++-- test/git/test_tree.py | 234 ++++++++++++++-------------- test/git/test_utils.py | 18 +-- 10 files changed, 715 insertions(+), 715 deletions(-) (limited to 'test/git') diff --git a/test/git/test_actor.py b/test/git/test_actor.py index 862010fc..ae4da507 100644 --- a/test/git/test_actor.py +++ b/test/git/test_actor.py @@ -9,20 +9,20 @@ from test.testlib import * from git import * class TestActor(object): - def test_from_string_should_separate_name_and_email(self): - a = Actor.from_string("Michael Trier ") - assert_equal("Michael Trier", a.name) - assert_equal("mtrier@example.com", a.email) + def test_from_string_should_separate_name_and_email(self): + a = Actor.from_string("Michael Trier ") + assert_equal("Michael Trier", a.name) + assert_equal("mtrier@example.com", a.email) - def test_from_string_should_handle_just_name(self): - a = Actor.from_string("Michael Trier") - assert_equal("Michael Trier", a.name) - assert_equal(None, a.email) + def test_from_string_should_handle_just_name(self): + a = Actor.from_string("Michael Trier") + assert_equal("Michael Trier", a.name) + assert_equal(None, a.email) - def test_should_display_representation(self): - a = Actor.from_string("Michael Trier ") - assert_equal('">', repr(a)) + def test_should_display_representation(self): + a = Actor.from_string("Michael Trier ") + assert_equal('">', repr(a)) - def test_str_should_alias_name(self): - a = Actor.from_string("Michael Trier ") - assert_equal(a.name, str(a)) \ No newline at end of file + def test_str_should_alias_name(self): + a = Actor.from_string("Michael Trier ") + assert_equal(a.name, str(a)) \ No newline at end of file diff --git a/test/git/test_blob.py b/test/git/test_blob.py index 8741fc1d..e2ac22e1 100644 --- a/test/git/test_blob.py +++ b/test/git/test_blob.py @@ -9,89 +9,89 @@ from test.testlib import * from git import * class TestBlob(object): - def setup(self): - self.repo = Repo(GIT_REPO) - - @patch_object(Git, '_call_process') - def test_should_return_blob_contents(self, git): - git.return_value = fixture('cat_file_blob') - blob = Blob(self.repo, **{'id': 'abc'}) - assert_equal("Hello world", blob.data) - assert_true(git.called) - assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True, 'with_raw_output': True})) + def setup(self): + self.repo = Repo(GIT_REPO) + + @patch_object(Git, '_call_process') + def test_should_return_blob_contents(self, git): + git.return_value = fixture('cat_file_blob') + blob = Blob(self.repo, **{'id': 'abc'}) + assert_equal("Hello world", blob.data) + assert_true(git.called) + assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True, 'with_raw_output': True})) - @patch_object(Git, '_call_process') - def test_should_return_blob_contents_with_newline(self, git): - git.return_value = fixture('cat_file_blob_nl') - blob = Blob(self.repo, **{'id': 'abc'}) - assert_equal("Hello world\n", blob.data) - assert_true(git.called) - assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True, 'with_raw_output': True})) - - @patch_object(Git, '_call_process') - def test_should_cache_data(self, git): - git.return_value = fixture('cat_file_blob') - blob = Blob(self.repo, **{'id': 'abc'}) - blob.data - blob.data - assert_true(git.called) - assert_equal(git.call_count, 1) - assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True, 'with_raw_output': True})) + @patch_object(Git, '_call_process') + def test_should_return_blob_contents_with_newline(self, git): + git.return_value = fixture('cat_file_blob_nl') + blob = Blob(self.repo, **{'id': 'abc'}) + assert_equal("Hello world\n", blob.data) + assert_true(git.called) + assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True, 'with_raw_output': True})) + + @patch_object(Git, '_call_process') + def test_should_cache_data(self, git): + git.return_value = fixture('cat_file_blob') + blob = Blob(self.repo, **{'id': 'abc'}) + blob.data + blob.data + assert_true(git.called) + assert_equal(git.call_count, 1) + assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True, 'with_raw_output': True})) - @patch_object(Git, '_call_process') - def test_should_return_file_size(self, git): - git.return_value = fixture('cat_file_blob_size') - blob = Blob(self.repo, **{'id': 'abc'}) - assert_equal(11, blob.size) - assert_true(git.called) - assert_equal(git.call_args, (('cat_file', 'abc'), {'s': True})) + @patch_object(Git, '_call_process') + def test_should_return_file_size(self, git): + git.return_value = fixture('cat_file_blob_size') + blob = Blob(self.repo, **{'id': 'abc'}) + assert_equal(11, blob.size) + assert_true(git.called) + assert_equal(git.call_args, (('cat_file', 'abc'), {'s': True})) - @patch_object(Git, '_call_process') - def test_should_cache_file_size(self, git): - git.return_value = fixture('cat_file_blob_size') - blob = Blob(self.repo, **{'id': 'abc'}) - assert_equal(11, blob.size) - assert_equal(11, blob.size) - assert_true(git.called) - assert_equal(git.call_count, 1) - assert_equal(git.call_args, (('cat_file', 'abc'), {'s': True})) + @patch_object(Git, '_call_process') + def test_should_cache_file_size(self, git): + git.return_value = fixture('cat_file_blob_size') + blob = Blob(self.repo, **{'id': 'abc'}) + assert_equal(11, blob.size) + assert_equal(11, blob.size) + assert_true(git.called) + assert_equal(git.call_count, 1) + assert_equal(git.call_args, (('cat_file', 'abc'), {'s': True})) - def test_mime_type_should_return_mime_type_for_known_types(self): - blob = Blob(self.repo, **{'id': 'abc', 'path': 'foo.png'}) - assert_equal("image/png", blob.mime_type) + def test_mime_type_should_return_mime_type_for_known_types(self): + blob = Blob(self.repo, **{'id': 'abc', 'path': 'foo.png'}) + assert_equal("image/png", blob.mime_type) - def test_mime_type_should_return_text_plain_for_unknown_types(self): - blob = Blob(self.repo, **{'id': 'abc'}) - assert_equal("text/plain", blob.mime_type) + def test_mime_type_should_return_text_plain_for_unknown_types(self): + blob = Blob(self.repo, **{'id': 'abc'}) + assert_equal("text/plain", blob.mime_type) - @patch_object(Git, '_call_process') - def test_should_display_blame_information(self, git): - git.return_value = fixture('blame') - b = Blob.blame(self.repo, 'master', 'lib/git.py') - assert_equal(13, len(b)) - assert_equal( 2, len(b[0]) ) - # assert_equal(25, reduce(lambda acc, x: acc + len(x[-1]), b)) - assert_equal(hash(b[0][0]), hash(b[9][0])) - c = b[0][0] - assert_true(git.called) - assert_equal(git.call_args, (('blame', 'master', '--', 'lib/git.py'), {'p': True})) - - assert_equal('634396b2f541a9f2d58b00be1a07f0c358b999b3', c.id) - assert_equal('Tom Preston-Werner', c.author.name) - assert_equal('tom@mojombo.com', c.author.email) - assert_equal(time.gmtime(1191997100), c.authored_date) - assert_equal('Tom Preston-Werner', c.committer.name) - assert_equal('tom@mojombo.com', c.committer.email) - assert_equal(time.gmtime(1191997100), c.committed_date) - assert_equal('initial grit setup', c.message) - - # test the 'lines per commit' entries - tlist = b[0][1] - assert_true( tlist ) - assert_true( isinstance( tlist[0], basestring ) ) - assert_true( len( tlist ) < sum( len(t) for t in tlist ) ) # test for single-char bug - + @patch_object(Git, '_call_process') + def test_should_display_blame_information(self, git): + git.return_value = fixture('blame') + b = Blob.blame(self.repo, 'master', 'lib/git.py') + assert_equal(13, len(b)) + assert_equal( 2, len(b[0]) ) + # assert_equal(25, reduce(lambda acc, x: acc + len(x[-1]), b)) + assert_equal(hash(b[0][0]), hash(b[9][0])) + c = b[0][0] + assert_true(git.called) + assert_equal(git.call_args, (('blame', 'master', '--', 'lib/git.py'), {'p': True})) + + assert_equal('634396b2f541a9f2d58b00be1a07f0c358b999b3', c.id) + assert_equal('Tom Preston-Werner', c.author.name) + assert_equal('tom@mojombo.com', c.author.email) + assert_equal(time.gmtime(1191997100), c.authored_date) + assert_equal('Tom Preston-Werner', c.committer.name) + assert_equal('tom@mojombo.com', c.committer.email) + assert_equal(time.gmtime(1191997100), c.committed_date) + assert_equal('initial grit setup', c.message) + + # test the 'lines per commit' entries + tlist = b[0][1] + assert_true( tlist ) + assert_true( isinstance( tlist[0], basestring ) ) + assert_true( len( tlist ) < sum( len(t) for t in tlist ) ) # test for single-char bug + - def test_should_return_appropriate_representation(self): - blob = Blob(self.repo, **{'id': 'abc'}) - assert_equal('', repr(blob)) + def test_should_return_appropriate_representation(self): + blob = Blob(self.repo, **{'id': 'abc'}) + assert_equal('', repr(blob)) diff --git a/test/git/test_commit.py b/test/git/test_commit.py index fb376b02..e92c13dd 100644 --- a/test/git/test_commit.py +++ b/test/git/test_commit.py @@ -8,241 +8,241 @@ from test.testlib import * from git import * class TestCommit(object): - def setup(self): - self.repo = Repo(GIT_REPO) + def setup(self): + self.repo = Repo(GIT_REPO) - @patch_object(Git, '_call_process') - def test_bake(self, git): - git.return_value = fixture('rev_list_single') + @patch_object(Git, '_call_process') + def test_bake(self, git): + git.return_value = fixture('rev_list_single') - commit = Commit(self.repo, **{'id': '4c8124ffcf4039d292442eeccabdeca5af5c5017'}) - commit.author # bake + commit = Commit(self.repo, **{'id': '4c8124ffcf4039d292442eeccabdeca5af5c5017'}) + commit.author # bake - assert_equal("Tom Preston-Werner", commit.author.name) - assert_equal("tom@mojombo.com", commit.author.email) + assert_equal("Tom Preston-Werner", commit.author.name) + assert_equal("tom@mojombo.com", commit.author.email) - assert_true(git.called) - assert_equal(git.call_args, (('rev_list', '4c8124ffcf4039d292442eeccabdeca5af5c5017', '--', ''), {'pretty': 'raw', 'max_count': 1})) + assert_true(git.called) + assert_equal(git.call_args, (('rev_list', '4c8124ffcf4039d292442eeccabdeca5af5c5017', '--', ''), {'pretty': 'raw', 'max_count': 1})) - @patch_object(Git, '_call_process') - def test_id_abbrev(self, git): - git.return_value = fixture('rev_list_commit_idabbrev') - assert_equal('80f136f', self.repo.commit('80f136f500dfdb8c3e8abf4ae716f875f0a1b57f').id_abbrev) + @patch_object(Git, '_call_process') + def test_id_abbrev(self, git): + git.return_value = fixture('rev_list_commit_idabbrev') + assert_equal('80f136f', self.repo.commit('80f136f500dfdb8c3e8abf4ae716f875f0a1b57f').id_abbrev) - @patch_object(Git, '_call_process') - def test_diff(self, git): - git.return_value = fixture('diff_p') + @patch_object(Git, '_call_process') + def test_diff(self, git): + git.return_value = fixture('diff_p') - diffs = Commit.diff(self.repo, 'master') + diffs = Commit.diff(self.repo, 'master') - assert_equal(15, len(diffs)) + assert_equal(15, len(diffs)) - assert_equal('.gitignore', diffs[0].a_blob.path) - assert_equal('.gitignore', diffs[0].b_blob.path) - assert_equal('4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diffs[0].a_blob.id) - assert_equal('2dd02534615434d88c51307beb0f0092f21fd103', diffs[0].b_blob.id) - assert_equal('100644', diffs[0].b_blob.mode) - assert_equal(False, diffs[0].new_file) - assert_equal(False, diffs[0].deleted_file) - assert_equal("--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg", diffs[0].diff) + assert_equal('.gitignore', diffs[0].a_blob.path) + assert_equal('.gitignore', diffs[0].b_blob.path) + assert_equal('4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diffs[0].a_blob.id) + assert_equal('2dd02534615434d88c51307beb0f0092f21fd103', diffs[0].b_blob.id) + assert_equal('100644', diffs[0].b_blob.mode) + assert_equal(False, diffs[0].new_file) + assert_equal(False, diffs[0].deleted_file) + assert_equal("--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg", diffs[0].diff) - assert_equal('lib/grit/actor.rb', diffs[5].b_blob.path) - assert_equal(None, diffs[5].a_blob) - assert_equal('f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_blob.id) - assert_equal( None, diffs[5].a_mode ) - assert_equal(True, diffs[5].new_file) + assert_equal('lib/grit/actor.rb', diffs[5].b_blob.path) + assert_equal(None, diffs[5].a_blob) + assert_equal('f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_blob.id) + assert_equal( None, diffs[5].a_mode ) + assert_equal(True, diffs[5].new_file) - assert_true(git.called) - assert_equal(git.call_args, (('diff', '-M', 'master'), {'full_index': True})) + assert_true(git.called) + assert_equal(git.call_args, (('diff', '-M', 'master'), {'full_index': True})) - @patch_object(Git, '_call_process') - def test_diff_with_rename(self, git): - git.return_value = fixture('diff_rename') + @patch_object(Git, '_call_process') + def test_diff_with_rename(self, git): + git.return_value = fixture('diff_rename') - diffs = Commit.diff(self.repo, 'rename') + diffs = Commit.diff(self.repo, 'rename') - assert_equal(1, len(diffs)) + assert_equal(1, len(diffs)) - diff = diffs[0] - assert_true(diff.renamed) - assert_equal(diff.rename_from, 'AUTHORS') - assert_equal(diff.rename_to, 'CONTRIBUTORS') + diff = diffs[0] + assert_true(diff.renamed) + assert_equal(diff.rename_from, 'AUTHORS') + assert_equal(diff.rename_to, 'CONTRIBUTORS') - assert_true(git.called) - assert_equal(git.call_args, (('diff', '-M', 'rename'), {'full_index': True})) + assert_true(git.called) + assert_equal(git.call_args, (('diff', '-M', 'rename'), {'full_index': True})) - @patch_object(Git, '_call_process') - def test_diff_with_two_commits(self, git): - git.return_value = fixture('diff_2') + @patch_object(Git, '_call_process') + def test_diff_with_two_commits(self, git): + git.return_value = fixture('diff_2') - diffs = Commit.diff(self.repo, '59ddc32', '13d27d5') + diffs = Commit.diff(self.repo, '59ddc32', '13d27d5') - assert_equal(3, len(diffs)) + assert_equal(3, len(diffs)) - assert_true(git.called) - assert_equal(git.call_args, (('diff', '-M', '59ddc32', '13d27d5'), {'full_index': True})) + assert_true(git.called) + assert_equal(git.call_args, (('diff', '-M', '59ddc32', '13d27d5'), {'full_index': True})) - @patch_object(Git, '_call_process') - def test_diff_with_files(self, git): - git.return_value = fixture('diff_f') + @patch_object(Git, '_call_process') + def test_diff_with_files(self, git): + git.return_value = fixture('diff_f') - diffs = Commit.diff(self.repo, '59ddc32', ['lib']) + diffs = Commit.diff(self.repo, '59ddc32', ['lib']) - assert_equal(1, len(diffs)) - assert_equal('lib/grit/diff.rb', diffs[0].a_blob.path) + assert_equal(1, len(diffs)) + assert_equal('lib/grit/diff.rb', diffs[0].a_blob.path) - assert_true(git.called) - assert_equal(git.call_args, (('diff', '-M', '59ddc32', '--', 'lib'), {'full_index': True})) + assert_true(git.called) + assert_equal(git.call_args, (('diff', '-M', '59ddc32', '--', 'lib'), {'full_index': True})) - @patch_object(Git, '_call_process') - def test_diff_with_two_commits_and_files(self, git): - git.return_value = fixture('diff_2f') + @patch_object(Git, '_call_process') + def test_diff_with_two_commits_and_files(self, git): + git.return_value = fixture('diff_2f') - diffs = Commit.diff(self.repo, '59ddc32', '13d27d5', ['lib']) + diffs = Commit.diff(self.repo, '59ddc32', '13d27d5', ['lib']) - assert_equal(1, len(diffs)) - assert_equal('lib/grit/commit.rb', diffs[0].a_blob.path) + assert_equal(1, len(diffs)) + assert_equal('lib/grit/commit.rb', diffs[0].a_blob.path) - assert_true(git.called) - assert_equal(git.call_args, (('diff', '-M', '59ddc32', '13d27d5', '--', 'lib'), {'full_index': True})) + assert_true(git.called) + assert_equal(git.call_args, (('diff', '-M', '59ddc32', '13d27d5', '--', 'lib'), {'full_index': True})) - @patch_object(Git, '_call_process') - def test_diffs(self, git): - git.return_value = fixture('diff_p') + @patch_object(Git, '_call_process') + def test_diffs(self, git): + git.return_value = fixture('diff_p') - commit = Commit(self.repo, id='91169e1f5fa4de2eaea3f176461f5dc784796769', parents=['038af8c329ef7c1bae4568b98bd5c58510465493']) - diffs = commit.diffs + commit = Commit(self.repo, id='91169e1f5fa4de2eaea3f176461f5dc784796769', parents=['038af8c329ef7c1bae4568b98bd5c58510465493']) + diffs = commit.diffs - assert_equal(15, len(diffs)) + assert_equal(15, len(diffs)) - assert_equal('.gitignore', diffs[0].a_blob.path) - assert_equal('.gitignore', diffs[0].b_blob.path) - assert_equal('4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diffs[0].a_blob.id) - assert_equal('2dd02534615434d88c51307beb0f0092f21fd103', diffs[0].b_blob.id) - assert_equal('100644', diffs[0].b_blob.mode) - assert_equal(False, diffs[0].new_file) - assert_equal(False, diffs[0].deleted_file) - assert_equal("--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg", diffs[0].diff) + assert_equal('.gitignore', diffs[0].a_blob.path) + assert_equal('.gitignore', diffs[0].b_blob.path) + assert_equal('4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diffs[0].a_blob.id) + assert_equal('2dd02534615434d88c51307beb0f0092f21fd103', diffs[0].b_blob.id) + assert_equal('100644', diffs[0].b_blob.mode) + assert_equal(False, diffs[0].new_file) + assert_equal(False, diffs[0].deleted_file) + assert_equal("--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg", diffs[0].diff) - assert_equal('lib/grit/actor.rb', diffs[5].b_blob.path) - assert_equal(None, diffs[5].a_blob) - assert_equal('f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_blob.id) - assert_equal(True, diffs[5].new_file) + assert_equal('lib/grit/actor.rb', diffs[5].b_blob.path) + assert_equal(None, diffs[5].a_blob) + assert_equal('f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_blob.id) + assert_equal(True, diffs[5].new_file) - assert_true(git.called) - assert_equal(git.call_args, (('diff', '-M', - '038af8c329ef7c1bae4568b98bd5c58510465493', - '91169e1f5fa4de2eaea3f176461f5dc784796769', - ), {'full_index': True})) + assert_true(git.called) + assert_equal(git.call_args, (('diff', '-M', + '038af8c329ef7c1bae4568b98bd5c58510465493', + '91169e1f5fa4de2eaea3f176461f5dc784796769', + ), {'full_index': True})) - @patch_object(Git, '_call_process') - def test_diffs_on_initial_import(self, git): - git.return_value = fixture('diff_i') - - commit = Commit(self.repo, id='634396b2f541a9f2d58b00be1a07f0c358b999b3') - commit.__bake_it__() - diffs = commit.diffs + @patch_object(Git, '_call_process') + def test_diffs_on_initial_import(self, git): + git.return_value = fixture('diff_i') + + commit = Commit(self.repo, id='634396b2f541a9f2d58b00be1a07f0c358b999b3') + commit.__bake_it__() + diffs = commit.diffs - assert_equal(10, len(diffs)) + assert_equal(10, len(diffs)) - assert_equal('History.txt', diffs[0].b_blob.path) - assert_equal(None, diffs[0].a_blob) - assert_equal('100644', diffs[0].b_blob.mode) - assert_equal('81d2c27608b352814cbe979a6acd678d30219678', diffs[0].b_blob.id) - assert_equal(True, diffs[0].new_file) - assert_equal(False, diffs[0].deleted_file) - assert_equal("--- /dev/null\n+++ b/History.txt\n@@ -0,0 +1,5 @@\n+== 1.0.0 / 2007-10-09\n+\n+* 1 major enhancement\n+ * Birthday!\n+", diffs[0].diff) + assert_equal('History.txt', diffs[0].b_blob.path) + assert_equal(None, diffs[0].a_blob) + assert_equal('100644', diffs[0].b_blob.mode) + assert_equal('81d2c27608b352814cbe979a6acd678d30219678', diffs[0].b_blob.id) + assert_equal(True, diffs[0].new_file) + assert_equal(False, diffs[0].deleted_file) + assert_equal("--- /dev/null\n+++ b/History.txt\n@@ -0,0 +1,5 @@\n+== 1.0.0 / 2007-10-09\n+\n+* 1 major enhancement\n+ * Birthday!\n+", diffs[0].diff) - assert_equal('lib/grit.rb', diffs[5].b_blob.path) - assert_equal(None, diffs[5].a_blob) - assert_equal('32cec87d1e78946a827ddf6a8776be4d81dcf1d1', diffs[5].b_blob.id) - assert_equal(True, diffs[5].new_file) + assert_equal('lib/grit.rb', diffs[5].b_blob.path) + assert_equal(None, diffs[5].a_blob) + assert_equal('32cec87d1e78946a827ddf6a8776be4d81dcf1d1', diffs[5].b_blob.id) + assert_equal(True, diffs[5].new_file) - assert_true(git.called) - assert_equal(git.call_args, (('show', '634396b2f541a9f2d58b00be1a07f0c358b999b3', '-M'), {'full_index': True, 'pretty': 'raw'})) + assert_true(git.called) + assert_equal(git.call_args, (('show', '634396b2f541a9f2d58b00be1a07f0c358b999b3', '-M'), {'full_index': True, 'pretty': 'raw'})) - @patch_object(Git, '_call_process') - def test_diffs_on_initial_import_with_empty_commit(self, git): - git.return_value = fixture('show_empty_commit') - - commit = Commit(self.repo, id='634396b2f541a9f2d58b00be1a07f0c358b999b3') - diffs = commit.diffs + @patch_object(Git, '_call_process') + def test_diffs_on_initial_import_with_empty_commit(self, git): + git.return_value = fixture('show_empty_commit') + + commit = Commit(self.repo, id='634396b2f541a9f2d58b00be1a07f0c358b999b3') + diffs = commit.diffs - assert_equal([], diffs) - - assert_true(git.called) - assert_equal(git.call_args, (('show', '634396b2f541a9f2d58b00be1a07f0c358b999b3', '-M'), {'full_index': True, 'pretty': 'raw'})) - - @patch_object(Git, '_call_process') - def test_diffs_with_mode_only_change(self, git): - git.return_value = fixture('diff_mode_only') - - commit = Commit(self.repo, id='91169e1f5fa4de2eaea3f176461f5dc784796769') - commit.__bake_it__() - diffs = commit.diffs - - # in case of mode-only changes, there is no blob - assert_equal(23, len(diffs)) - assert_equal(None, diffs[0].a_blob) - assert_equal(None, diffs[0].b_blob) - assert_equal('100644', diffs[0].a_mode) - assert_equal('100755', diffs[0].b_mode) - - assert_true(git.called) - assert_equal(git.call_args, (('show', '91169e1f5fa4de2eaea3f176461f5dc784796769', '-M'), {'full_index': True, 'pretty': 'raw'})) - - @patch_object(Git, '_call_process') - def test_stats(self, git): - git.return_value = fixture('diff_tree_numstat_root') - - commit = Commit(self.repo, id='634396b2f541a9f2d58b00be1a07f0c358b999b3') - commit.__bake_it__() - stats = commit.stats - - keys = stats.files.keys() - keys.sort() - assert_equal(["a.txt", "b.txt"], keys) - - assert_true(git.called) - assert_equal(git.call_args, (('diff_tree', '634396b2f541a9f2d58b00be1a07f0c358b999b3', '--'), {'numstat': True, 'root': True })) - - @patch_object(Git, '_call_process') - def test_rev_list_bisect_all(self, git): - """ - 'git rev-list --bisect-all' returns additional information - in the commit header. This test ensures that we properly parse it. - """ - - git.return_value = fixture('rev_list_bisect_all') - - revs = self.repo.git.rev_list('HEAD', - pretty='raw', - first_parent=True, - bisect_all=True) - assert_true(git.called) - - commits = Commit.list_from_string(self.repo, revs) - expected_ids = ( - 'cf37099ea8d1d8c7fbf9b6d12d7ec0249d3acb8b', - '33ebe7acec14b25c5f84f35a664803fcab2f7781', - 'a6604a00a652e754cb8b6b0b9f194f839fc38d7c', - '8df638c22c75ddc9a43ecdde90c0c9939f5009e7', - 'c231551328faa864848bde6ff8127f59c9566e90', - ) - for sha1, commit in zip(expected_ids, commits): - assert_equal(sha1, commit.id) - - def test_str(self): - commit = Commit(self.repo, id='abc') - assert_equal ("abc", str(commit)) - - def test_repr(self): - commit = Commit(self.repo, id='abc') - assert_equal('', repr(commit)) - - def test_equality(self): - commit1 = Commit(self.repo, id='abc') - commit2 = Commit(self.repo, id='abc') - commit3 = Commit(self.repo, id='zyx') - assert_equal(commit1, commit2) - assert_not_equal(commit2, commit3) + assert_equal([], diffs) + + assert_true(git.called) + assert_equal(git.call_args, (('show', '634396b2f541a9f2d58b00be1a07f0c358b999b3', '-M'), {'full_index': True, 'pretty': 'raw'})) + + @patch_object(Git, '_call_process') + def test_diffs_with_mode_only_change(self, git): + git.return_value = fixture('diff_mode_only') + + commit = Commit(self.repo, id='91169e1f5fa4de2eaea3f176461f5dc784796769') + commit.__bake_it__() + diffs = commit.diffs + + # in case of mode-only changes, there is no blob + assert_equal(23, len(diffs)) + assert_equal(None, diffs[0].a_blob) + assert_equal(None, diffs[0].b_blob) + assert_equal('100644', diffs[0].a_mode) + assert_equal('100755', diffs[0].b_mode) + + assert_true(git.called) + assert_equal(git.call_args, (('show', '91169e1f5fa4de2eaea3f176461f5dc784796769', '-M'), {'full_index': True, 'pretty': 'raw'})) + + @patch_object(Git, '_call_process') + def test_stats(self, git): + git.return_value = fixture('diff_tree_numstat_root') + + commit = Commit(self.repo, id='634396b2f541a9f2d58b00be1a07f0c358b999b3') + commit.__bake_it__() + stats = commit.stats + + keys = stats.files.keys() + keys.sort() + assert_equal(["a.txt", "b.txt"], keys) + + assert_true(git.called) + assert_equal(git.call_args, (('diff_tree', '634396b2f541a9f2d58b00be1a07f0c358b999b3', '--'), {'numstat': True, 'root': True })) + + @patch_object(Git, '_call_process') + def test_rev_list_bisect_all(self, git): + """ + 'git rev-list --bisect-all' returns additional information + in the commit header. This test ensures that we properly parse it. + """ + + git.return_value = fixture('rev_list_bisect_all') + + revs = self.repo.git.rev_list('HEAD', + pretty='raw', + first_parent=True, + bisect_all=True) + assert_true(git.called) + + commits = Commit.list_from_string(self.repo, revs) + expected_ids = ( + 'cf37099ea8d1d8c7fbf9b6d12d7ec0249d3acb8b', + '33ebe7acec14b25c5f84f35a664803fcab2f7781', + 'a6604a00a652e754cb8b6b0b9f194f839fc38d7c', + '8df638c22c75ddc9a43ecdde90c0c9939f5009e7', + 'c231551328faa864848bde6ff8127f59c9566e90', + ) + for sha1, commit in zip(expected_ids, commits): + assert_equal(sha1, commit.id) + + def test_str(self): + commit = Commit(self.repo, id='abc') + assert_equal ("abc", str(commit)) + + def test_repr(self): + commit = Commit(self.repo, id='abc') + assert_equal('', repr(commit)) + + def test_equality(self): + commit1 = Commit(self.repo, id='abc') + commit2 = Commit(self.repo, id='abc') + commit3 = Commit(self.repo, id='zyx') + assert_equal(commit1, commit2) + assert_not_equal(commit2, commit3) diff --git a/test/git/test_diff.py b/test/git/test_diff.py index 65a27e98..b9834879 100644 --- a/test/git/test_diff.py +++ b/test/git/test_diff.py @@ -8,23 +8,23 @@ from test.testlib import * from git import * class TestDiff(object): - def setup(self): - self.repo = Repo(GIT_REPO) + def setup(self): + self.repo = Repo(GIT_REPO) - def test_list_from_string_new_mode(self): - output = fixture('diff_new_mode') - diffs = Diff.list_from_string(self.repo, output) - assert_equal(1, len(diffs)) - assert_equal(10, len(diffs[0].diff.splitlines())) + def test_list_from_string_new_mode(self): + output = fixture('diff_new_mode') + diffs = Diff.list_from_string(self.repo, output) + assert_equal(1, len(diffs)) + assert_equal(10, len(diffs[0].diff.splitlines())) - def test_diff_with_rename(self): - output = fixture('diff_rename') - diffs = Diff.list_from_string(self.repo, output) + def test_diff_with_rename(self): + output = fixture('diff_rename') + diffs = Diff.list_from_string(self.repo, output) - assert_equal(1, len(diffs)) + assert_equal(1, len(diffs)) - diff = diffs[0] - assert_true(diff.renamed) - assert_equal(diff.rename_from, 'AUTHORS') - assert_equal(diff.rename_to, 'CONTRIBUTORS') + diff = diffs[0] + assert_true(diff.renamed) + assert_equal(diff.rename_from, 'AUTHORS') + assert_equal(diff.rename_to, 'CONTRIBUTORS') diff --git a/test/git/test_git.py b/test/git/test_git.py index 6e28f4c0..c9f399cc 100644 --- a/test/git/test_git.py +++ b/test/git/test_git.py @@ -9,50 +9,50 @@ from test.testlib import * from git import Git, GitCommandError class TestGit(object): - def setup(self): - base = os.path.join(os.path.dirname(__file__), "../..") - self.git = Git(base) - - @patch_object(Git, 'execute') - def test_call_process_calls_execute(self, git): - git.return_value = '' - self.git.version() - assert_true(git.called) - assert_equal(git.call_args, ((['git', 'version'],), {})) - - @raises(GitCommandError) - def test_it_raises_errors(self): - self.git.this_does_not_exist() - - - def test_it_transforms_kwargs_into_git_command_arguments(self): - assert_equal(["-s"], self.git.transform_kwargs(**{'s': True})) - assert_equal(["-s5"], self.git.transform_kwargs(**{'s': 5})) - - assert_equal(["--max-count"], self.git.transform_kwargs(**{'max_count': True})) - assert_equal(["--max-count=5"], self.git.transform_kwargs(**{'max_count': 5})) - - assert_equal(["-s", "-t"], self.git.transform_kwargs(**{'s': True, 't': True})) - - def test_it_executes_git_to_shell_and_returns_result(self): - assert_match('^git version [\d\.]{2}.*$', self.git.execute(["git","version"])) - - def test_it_accepts_stdin(self): - filename = fixture_path("cat_file_blob") - fh = open(filename, 'r') - assert_equal("70c379b63ffa0795fdbfbc128e5a2818397b7ef8", - self.git.hash_object(istream=fh, stdin=True)) - fh.close() - - def test_it_handles_large_input(self): - if sys.platform == 'win32': - output = self.git.execute(["type", "C:\WINDOWS\system32\cmd.exe"]) - else: - output = self.git.execute(["cat", "/bin/bash"]) - assert_true(len(output) > 4096) # at least 4k - - @patch_object(Git, 'execute') - def test_it_ignores_false_kwargs(self, git): - # this_should_not_be_ignored=False implies it *should* be ignored - output = self.git.version(pass_this_kwarg=False) - assert_true("pass_this_kwarg" not in git.call_args[1]) + def setup(self): + base = os.path.join(os.path.dirname(__file__), "../..") + self.git = Git(base) + + @patch_object(Git, 'execute') + def test_call_process_calls_execute(self, git): + git.return_value = '' + self.git.version() + assert_true(git.called) + assert_equal(git.call_args, ((['git', 'version'],), {})) + + @raises(GitCommandError) + def test_it_raises_errors(self): + self.git.this_does_not_exist() + + + def test_it_transforms_kwargs_into_git_command_arguments(self): + assert_equal(["-s"], self.git.transform_kwargs(**{'s': True})) + assert_equal(["-s5"], self.git.transform_kwargs(**{'s': 5})) + + assert_equal(["--max-count"], self.git.transform_kwargs(**{'max_count': True})) + assert_equal(["--max-count=5"], self.git.transform_kwargs(**{'max_count': 5})) + + assert_equal(["-s", "-t"], self.git.transform_kwargs(**{'s': True, 't': True})) + + def test_it_executes_git_to_shell_and_returns_result(self): + assert_match('^git version [\d\.]{2}.*$', self.git.execute(["git","version"])) + + def test_it_accepts_stdin(self): + filename = fixture_path("cat_file_blob") + fh = open(filename, 'r') + assert_equal("70c379b63ffa0795fdbfbc128e5a2818397b7ef8", + self.git.hash_object(istream=fh, stdin=True)) + fh.close() + + def test_it_handles_large_input(self): + if sys.platform == 'win32': + output = self.git.execute(["type", "C:\WINDOWS\system32\cmd.exe"]) + else: + output = self.git.execute(["cat", "/bin/bash"]) + assert_true(len(output) > 4096) # at least 4k + + @patch_object(Git, 'execute') + def test_it_ignores_false_kwargs(self, git): + # this_should_not_be_ignored=False implies it *should* be ignored + output = self.git.version(pass_this_kwarg=False) + assert_true("pass_this_kwarg" not in git.call_args[1]) diff --git a/test/git/test_head.py b/test/git/test_head.py index e3408974..8338552f 100644 --- a/test/git/test_head.py +++ b/test/git/test_head.py @@ -8,25 +8,25 @@ from test.testlib import * from git import * class TestHead(object): - def setup(self): - self.repo = Repo(GIT_REPO) + def setup(self): + self.repo = Repo(GIT_REPO) - @patch_object(Git, '_call_process') - def test_repr(self, git): - git.return_value = fixture('for_each_ref') - - head = self.repo.heads[0] - - assert_equal('' % head.name, repr(head)) - - assert_true(git.called) - assert_equal(git.call_args, (('for_each_ref', 'refs/heads'), {'sort': 'committerdate', 'format': '%(refname)%00%(objectname)'})) + @patch_object(Git, '_call_process') + def test_repr(self, git): + git.return_value = fixture('for_each_ref') + + head = self.repo.heads[0] + + assert_equal('' % head.name, repr(head)) + + assert_true(git.called) + assert_equal(git.call_args, (('for_each_ref', 'refs/heads'), {'sort': 'committerdate', 'format': '%(refname)%00%(objectname)'})) - @patch_object(Git, '_call_process') - def test_ref_with_path_component(self, git): - git.return_value = fixture('for_each_ref_with_path_component') - head = self.repo.heads[0] + @patch_object(Git, '_call_process') + def test_ref_with_path_component(self, git): + git.return_value = fixture('for_each_ref_with_path_component') + head = self.repo.heads[0] - assert_equal('refactoring/feature1', head.name) - assert_true(git.called) - assert_equal(git.call_args, (('for_each_ref', 'refs/heads'), {'sort': 'committerdate', 'format': '%(refname)%00%(objectname)'})) + assert_equal('refactoring/feature1', head.name) + assert_true(git.called) + assert_equal(git.call_args, (('for_each_ref', 'refs/heads'), {'sort': 'committerdate', 'format': '%(refname)%00%(objectname)'})) diff --git a/test/git/test_repo.py b/test/git/test_repo.py index a9d3beaf..e232b065 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -10,255 +10,255 @@ from test.testlib import * from git import * class TestRepo(object): - def setup(self): - self.repo = Repo(GIT_REPO) - - @raises(InvalidGitRepositoryError) - def test_new_should_raise_on_invalid_repo_location(self): - if sys.platform == "win32": - Repo("C:\\WINDOWS\\Temp") - else: - Repo("/tmp") + def setup(self): + self.repo = Repo(GIT_REPO) + + @raises(InvalidGitRepositoryError) + def test_new_should_raise_on_invalid_repo_location(self): + if sys.platform == "win32": + Repo("C:\\WINDOWS\\Temp") + else: + Repo("/tmp") - @raises(NoSuchPathError) - def test_new_should_raise_on_non_existant_path(self): - Repo("repos/foobar") + @raises(NoSuchPathError) + def test_new_should_raise_on_non_existant_path(self): + Repo("repos/foobar") - def test_description(self): - txt = "Test repository" - self.repo.description = txt - assert_equal(self.repo.description, txt) + def test_description(self): + txt = "Test repository" + self.repo.description = txt + assert_equal(self.repo.description, txt) - def test_heads_should_return_array_of_head_objects(self): - for head in self.repo.heads: - assert_equal(Head, head.__class__) + def test_heads_should_return_array_of_head_objects(self): + for head in self.repo.heads: + assert_equal(Head, head.__class__) - @patch_object(Git, '_call_process') - def test_heads_should_populate_head_data(self, git): - git.return_value = fixture('for_each_ref') + @patch_object(Git, '_call_process') + def test_heads_should_populate_head_data(self, git): + git.return_value = fixture('for_each_ref') - head = self.repo.heads[0] - assert_equal('master', head.name) - assert_equal('634396b2f541a9f2d58b00be1a07f0c358b999b3', head.commit.id) + head = self.repo.heads[0] + assert_equal('master', head.name) + assert_equal('634396b2f541a9f2d58b00be1a07f0c358b999b3', head.commit.id) - assert_true(git.called) - assert_equal(git.call_args, (('for_each_ref', 'refs/heads'), {'sort': 'committerdate', 'format': '%(refname)%00%(objectname)'})) + assert_true(git.called) + assert_equal(git.call_args, (('for_each_ref', 'refs/heads'), {'sort': 'committerdate', 'format': '%(refname)%00%(objectname)'})) - @patch_object(Git, '_call_process') - def test_commits(self, git): - git.return_value = fixture('rev_list') + @patch_object(Git, '_call_process') + def test_commits(self, git): + git.return_value = fixture('rev_list') - commits = self.repo.commits('master', max_count=10) + commits = self.repo.commits('master', max_count=10) - c = commits[0] - assert_equal('4c8124ffcf4039d292442eeccabdeca5af5c5017', c.id) - assert_equal(["634396b2f541a9f2d58b00be1a07f0c358b999b3"], [p.id for p in c.parents]) - assert_equal("672eca9b7f9e09c22dcb128c283e8c3c8d7697a4", c.tree.id) - assert_equal("Tom Preston-Werner", c.author.name) - assert_equal("tom@mojombo.com", c.author.email) - assert_equal(time.gmtime(1191999972), c.authored_date) - assert_equal("Tom Preston-Werner", c.committer.name) - assert_equal("tom@mojombo.com", c.committer.email) - assert_equal(time.gmtime(1191999972), c.committed_date) - assert_equal("implement Grit#heads", c.message) + c = commits[0] + assert_equal('4c8124ffcf4039d292442eeccabdeca5af5c5017', c.id) + assert_equal(["634396b2f541a9f2d58b00be1a07f0c358b999b3"], [p.id for p in c.parents]) + assert_equal("672eca9b7f9e09c22dcb128c283e8c3c8d7697a4", c.tree.id) + assert_equal("Tom Preston-Werner", c.author.name) + assert_equal("tom@mojombo.com", c.author.email) + assert_equal(time.gmtime(1191999972), c.authored_date) + assert_equal("Tom Preston-Werner", c.committer.name) + assert_equal("tom@mojombo.com", c.committer.email) + assert_equal(time.gmtime(1191999972), c.committed_date) + assert_equal("implement Grit#heads", c.message) - c = commits[1] - assert_equal([], c.parents) + c = commits[1] + assert_equal([], c.parents) - c = commits[2] - assert_equal(["6e64c55896aabb9a7d8e9f8f296f426d21a78c2c", "7f874954efb9ba35210445be456c74e037ba6af2"], map(lambda p: p.id, c.parents)) - assert_equal("Merge branch 'site'", c.summary) + c = commits[2] + assert_equal(["6e64c55896aabb9a7d8e9f8f296f426d21a78c2c", "7f874954efb9ba35210445be456c74e037ba6af2"], map(lambda p: p.id, c.parents)) + assert_equal("Merge branch 'site'", c.summary) - assert_true(git.called) - assert_equal(git.call_args, (('rev_list', 'master', '--', ''), {'skip': 0, 'pretty': 'raw', 'max_count': 10})) + assert_true(git.called) + assert_equal(git.call_args, (('rev_list', 'master', '--', ''), {'skip': 0, 'pretty': 'raw', 'max_count': 10})) - @patch_object(Git, '_call_process') - def test_commit_count(self, git): - git.return_value = fixture('rev_list_count') + @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_equal(655, self.repo.commit_count('master')) - assert_true(git.called) - assert_equal(git.call_args, (('rev_list', '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 = fixture('rev_list_single') + @patch_object(Git, '_call_process') + def test_commit(self, git): + git.return_value = fixture('rev_list_single') - commit = self.repo.commit('4c8124ffcf4039d292442eeccabdeca5af5c5017') + commit = self.repo.commit('4c8124ffcf4039d292442eeccabdeca5af5c5017') - assert_equal("4c8124ffcf4039d292442eeccabdeca5af5c5017", commit.id) + assert_equal("4c8124ffcf4039d292442eeccabdeca5af5c5017", commit.id) - assert_true(git.called) - assert_equal(git.call_args, (('rev_list', '4c8124ffcf4039d292442eeccabdeca5af5c5017', '--', ''), {'pretty': 'raw', 'max_count': 1})) + assert_true(git.called) + assert_equal(git.call_args, (('rev_list', '4c8124ffcf4039d292442eeccabdeca5af5c5017', '--', ''), {'pretty': 'raw', 'max_count': 1})) - @patch_object(Git, '_call_process') - def test_tree(self, git): - git.return_value = fixture('ls_tree_a') + @patch_object(Git, '_call_process') + def test_tree(self, git): + git.return_value = fixture('ls_tree_a') - tree = self.repo.tree('master') + tree = self.repo.tree('master') - assert_equal(4, len([c for c in tree.values() if isinstance(c, Blob)])) - assert_equal(3, len([c for c in tree.values() if isinstance(c, Tree)])) + assert_equal(4, len([c for c in tree.values() if isinstance(c, Blob)])) + assert_equal(3, len([c for c in tree.values() if isinstance(c, Tree)])) - assert_true(git.called) - assert_equal(git.call_args, (('ls_tree', 'master'), {})) + assert_true(git.called) + assert_equal(git.call_args, (('ls_tree', 'master'), {})) - @patch_object(Git, '_call_process') - def test_blob(self, git): - git.return_value = fixture('cat_file_blob') + @patch_object(Git, '_call_process') + def test_blob(self, git): + git.return_value = fixture('cat_file_blob') - blob = self.repo.blob("abc") - assert_equal("Hello world", blob.data) + blob = self.repo.blob("abc") + assert_equal("Hello world", blob.data) - assert_true(git.called) - assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True, 'with_raw_output': True})) + assert_true(git.called) + assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True, 'with_raw_output': True})) - @patch_object(Repo, '__init__') - @patch_object(Git, '_call_process') - def test_init_bare(self, git, repo): - git.return_value = True - repo.return_value = None + @patch_object(Repo, '__init__') + @patch_object(Git, '_call_process') + def test_init_bare(self, git, repo): + git.return_value = True + repo.return_value = None - Repo.init_bare("repos/foo/bar.git") + Repo.init_bare("repos/foo/bar.git") - assert_true(git.called) - assert_equal(git.call_args, (('init', '--bare'), {})) - assert_true(repo.called) - assert_equal(repo.call_args, (('repos/foo/bar.git',), {})) + 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): - git.return_value = True - repo.return_value = None + @patch_object(Repo, '__init__') + @patch_object(Git, '_call_process') + def test_init_bare_with_options(self, git, repo): + git.return_value = True + repo.return_value = None - Repo.init_bare("repos/foo/bar.git", **{'template': "/baz/sweet"}) + Repo.init_bare("repos/foo/bar.git", **{'template': "/baz/sweet"}) - 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',), {})) + 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): - git.return_value = None - repo.return_value = None + @patch_object(Repo, '__init__') + @patch_object(Git, '_call_process') + def test_fork_bare(self, git, repo): + git.return_value = None + repo.return_value = None - self.repo.fork_bare("repos/foo/bar.git") + self.repo.fork_bare("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_true(repo.called) + 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_true(repo.called) - @patch_object(Repo, '__init__') - @patch_object(Git, '_call_process') - def test_fork_bare_with_options(self, git, repo): - git.return_value = None - repo.return_value = None + @patch_object(Repo, '__init__') + @patch_object(Git, '_call_process') + def test_fork_bare_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.fork_bare("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'})) - assert_true(repo.called) + 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'})) + assert_true(repo.called) - @patch_object(Git, '_call_process') - def test_diff(self, git): - self.repo.diff('master^', 'master') + @patch_object(Git, '_call_process') + def test_diff(self, git): + self.repo.diff('master^', 'master') - assert_true(git.called) - assert_equal(git.call_args, (('diff', 'master^', 'master', '--'), {})) + assert_true(git.called) + assert_equal(git.call_args, (('diff', 'master^', 'master', '--'), {})) - self.repo.diff('master^', 'master', 'foo/bar') + self.repo.diff('master^', 'master', 'foo/bar') - assert_true(git.called) - assert_equal(git.call_args, (('diff', 'master^', 'master', '--', 'foo/bar'), {})) + assert_true(git.called) + assert_equal(git.call_args, (('diff', 'master^', 'master', '--', 'foo/bar'), {})) - self.repo.diff('master^', 'master', 'foo/bar', 'foo/baz') + self.repo.diff('master^', 'master', 'foo/bar', 'foo/baz') - assert_true(git.called) - assert_equal(git.call_args, (('diff', 'master^', 'master', '--', 'foo/bar', 'foo/baz'), {})) + assert_true(git.called) + assert_equal(git.call_args, (('diff', 'master^', 'master', '--', 'foo/bar', 'foo/baz'), {})) - @patch_object(Git, '_call_process') - def test_diff_with_parents(self, git): - git.return_value = fixture('diff_p') + @patch_object(Git, '_call_process') + def test_diff_with_parents(self, git): + git.return_value = fixture('diff_p') - diffs = self.repo.commit_diff('master') - assert_equal(15, len(diffs)) - assert_true(git.called) + diffs = self.repo.commit_diff('master') + assert_equal(15, len(diffs)) + assert_true(git.called) - def test_archive_tar(self): - assert self.repo.archive_tar() + 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_tar_gz(self): + assert self.repo.archive_tar_gz() - @patch('git.utils.touch') - def test_enable_daemon_serve(self, touch): - self.repo.daemon_serve = False - assert_false(self.repo.daemon_serve) + @patch('git.utils.touch') + def test_enable_daemon_serve(self, touch): + self.repo.daemon_serve = False + assert_false(self.repo.daemon_serve) - def test_disable_daemon_serve(self): - self.repo.daemon_serve = True - assert_true(self.repo.daemon_serve) + def test_disable_daemon_serve(self): + self.repo.daemon_serve = True + assert_true(self.repo.daemon_serve) - @patch_object(os.path, 'exists') - def test_alternates_no_file(self, os): - os.return_value = False - assert_equal([], self.repo.alternates) - - assert_true(os.called) - - @patch_object(os, 'remove') - def test_alternates_setter_empty(self, os): - self.repo.alternates = [] - assert_true(os.called) - - def test_repr(self): - path = os.path.join(os.path.abspath(GIT_REPO), '.git') - assert_equal('' % path, repr(self.repo)) - - @patch_object(Git, '_call_process') - def test_log(self, git): - git.return_value = fixture('rev_list') - assert_equal('4c8124ffcf4039d292442eeccabdeca5af5c5017', self.repo.log()[0].id) - assert_equal('ab25fd8483882c3bda8a458ad2965d2248654335', self.repo.log()[-1].id) - assert_true(git.called) - assert_equal(git.call_count, 2) - assert_equal(git.call_args, (('log', 'master', '--'), {'pretty': 'raw'})) - - @patch_object(Git, '_call_process') - def test_log_with_path_and_options(self, git): - git.return_value = fixture('rev_list') - self.repo.log('master', 'file.rb', **{'max_count': 1}) - assert_true(git.called) - assert_equal(git.call_args, (('log', 'master', '--', 'file.rb'), {'pretty': 'raw', 'max_count': 1})) - - def test_is_dirty_with_bare_repository(self): - self.repo.bare = True - assert_false(self.repo.is_dirty) - - @patch_object(Git, '_call_process') - def test_is_dirty_with_clean_working_dir(self, git): - self.repo.bare = False - git.return_value = '' - assert_false(self.repo.is_dirty) - assert_equal(git.call_args, (('diff', 'HEAD', '--'), {})) - - @patch_object(Git, '_call_process') - def test_is_dirty_with_dirty_working_dir(self, git): - self.repo.bare = False - git.return_value = '''-aaa\n+bbb''' - assert_true(self.repo.is_dirty) - assert_equal(git.call_args, (('diff', 'HEAD', '--'), {})) - - @patch_object(Git, '_call_process') - def test_active_branch(self, git): - git.return_value = 'refs/heads/major-refactoring' - assert_equal(self.repo.active_branch, 'major-refactoring') - assert_equal(git.call_args, (('symbolic_ref', 'HEAD'), {})) + @patch_object(os.path, 'exists') + def test_alternates_no_file(self, os): + os.return_value = False + assert_equal([], self.repo.alternates) + + assert_true(os.called) + + @patch_object(os, 'remove') + def test_alternates_setter_empty(self, os): + self.repo.alternates = [] + assert_true(os.called) + + def test_repr(self): + path = os.path.join(os.path.abspath(GIT_REPO), '.git') + assert_equal('' % path, repr(self.repo)) + + @patch_object(Git, '_call_process') + def test_log(self, git): + git.return_value = fixture('rev_list') + assert_equal('4c8124ffcf4039d292442eeccabdeca5af5c5017', self.repo.log()[0].id) + assert_equal('ab25fd8483882c3bda8a458ad2965d2248654335', self.repo.log()[-1].id) + assert_true(git.called) + assert_equal(git.call_count, 2) + assert_equal(git.call_args, (('log', 'master', '--'), {'pretty': 'raw'})) + + @patch_object(Git, '_call_process') + def test_log_with_path_and_options(self, git): + git.return_value = fixture('rev_list') + self.repo.log('master', 'file.rb', **{'max_count': 1}) + assert_true(git.called) + assert_equal(git.call_args, (('log', 'master', '--', 'file.rb'), {'pretty': 'raw', 'max_count': 1})) + + def test_is_dirty_with_bare_repository(self): + self.repo.bare = True + assert_false(self.repo.is_dirty) + + @patch_object(Git, '_call_process') + def test_is_dirty_with_clean_working_dir(self, git): + self.repo.bare = False + git.return_value = '' + assert_false(self.repo.is_dirty) + assert_equal(git.call_args, (('diff', 'HEAD', '--'), {})) + + @patch_object(Git, '_call_process') + def test_is_dirty_with_dirty_working_dir(self, git): + self.repo.bare = False + git.return_value = '''-aaa\n+bbb''' + assert_true(self.repo.is_dirty) + assert_equal(git.call_args, (('diff', 'HEAD', '--'), {})) + + @patch_object(Git, '_call_process') + def test_active_branch(self, git): + git.return_value = 'refs/heads/major-refactoring' + assert_equal(self.repo.active_branch, 'major-refactoring') + assert_equal(git.call_args, (('symbolic_ref', 'HEAD'), {})) diff --git a/test/git/test_stats.py b/test/git/test_stats.py index b6f1b60e..0063bb2d 100644 --- a/test/git/test_stats.py +++ b/test/git/test_stats.py @@ -8,20 +8,20 @@ from test.testlib import * from git import * class TestStats(object): - def setup(self): - self.repo = Repo(GIT_REPO) - - def test_list_from_string(self): - output = fixture('diff_numstat') - stats = Stats.list_from_string(self.repo, output) - - assert_equal(2, stats.total['files']) - assert_equal(52, stats.total['lines']) - assert_equal(29, stats.total['insertions']) - assert_equal(23, stats.total['deletions']) - - assert_equal(29, stats.files["a.txt"]['insertions']) - assert_equal(18, stats.files["a.txt"]['deletions']) - - assert_equal(0, stats.files["b.txt"]['insertions']) - assert_equal(5, stats.files["b.txt"]['deletions']) + def setup(self): + self.repo = Repo(GIT_REPO) + + def test_list_from_string(self): + output = fixture('diff_numstat') + stats = Stats.list_from_string(self.repo, output) + + assert_equal(2, stats.total['files']) + assert_equal(52, stats.total['lines']) + assert_equal(29, stats.total['insertions']) + assert_equal(23, stats.total['deletions']) + + assert_equal(29, stats.files["a.txt"]['insertions']) + assert_equal(18, stats.files["a.txt"]['deletions']) + + assert_equal(0, stats.files["b.txt"]['insertions']) + assert_equal(5, stats.files["b.txt"]['deletions']) diff --git a/test/git/test_tree.py b/test/git/test_tree.py index 3946a33c..d52a8e0a 100644 --- a/test/git/test_tree.py +++ b/test/git/test_tree.py @@ -8,142 +8,142 @@ from test.testlib import * from git import * class TestTree(object): - def setup(self): - self.repo = Repo(GIT_REPO) - - @patch_object(Git, '_call_process') - def test_contents_should_cache(self, git): - git.return_value = fixture('ls_tree_a') + fixture('ls_tree_b') - - tree = self.repo.tree('master') - - child = tree['grit'] - child.items() - child.items() - - assert_true(git.called) - assert_equal(2, git.call_count) - assert_equal(git.call_args, (('ls_tree', '34868e6e7384cb5ee51c543a8187fdff2675b5a7'), {})) + def setup(self): + self.repo = Repo(GIT_REPO) + + @patch_object(Git, '_call_process') + def test_contents_should_cache(self, git): + git.return_value = fixture('ls_tree_a') + fixture('ls_tree_b') + + tree = self.repo.tree('master') + + child = tree['grit'] + child.items() + child.items() + + assert_true(git.called) + assert_equal(2, git.call_count) + assert_equal(git.call_args, (('ls_tree', '34868e6e7384cb5ee51c543a8187fdff2675b5a7'), {})) - def test_content_from_string_tree_should_return_tree(self): - text = fixture('ls_tree_a').splitlines()[-1] - tree = Tree.content_from_string(None, text) - - assert_equal(Tree, tree.__class__) - assert_equal("650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44", tree.id) - assert_equal("040000", tree.mode) - assert_equal("test", tree.path) + def test_content_from_string_tree_should_return_tree(self): + text = fixture('ls_tree_a').splitlines()[-1] + tree = Tree.content_from_string(None, text) + + assert_equal(Tree, tree.__class__) + assert_equal("650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44", tree.id) + assert_equal("040000", tree.mode) + assert_equal("test", tree.path) - def test_content_from_string_tree_should_return_blob(self): - text = fixture('ls_tree_b').split("\n")[0] - - tree = Tree.content_from_string(None, text) - - assert_equal(Blob, tree.__class__) - assert_equal("aa94e396335d2957ca92606f909e53e7beaf3fbb", tree.id) - assert_equal("100644", tree.mode) - assert_equal("grit.rb", tree.path) + def test_content_from_string_tree_should_return_blob(self): + text = fixture('ls_tree_b').split("\n")[0] + + tree = Tree.content_from_string(None, text) + + assert_equal(Blob, tree.__class__) + assert_equal("aa94e396335d2957ca92606f909e53e7beaf3fbb", tree.id) + assert_equal("100644", tree.mode) + assert_equal("grit.rb", tree.path) - def test_content_from_string_tree_should_return_commit(self): - text = fixture('ls_tree_commit').split("\n")[1] - - tree = Tree.content_from_string(None, text) - assert_none(tree) - - @raises(TypeError) - def test_content_from_string_invalid_type_should_raise(self): - Tree.content_from_string(None, "040000 bogus 650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44 test") - - @patch_object(Blob, 'size') - @patch_object(Git, '_call_process') - def test_slash(self, git, blob): - git.return_value = fixture('ls_tree_a') - blob.return_value = 1 - - tree = self.repo.tree('master') - - assert_equal('aa06ba24b4e3f463b3c4a85469d0fb9e5b421cf8', (tree/'lib').id) - assert_equal('8b1e02c0fb554eed2ce2ef737a68bb369d7527df', (tree/'README.txt').id) - - assert_true(git.called) - assert_equal(git.call_args, (('ls_tree', 'master'), {})) + def test_content_from_string_tree_should_return_commit(self): + text = fixture('ls_tree_commit').split("\n")[1] + + tree = Tree.content_from_string(None, text) + assert_none(tree) + + @raises(TypeError) + def test_content_from_string_invalid_type_should_raise(self): + Tree.content_from_string(None, "040000 bogus 650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44 test") + + @patch_object(Blob, 'size') + @patch_object(Git, '_call_process') + def test_slash(self, git, blob): + git.return_value = fixture('ls_tree_a') + blob.return_value = 1 + + tree = self.repo.tree('master') + + assert_equal('aa06ba24b4e3f463b3c4a85469d0fb9e5b421cf8', (tree/'lib').id) + assert_equal('8b1e02c0fb554eed2ce2ef737a68bb369d7527df', (tree/'README.txt').id) + + assert_true(git.called) + assert_equal(git.call_args, (('ls_tree', 'master'), {})) - @patch_object(Blob, 'size') - @patch_object(Git, '_call_process') - def test_slash_with_zero_length_file(self, git, blob): - git.return_value = fixture('ls_tree_a') - blob.return_value = 0 - - tree = self.repo.tree('master') - - assert_not_none(tree/'README.txt') - assert_equal('8b1e02c0fb554eed2ce2ef737a68bb369d7527df', (tree/'README.txt').id) - - assert_true(git.called) - assert_equal(git.call_args, (('ls_tree', 'master'), {})) + @patch_object(Blob, 'size') + @patch_object(Git, '_call_process') + def test_slash_with_zero_length_file(self, git, blob): + git.return_value = fixture('ls_tree_a') + blob.return_value = 0 + + tree = self.repo.tree('master') + + assert_not_none(tree/'README.txt') + assert_equal('8b1e02c0fb554eed2ce2ef737a68bb369d7527df', (tree/'README.txt').id) + + assert_true(git.called) + assert_equal(git.call_args, (('ls_tree', 'master'), {})) - @patch_object(Git, '_call_process') - def test_slash_with_commits(self, git): - git.return_value = fixture('ls_tree_commit') + @patch_object(Git, '_call_process') + def test_slash_with_commits(self, git): + git.return_value = fixture('ls_tree_commit') - tree = self.repo.tree('master') - - assert_none(tree/'bar') - assert_equal('2afb47bcedf21663580d5e6d2f406f08f3f65f19', (tree/'foo').id) - assert_equal('f623ee576a09ca491c4a27e48c0dfe04be5f4a2e', (tree/'baz').id) + tree = self.repo.tree('master') + + assert_none(tree/'bar') + assert_equal('2afb47bcedf21663580d5e6d2f406f08f3f65f19', (tree/'foo').id) + assert_equal('f623ee576a09ca491c4a27e48c0dfe04be5f4a2e', (tree/'baz').id) - assert_true(git.called) - assert_equal(git.call_args, (('ls_tree', 'master'), {})) + assert_true(git.called) + assert_equal(git.call_args, (('ls_tree', 'master'), {})) - @patch_object(Blob, 'size') - @patch_object(Git, '_call_process') - def test_dict(self, git, blob): - git.return_value = fixture('ls_tree_a') - blob.return_value = 1 + @patch_object(Blob, 'size') + @patch_object(Git, '_call_process') + def test_dict(self, git, blob): + git.return_value = fixture('ls_tree_a') + blob.return_value = 1 - tree = self.repo.tree('master') + tree = self.repo.tree('master') - assert_equal('aa06ba24b4e3f463b3c4a85469d0fb9e5b421cf8', tree['lib'].id) - assert_equal('8b1e02c0fb554eed2ce2ef737a68bb369d7527df', tree['README.txt'].id) + assert_equal('aa06ba24b4e3f463b3c4a85469d0fb9e5b421cf8', tree['lib'].id) + assert_equal('8b1e02c0fb554eed2ce2ef737a68bb369d7527df', tree['README.txt'].id) - assert_true(git.called) - assert_equal(git.call_args, (('ls_tree', 'master'), {})) + assert_true(git.called) + assert_equal(git.call_args, (('ls_tree', 'master'), {})) - @patch_object(Blob, 'size') - @patch_object(Git, '_call_process') - def test_dict_with_zero_length_file(self, git, blob): - git.return_value = fixture('ls_tree_a') - blob.return_value = 0 + @patch_object(Blob, 'size') + @patch_object(Git, '_call_process') + def test_dict_with_zero_length_file(self, git, blob): + git.return_value = fixture('ls_tree_a') + blob.return_value = 0 - tree = self.repo.tree('master') + tree = self.repo.tree('master') - assert_not_none(tree['README.txt']) - assert_equal('8b1e02c0fb554eed2ce2ef737a68bb369d7527df', tree['README.txt'].id) + assert_not_none(tree['README.txt']) + assert_equal('8b1e02c0fb554eed2ce2ef737a68bb369d7527df', tree['README.txt'].id) - assert_true(git.called) - assert_equal(git.call_args, (('ls_tree', 'master'), {})) + assert_true(git.called) + assert_equal(git.call_args, (('ls_tree', 'master'), {})) - @patch_object(Git, '_call_process') - def test_dict_with_commits(self, git): - git.return_value = fixture('ls_tree_commit') + @patch_object(Git, '_call_process') + def test_dict_with_commits(self, git): + git.return_value = fixture('ls_tree_commit') - tree = self.repo.tree('master') + tree = self.repo.tree('master') - assert_none(tree.get('bar')) - assert_equal('2afb47bcedf21663580d5e6d2f406f08f3f65f19', tree['foo'].id) - assert_equal('f623ee576a09ca491c4a27e48c0dfe04be5f4a2e', tree['baz'].id) + assert_none(tree.get('bar')) + assert_equal('2afb47bcedf21663580d5e6d2f406f08f3f65f19', tree['foo'].id) + assert_equal('f623ee576a09ca491c4a27e48c0dfe04be5f4a2e', tree['baz'].id) - assert_true(git.called) - assert_equal(git.call_args, (('ls_tree', 'master'), {})) + assert_true(git.called) + assert_equal(git.call_args, (('ls_tree', 'master'), {})) - @patch_object(Git, '_call_process') - @raises(KeyError) - def test_dict_with_non_existant_file(self, git): - git.return_value = fixture('ls_tree_commit') + @patch_object(Git, '_call_process') + @raises(KeyError) + def test_dict_with_non_existant_file(self, git): + git.return_value = fixture('ls_tree_commit') - tree = self.repo.tree('master') - tree['bar'] + tree = self.repo.tree('master') + tree['bar'] - def test_repr(self): - tree = Tree(self.repo, id='abc') - assert_equal('', repr(tree)) + def test_repr(self): + tree = Tree(self.repo, id='abc') + assert_equal('', repr(tree)) diff --git a/test/git/test_utils.py b/test/git/test_utils.py index 327a07ed..2983a14a 100644 --- a/test/git/test_utils.py +++ b/test/git/test_utils.py @@ -9,13 +9,13 @@ from test.testlib import * from git import * class TestUtils(object): - def setup(self): - self.testdict = { - "string": "42", - "int": 42, - "array": [ 42 ], - } + def setup(self): + self.testdict = { + "string": "42", + "int": 42, + "array": [ 42 ], + } - def test_it_should_dashify(self): - assert_equal('this-is-my-argument', dashify('this_is_my_argument')) - assert_equal('foo', dashify('foo')) + def test_it_should_dashify(self): + assert_equal('this-is-my-argument', dashify('this_is_my_argument')) + assert_equal('foo', dashify('foo')) -- cgit v1.2.3 From 101fb1df36f29469ee8f4e0b9e7846d856b87daa Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Oct 2009 17:15:07 +0200 Subject: blob tests fixed to deal with changes to the Blob type --- test/git/test_blob.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'test/git') diff --git a/test/git/test_blob.py b/test/git/test_blob.py index e2ac22e1..94d3a33b 100644 --- a/test/git/test_blob.py +++ b/test/git/test_blob.py @@ -31,12 +31,13 @@ class TestBlob(object): @patch_object(Git, '_call_process') def test_should_cache_data(self, git): git.return_value = fixture('cat_file_blob') - blob = Blob(self.repo, **{'id': 'abc'}) + bid = '787b92b63f629398f3d2ceb20f7f0c2578259e84' + blob = Blob(self.repo, bid) blob.data blob.data assert_true(git.called) assert_equal(git.call_count, 1) - assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True, 'with_raw_output': True})) + assert_equal(git.call_args, (('cat_file', bid), {'p': True, 'with_raw_output': True})) @patch_object(Git, '_call_process') def test_should_return_file_size(self, git): @@ -61,7 +62,7 @@ class TestBlob(object): assert_equal("image/png", blob.mime_type) def test_mime_type_should_return_text_plain_for_unknown_types(self): - blob = Blob(self.repo, **{'id': 'abc'}) + blob = Blob(self.repo, **{'id': 'abc','path': 'something'}) assert_equal("text/plain", blob.mime_type) @patch_object(Git, '_call_process') -- cgit v1.2.3 From 15b9129ec639112e94ea96b6a395ad9b149515d1 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Oct 2009 19:07:03 +0200 Subject: lazymixin system now supports per-attribute baking, it is up to the class whether it bakes more. This also leads to more efficient use of memory as values are only cached and set when required - the baking system does not require an own tracking variable anymore, and values are only to be cached once - then python will natively find the cache without involving any additional overhead. This works by using __getattr__ instead of __get_attribute__ which would always be called --- test/git/test_commit.py | 3 --- test/git/test_tree.py | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) (limited to 'test/git') diff --git a/test/git/test_commit.py b/test/git/test_commit.py index e92c13dd..341d72e2 100644 --- a/test/git/test_commit.py +++ b/test/git/test_commit.py @@ -140,7 +140,6 @@ class TestCommit(object): git.return_value = fixture('diff_i') commit = Commit(self.repo, id='634396b2f541a9f2d58b00be1a07f0c358b999b3') - commit.__bake_it__() diffs = commit.diffs assert_equal(10, len(diffs)) @@ -178,7 +177,6 @@ class TestCommit(object): git.return_value = fixture('diff_mode_only') commit = Commit(self.repo, id='91169e1f5fa4de2eaea3f176461f5dc784796769') - commit.__bake_it__() diffs = commit.diffs # in case of mode-only changes, there is no blob @@ -196,7 +194,6 @@ class TestCommit(object): git.return_value = fixture('diff_tree_numstat_root') commit = Commit(self.repo, id='634396b2f541a9f2d58b00be1a07f0c358b999b3') - commit.__bake_it__() stats = commit.stats keys = stats.files.keys() diff --git a/test/git/test_tree.py b/test/git/test_tree.py index d52a8e0a..205fbf1a 100644 --- a/test/git/test_tree.py +++ b/test/git/test_tree.py @@ -43,7 +43,7 @@ class TestTree(object): assert_equal("aa94e396335d2957ca92606f909e53e7beaf3fbb", tree.id) assert_equal("100644", tree.mode) assert_equal("grit.rb", tree.path) - + def test_content_from_string_tree_should_return_commit(self): text = fixture('ls_tree_commit').split("\n")[1] -- cgit v1.2.3 From 9a119924bd314934158515a1a5f5877be63f6f91 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Oct 2009 20:21:22 +0200 Subject: fixed issue in Ref.name implementation which would not handle components properly --- test/git/test_head.py | 16 +++++----------- test/git/test_tag.py | 2 +- 2 files changed, 6 insertions(+), 12 deletions(-) (limited to 'test/git') diff --git a/test/git/test_head.py b/test/git/test_head.py index 8338552f..b8380838 100644 --- a/test/git/test_head.py +++ b/test/git/test_head.py @@ -11,16 +11,11 @@ class TestHead(object): def setup(self): self.repo = Repo(GIT_REPO) - @patch_object(Git, '_call_process') - def test_repr(self, git): - git.return_value = fixture('for_each_ref') - - head = self.repo.heads[0] - - assert_equal('' % head.name, repr(head)) - - assert_true(git.called) - assert_equal(git.call_args, (('for_each_ref', 'refs/heads'), {'sort': 'committerdate', 'format': '%(refname)%00%(objectname)'})) + def test_base(self): + for head in self.repo.heads: + assert head.name + assert "refs/heads" in head.path + # END for each head @patch_object(Git, '_call_process') def test_ref_with_path_component(self, git): @@ -29,4 +24,3 @@ class TestHead(object): assert_equal('refactoring/feature1', head.name) assert_true(git.called) - assert_equal(git.call_args, (('for_each_ref', 'refs/heads'), {'sort': 'committerdate', 'format': '%(refname)%00%(objectname)'})) diff --git a/test/git/test_tag.py b/test/git/test_tag.py index 52f7898c..fe3f78cc 100644 --- a/test/git/test_tag.py +++ b/test/git/test_tag.py @@ -18,7 +18,7 @@ class TestTag(object): tag_object_refs = list() for tag in self.repo.tags: assert "refs/tags" in tag.path - assert "/" not in tag.name + assert tag.name assert isinstance( tag.commit, Commit ) if tag.tag is not None: tag_object_refs.append( tag ) -- cgit v1.2.3 From 708b8dda8e7b87841a5f39c60b799c514e75a9c7 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Oct 2009 21:17:59 +0200 Subject: commit: fixed failing commit tests as the mocked git command would always return the same thing which does not work anymore - re-implemented it in a more dynamic manner, but in the end tests will have to be revised anyway Added slots to Diff and Stats type respectively --- test/git/test_commit.py | 82 ++++++++++++++++++++++--------------------------- test/git/test_repo.py | 15 +++------ 2 files changed, 41 insertions(+), 56 deletions(-) (limited to 'test/git') diff --git a/test/git/test_commit.py b/test/git/test_commit.py index 341d72e2..79768c3f 100644 --- a/test/git/test_commit.py +++ b/test/git/test_commit.py @@ -135,30 +135,21 @@ class TestCommit(object): '91169e1f5fa4de2eaea3f176461f5dc784796769', ), {'full_index': True})) - @patch_object(Git, '_call_process') - def test_diffs_on_initial_import(self, git): - git.return_value = fixture('diff_i') - - commit = Commit(self.repo, id='634396b2f541a9f2d58b00be1a07f0c358b999b3') - diffs = commit.diffs - - assert_equal(10, len(diffs)) - - assert_equal('History.txt', diffs[0].b_blob.path) - assert_equal(None, diffs[0].a_blob) - assert_equal('100644', diffs[0].b_blob.mode) - assert_equal('81d2c27608b352814cbe979a6acd678d30219678', diffs[0].b_blob.id) - assert_equal(True, diffs[0].new_file) - assert_equal(False, diffs[0].deleted_file) - assert_equal("--- /dev/null\n+++ b/History.txt\n@@ -0,0 +1,5 @@\n+== 1.0.0 / 2007-10-09\n+\n+* 1 major enhancement\n+ * Birthday!\n+", diffs[0].diff) - - assert_equal('lib/grit.rb', diffs[5].b_blob.path) - assert_equal(None, diffs[5].a_blob) - assert_equal('32cec87d1e78946a827ddf6a8776be4d81dcf1d1', diffs[5].b_blob.id) - assert_equal(True, diffs[5].new_file) - - assert_true(git.called) - assert_equal(git.call_args, (('show', '634396b2f541a9f2d58b00be1a07f0c358b999b3', '-M'), {'full_index': True, 'pretty': 'raw'})) + def test_diffs_on_initial_import(self): + commit = Commit(self.repo, '33ebe7acec14b25c5f84f35a664803fcab2f7781') + + for diff in commit.diffs: + assert isinstance(diff, Diff) + assert isinstance(diff.a_blob, Blob) or isinstance(diff.b_blob, Blob) + assert isinstance(diff.a_mode, int) and isinstance(diff.b_mode, int) + assert diff.diff + if diff.renamed: + assert diff.rename_from and diff.rename_to and diff.rename_from != diff.rename_to + if diff.a_blob is None: + assert diff.new_file and isinstance(diff.new_file, bool) + if diff.b_blob is None: + assert diff.deleted_file and isinstance(diff.deleted_file, bool) + # END for each diff in initial import commit @patch_object(Git, '_call_process') def test_diffs_on_initial_import_with_empty_commit(self, git): @@ -172,37 +163,36 @@ class TestCommit(object): assert_true(git.called) assert_equal(git.call_args, (('show', '634396b2f541a9f2d58b00be1a07f0c358b999b3', '-M'), {'full_index': True, 'pretty': 'raw'})) - @patch_object(Git, '_call_process') - def test_diffs_with_mode_only_change(self, git): - git.return_value = fixture('diff_mode_only') - - commit = Commit(self.repo, id='91169e1f5fa4de2eaea3f176461f5dc784796769') + def test_diffs_with_mode_only_change(self): + commit = Commit(self.repo, id='ccde80b7a3037a004a7807a6b79916ce2a1e9729') diffs = commit.diffs # in case of mode-only changes, there is no blob - assert_equal(23, len(diffs)) + assert_equal(1, len(diffs)) assert_equal(None, diffs[0].a_blob) assert_equal(None, diffs[0].b_blob) assert_equal('100644', diffs[0].a_mode) assert_equal('100755', diffs[0].b_mode) - assert_true(git.called) - assert_equal(git.call_args, (('show', '91169e1f5fa4de2eaea3f176461f5dc784796769', '-M'), {'full_index': True, 'pretty': 'raw'})) - - @patch_object(Git, '_call_process') - def test_stats(self, git): - git.return_value = fixture('diff_tree_numstat_root') - - commit = Commit(self.repo, id='634396b2f541a9f2d58b00be1a07f0c358b999b3') + def test_stats(self): + commit = Commit(self.repo, id='33ebe7acec14b25c5f84f35a664803fcab2f7781') stats = commit.stats - - keys = stats.files.keys() - keys.sort() - assert_equal(["a.txt", "b.txt"], keys) - - assert_true(git.called) - assert_equal(git.call_args, (('diff_tree', '634396b2f541a9f2d58b00be1a07f0c358b999b3', '--'), {'numstat': True, 'root': True })) - + + def check_entries(d): + assert isinstance(d, dict) + for key in ("insertions", "deletions", "lines"): + assert key in d + # END assertion helper + assert stats.files + assert stats.total + + check_entries(stats.total) + assert "files" in stats.total + + for filepath, d in stats.files.items(): + check_entries(d) + # END for each stated file + @patch_object(Git, '_call_process') def test_rev_list_bisect_all(self, git): """ diff --git a/test/git/test_repo.py b/test/git/test_repo.py index e232b065..d4316981 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -33,16 +33,11 @@ class TestRepo(object): for head in self.repo.heads: assert_equal(Head, head.__class__) - @patch_object(Git, '_call_process') - def test_heads_should_populate_head_data(self, git): - git.return_value = fixture('for_each_ref') - - head = self.repo.heads[0] - assert_equal('master', head.name) - assert_equal('634396b2f541a9f2d58b00be1a07f0c358b999b3', head.commit.id) - - assert_true(git.called) - assert_equal(git.call_args, (('for_each_ref', 'refs/heads'), {'sort': 'committerdate', 'format': '%(refname)%00%(objectname)'})) + def test_heads_should_populate_head_data(self): + for head in self.repo.heads: + assert head.name + assert isinstance(head.commit,Commit) + # END for each head @patch_object(Git, '_call_process') def test_commits(self, git): -- cgit v1.2.3 From b01824b1aecf8aadae4501e22feb45c20fb26bce Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Oct 2009 22:22:28 +0200 Subject: Fixed remaining tests to deal with the changes mode is now generally an int compatible to the stat module --- test/git/test_commit.py | 74 ++++++++++++++++++++++++++++--------------------- test/git/test_repo.py | 2 +- test/git/test_tree.py | 4 +-- 3 files changed, 46 insertions(+), 34 deletions(-) (limited to 'test/git') diff --git a/test/git/test_commit.py b/test/git/test_commit.py index 79768c3f..ab1801ee 100644 --- a/test/git/test_commit.py +++ b/test/git/test_commit.py @@ -36,21 +36,25 @@ class TestCommit(object): diffs = Commit.diff(self.repo, 'master') assert_equal(15, len(diffs)) + + diff = diffs[0] + assert_equal('.gitignore', diff.a_blob.path) + assert_equal('.gitignore', diff.b_blob.path) + assert_equal('4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diff.a_blob.id) + assert_equal('2dd02534615434d88c51307beb0f0092f21fd103', diff.b_blob.id) + + assert_mode_644(diff.b_blob.mode) + + assert_equal(False, diff.new_file) + assert_equal(False, diff.deleted_file) + assert_equal("--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg", diff.diff) - assert_equal('.gitignore', diffs[0].a_blob.path) - assert_equal('.gitignore', diffs[0].b_blob.path) - assert_equal('4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diffs[0].a_blob.id) - assert_equal('2dd02534615434d88c51307beb0f0092f21fd103', diffs[0].b_blob.id) - assert_equal('100644', diffs[0].b_blob.mode) - assert_equal(False, diffs[0].new_file) - assert_equal(False, diffs[0].deleted_file) - assert_equal("--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg", diffs[0].diff) - - assert_equal('lib/grit/actor.rb', diffs[5].b_blob.path) - assert_equal(None, diffs[5].a_blob) - assert_equal('f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_blob.id) - assert_equal( None, diffs[5].a_mode ) - assert_equal(True, diffs[5].new_file) + diff = diffs[5] + assert_equal('lib/grit/actor.rb', diff.b_blob.path) + assert_equal(None, diff.a_blob) + assert_equal('f733bce6b57c0e5e353206e692b0e3105c2527f4', diff.b_blob.id) + assert_equal( None, diff.a_mode ) + assert_equal(True, diff.new_file) assert_true(git.called) assert_equal(git.call_args, (('diff', '-M', 'master'), {'full_index': True})) @@ -115,19 +119,21 @@ class TestCommit(object): assert_equal(15, len(diffs)) - assert_equal('.gitignore', diffs[0].a_blob.path) - assert_equal('.gitignore', diffs[0].b_blob.path) - assert_equal('4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diffs[0].a_blob.id) - assert_equal('2dd02534615434d88c51307beb0f0092f21fd103', diffs[0].b_blob.id) - assert_equal('100644', diffs[0].b_blob.mode) - assert_equal(False, diffs[0].new_file) - assert_equal(False, diffs[0].deleted_file) - assert_equal("--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg", diffs[0].diff) - - assert_equal('lib/grit/actor.rb', diffs[5].b_blob.path) - assert_equal(None, diffs[5].a_blob) - assert_equal('f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_blob.id) - assert_equal(True, diffs[5].new_file) + diff = diffs[0] + assert_equal('.gitignore', diff.a_blob.path) + assert_equal('.gitignore', diff.b_blob.path) + assert_equal('4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diff.a_blob.id) + assert_equal('2dd02534615434d88c51307beb0f0092f21fd103', diff.b_blob.id) + assert_mode_644(diff.b_blob.mode) + assert_equal(False, diff.new_file) + assert_equal(False, diff.deleted_file) + assert_equal("--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg", diff.diff) + + diff = diffs[5] + assert_equal('lib/grit/actor.rb', diff.b_blob.path) + assert_equal(None, diff.a_blob) + assert_equal('f733bce6b57c0e5e353206e692b0e3105c2527f4', diff.b_blob.id) + assert_equal(True, diff.new_file) assert_true(git.called) assert_equal(git.call_args, (('diff', '-M', @@ -141,8 +147,14 @@ class TestCommit(object): for diff in commit.diffs: assert isinstance(diff, Diff) assert isinstance(diff.a_blob, Blob) or isinstance(diff.b_blob, Blob) - assert isinstance(diff.a_mode, int) and isinstance(diff.b_mode, int) - assert diff.diff + + if diff.a_mode is not None: + assert isinstance(diff.a_mode, int) + if diff.b_mode is not None: + isinstance(diff.b_mode, int) + + assert diff.diff is not None # can be empty + if diff.renamed: assert diff.rename_from and diff.rename_to and diff.rename_from != diff.rename_to if diff.a_blob is None: @@ -171,8 +183,8 @@ class TestCommit(object): assert_equal(1, len(diffs)) assert_equal(None, diffs[0].a_blob) assert_equal(None, diffs[0].b_blob) - assert_equal('100644', diffs[0].a_mode) - assert_equal('100755', diffs[0].b_mode) + assert_mode_644(diffs[0].a_mode) + assert_mode_755(diffs[0].b_mode) def test_stats(self): commit = Commit(self.repo, id='33ebe7acec14b25c5f84f35a664803fcab2f7781') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index d4316981..aec85506 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -58,7 +58,7 @@ class TestRepo(object): assert_equal("implement Grit#heads", c.message) c = commits[1] - assert_equal([], c.parents) + assert_equal((,), c.parents) c = commits[2] assert_equal(["6e64c55896aabb9a7d8e9f8f296f426d21a78c2c", "7f874954efb9ba35210445be456c74e037ba6af2"], map(lambda p: p.id, c.parents)) diff --git a/test/git/test_tree.py b/test/git/test_tree.py index 205fbf1a..50d34006 100644 --- a/test/git/test_tree.py +++ b/test/git/test_tree.py @@ -31,7 +31,7 @@ class TestTree(object): assert_equal(Tree, tree.__class__) assert_equal("650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44", tree.id) - assert_equal("040000", tree.mode) + assert_equal(0,tree.mode) # git tree objects always use this mode assert_equal("test", tree.path) def test_content_from_string_tree_should_return_blob(self): @@ -41,7 +41,7 @@ class TestTree(object): assert_equal(Blob, tree.__class__) assert_equal("aa94e396335d2957ca92606f909e53e7beaf3fbb", tree.id) - assert_equal("100644", tree.mode) + assert_mode_644(tree.mode) assert_equal("grit.rb", tree.path) def test_content_from_string_tree_should_return_commit(self): -- cgit v1.2.3 From c68459a17ff59043d29c90020fffe651b2164e6a Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Oct 2009 22:50:07 +0200 Subject: Added remaining tests for new base classes and removed some methods whose existance was doubtful or unsafe --- test/git/test_base.py | 48 +++++++++++++++++++++++++++++++++++++++++------- test/git/test_commit.py | 4 ---- test/git/test_repo.py | 2 +- 3 files changed, 42 insertions(+), 12 deletions(-) (limited to 'test/git') diff --git a/test/git/test_base.py b/test/git/test_base.py index 787b92b6..8f522cec 100644 --- a/test/git/test_base.py +++ b/test/git/test_base.py @@ -8,32 +8,66 @@ import time from test.testlib import * from git import * import git.base as base +from itertools import chain class TestBase(object): type_tuples = ( ("blob", "8741fc1d09d61f02ffd8cded15ff603eff1ec070"), ("tree", "3a6a5e3eeed3723c09f1ef0399f81ed6b8d82e79"), - ("commit", "4251bd59fb8e11e40c40548cba38180a9536118c") ) + ("commit", "4251bd59fb8e11e40c40548cba38180a9536118c"), + ("tag", "e56a60e8e9cd333cfba0140a77cd12b0d9398f10") ) def setup(self): self.repo = Repo(GIT_REPO) - def test_base(self): - # test interface of base classes - fcreators = (self.repo.blob, self.repo.tree, self.repo.commit ) + def test_base_object(self): + # test interface of base object classes + fcreators = (self.repo.blob, self.repo.tree, self.repo.commit, lambda id: TagObject(self.repo,id) ) assert len(fcreators) == len(self.type_tuples) - for fcreator, (typename, hexsha) in zip(fcreators, self.type_tuples): + + s = set() + num_objs = 0 + num_index_objs = 0 + for fcreator, (typename, hexsha) in zip(fcreators, self.type_tuples): item = fcreator(hexsha) + num_objs += 1 assert item.id == hexsha assert item.type == typename assert item.size + assert item.data + assert item == item + assert not item != item + assert str(item) == item.id + assert repr(item) + s.add(item) + + if isinstance(item, base.IndexObject): + num_index_objs += 1 + if hasattr(item,'path'): # never runs here + assert not item.path.startswith("/") # must be relative + assert isinstance(item.mode, int) + # END index object check # END for each object type to create - assert False,"TODO: Test for all types" + # each has a unique sha + assert len(s) == num_objs + assert num_index_objs == 2 + def test_tags(self): # tag refs can point to tag objects or to commits - assert False, "TODO: Tag handling" + s = set() + ref_count = 0 + for ref in chain(self.repo.tags, self.repo.heads): + ref_count += 1 + assert isinstance(ref, base.Ref) + assert str(ref) == ref.name + assert repr(ref) + assert ref == ref + assert not ref != ref + s.add(ref) + # END for each ref + assert len(s) == ref_count def test_get_type_by_name(self): for tname in base.Object.TYPES: diff --git a/test/git/test_commit.py b/test/git/test_commit.py index ab1801ee..71dad562 100644 --- a/test/git/test_commit.py +++ b/test/git/test_commit.py @@ -24,10 +24,6 @@ class TestCommit(object): assert_true(git.called) assert_equal(git.call_args, (('rev_list', '4c8124ffcf4039d292442eeccabdeca5af5c5017', '--', ''), {'pretty': 'raw', 'max_count': 1})) - @patch_object(Git, '_call_process') - def test_id_abbrev(self, git): - git.return_value = fixture('rev_list_commit_idabbrev') - assert_equal('80f136f', self.repo.commit('80f136f500dfdb8c3e8abf4ae716f875f0a1b57f').id_abbrev) @patch_object(Git, '_call_process') def test_diff(self, git): diff --git a/test/git/test_repo.py b/test/git/test_repo.py index aec85506..421b8256 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -58,7 +58,7 @@ class TestRepo(object): assert_equal("implement Grit#heads", c.message) c = commits[1] - assert_equal((,), c.parents) + assert_equal(tuple(), c.parents) c = commits[2] assert_equal(["6e64c55896aabb9a7d8e9f8f296f426d21a78c2c", "7f874954efb9ba35210445be456c74e037ba6af2"], map(lambda p: p.id, c.parents)) -- cgit v1.2.3 From f2834177c0fdf6b1af659e460fd3348f468b8ab0 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 12 Oct 2009 11:50:14 +0200 Subject: Reorganized package structure and cleaned up imports --- test/git/test_base.py | 12 +++++++----- test/git/test_blob.py | 28 ---------------------------- test/git/test_repo.py | 27 +++++++++++++++++++++++++++ test/git/test_tag.py | 2 +- 4 files changed, 35 insertions(+), 34 deletions(-) (limited to 'test/git') diff --git a/test/git/test_base.py b/test/git/test_base.py index 8f522cec..a153eb83 100644 --- a/test/git/test_base.py +++ b/test/git/test_base.py @@ -7,8 +7,10 @@ import time from test.testlib import * from git import * -import git.base as base +import git.objects.base as base +import git.refs as refs from itertools import chain +from git.objects.util import get_object_type_by_name class TestBase(object): @@ -60,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, base.Ref) + assert isinstance(ref, refs.Ref) assert str(ref) == ref.name assert repr(ref) assert ref == ref @@ -69,10 +71,10 @@ class TestBase(object): # END for each ref assert len(s) == ref_count - def test_get_type_by_name(self): + def test_get_object_type_by_name(self): for tname in base.Object.TYPES: - assert base.Object in base.Object.get_type_by_name(tname).mro() + assert base.Object in get_object_type_by_name(tname).mro() # END for each known type - assert_raises( ValueError, base.Object.get_type_by_name, "doesntexist" ) + assert_raises( ValueError, get_object_type_by_name, "doesntexist" ) diff --git a/test/git/test_blob.py b/test/git/test_blob.py index 94d3a33b..ebb53d0c 100644 --- a/test/git/test_blob.py +++ b/test/git/test_blob.py @@ -65,34 +65,6 @@ class TestBlob(object): blob = Blob(self.repo, **{'id': 'abc','path': 'something'}) assert_equal("text/plain", blob.mime_type) - @patch_object(Git, '_call_process') - def test_should_display_blame_information(self, git): - git.return_value = fixture('blame') - b = Blob.blame(self.repo, 'master', 'lib/git.py') - assert_equal(13, len(b)) - assert_equal( 2, len(b[0]) ) - # assert_equal(25, reduce(lambda acc, x: acc + len(x[-1]), b)) - assert_equal(hash(b[0][0]), hash(b[9][0])) - c = b[0][0] - assert_true(git.called) - assert_equal(git.call_args, (('blame', 'master', '--', 'lib/git.py'), {'p': True})) - - assert_equal('634396b2f541a9f2d58b00be1a07f0c358b999b3', c.id) - assert_equal('Tom Preston-Werner', c.author.name) - assert_equal('tom@mojombo.com', c.author.email) - assert_equal(time.gmtime(1191997100), c.authored_date) - assert_equal('Tom Preston-Werner', c.committer.name) - assert_equal('tom@mojombo.com', c.committer.email) - assert_equal(time.gmtime(1191997100), c.committed_date) - assert_equal('initial grit setup', c.message) - - # test the 'lines per commit' entries - tlist = b[0][1] - assert_true( tlist ) - assert_true( isinstance( tlist[0], basestring ) ) - assert_true( len( tlist ) < sum( len(t) for t in tlist ) ) # test for single-char bug - - def test_should_return_appropriate_representation(self): blob = Blob(self.repo, **{'id': 'abc'}) assert_equal('', repr(blob)) diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 421b8256..3e2fb3dc 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -257,3 +257,30 @@ class TestRepo(object): git.return_value = 'refs/heads/major-refactoring' assert_equal(self.repo.active_branch, 'major-refactoring') assert_equal(git.call_args, (('symbolic_ref', 'HEAD'), {})) + + @patch_object(Git, '_call_process') + def test_should_display_blame_information(self, git): + git.return_value = fixture('blame') + b = self.repo.blame( 'master', 'lib/git.py') + assert_equal(13, len(b)) + assert_equal( 2, len(b[0]) ) + # assert_equal(25, reduce(lambda acc, x: acc + len(x[-1]), b)) + assert_equal(hash(b[0][0]), hash(b[9][0])) + c = b[0][0] + assert_true(git.called) + assert_equal(git.call_args, (('blame', 'master', '--', 'lib/git.py'), {'p': True})) + + assert_equal('634396b2f541a9f2d58b00be1a07f0c358b999b3', c.id) + assert_equal('Tom Preston-Werner', c.author.name) + assert_equal('tom@mojombo.com', c.author.email) + assert_equal(time.gmtime(1191997100), c.authored_date) + assert_equal('Tom Preston-Werner', c.committer.name) + assert_equal('tom@mojombo.com', c.committer.email) + assert_equal(time.gmtime(1191997100), c.committed_date) + assert_equal('initial grit setup', c.message) + + # test the 'lines per commit' entries + tlist = b[0][1] + assert_true( tlist ) + assert_true( isinstance( tlist[0], basestring ) ) + assert_true( len( tlist ) < sum( len(t) for t in tlist ) ) # test for single-char bug diff --git a/test/git/test_tag.py b/test/git/test_tag.py index fe3f78cc..2ebb860a 100644 --- a/test/git/test_tag.py +++ b/test/git/test_tag.py @@ -7,7 +7,7 @@ from mock import * from test.testlib import * from git import * -from git.tag import TagObject +from git.objects.tag import TagObject import time class TestTag(object): -- cgit v1.2.3 From 637eadce54ca8bbe536bcf7c570c025e28e47129 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 12 Oct 2009 14:56:47 +0200 Subject: renamed from_string and list_from_string to _from_string and _list_from_string to indicate their new status as private method, adjusted all callers respectively --- test/git/test_actor.py | 8 ++++---- test/git/test_commit.py | 2 +- test/git/test_diff.py | 4 ++-- test/git/test_stats.py | 4 ++-- test/git/test_tree.py | 8 ++++---- 5 files changed, 13 insertions(+), 13 deletions(-) (limited to 'test/git') diff --git a/test/git/test_actor.py b/test/git/test_actor.py index ae4da507..b7c2af7c 100644 --- a/test/git/test_actor.py +++ b/test/git/test_actor.py @@ -10,19 +10,19 @@ from git import * class TestActor(object): def test_from_string_should_separate_name_and_email(self): - a = Actor.from_string("Michael Trier ") + a = Actor._from_string("Michael Trier ") assert_equal("Michael Trier", a.name) assert_equal("mtrier@example.com", a.email) def test_from_string_should_handle_just_name(self): - a = Actor.from_string("Michael Trier") + a = Actor._from_string("Michael Trier") assert_equal("Michael Trier", a.name) assert_equal(None, a.email) def test_should_display_representation(self): - a = Actor.from_string("Michael Trier ") + a = Actor._from_string("Michael Trier ") assert_equal('">', repr(a)) def test_str_should_alias_name(self): - a = Actor.from_string("Michael Trier ") + a = Actor._from_string("Michael Trier ") assert_equal(a.name, str(a)) \ No newline at end of file diff --git a/test/git/test_commit.py b/test/git/test_commit.py index 71dad562..fa49821d 100644 --- a/test/git/test_commit.py +++ b/test/git/test_commit.py @@ -216,7 +216,7 @@ class TestCommit(object): bisect_all=True) assert_true(git.called) - commits = Commit.list_from_string(self.repo, revs) + commits = Commit._list_from_string(self.repo, revs) expected_ids = ( 'cf37099ea8d1d8c7fbf9b6d12d7ec0249d3acb8b', '33ebe7acec14b25c5f84f35a664803fcab2f7781', diff --git a/test/git/test_diff.py b/test/git/test_diff.py index b9834879..b2339455 100644 --- a/test/git/test_diff.py +++ b/test/git/test_diff.py @@ -13,13 +13,13 @@ class TestDiff(object): def test_list_from_string_new_mode(self): output = fixture('diff_new_mode') - diffs = Diff.list_from_string(self.repo, output) + diffs = Diff._list_from_string(self.repo, output) assert_equal(1, len(diffs)) assert_equal(10, len(diffs[0].diff.splitlines())) def test_diff_with_rename(self): output = fixture('diff_rename') - diffs = Diff.list_from_string(self.repo, output) + diffs = Diff._list_from_string(self.repo, output) assert_equal(1, len(diffs)) diff --git a/test/git/test_stats.py b/test/git/test_stats.py index 0063bb2d..706f29a4 100644 --- a/test/git/test_stats.py +++ b/test/git/test_stats.py @@ -11,9 +11,9 @@ class TestStats(object): def setup(self): self.repo = Repo(GIT_REPO) - def test_list_from_string(self): + def test__list_from_string(self): output = fixture('diff_numstat') - stats = Stats.list_from_string(self.repo, output) + stats = Stats._list_from_string(self.repo, output) assert_equal(2, stats.total['files']) assert_equal(52, stats.total['lines']) diff --git a/test/git/test_tree.py b/test/git/test_tree.py index 50d34006..cb8ebb04 100644 --- a/test/git/test_tree.py +++ b/test/git/test_tree.py @@ -27,7 +27,7 @@ class TestTree(object): def test_content_from_string_tree_should_return_tree(self): text = fixture('ls_tree_a').splitlines()[-1] - tree = Tree.content_from_string(None, text) + tree = Tree.content__from_string(None, text) assert_equal(Tree, tree.__class__) assert_equal("650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44", tree.id) @@ -37,7 +37,7 @@ class TestTree(object): def test_content_from_string_tree_should_return_blob(self): text = fixture('ls_tree_b').split("\n")[0] - tree = Tree.content_from_string(None, text) + tree = Tree.content__from_string(None, text) assert_equal(Blob, tree.__class__) assert_equal("aa94e396335d2957ca92606f909e53e7beaf3fbb", tree.id) @@ -47,12 +47,12 @@ class TestTree(object): def test_content_from_string_tree_should_return_commit(self): text = fixture('ls_tree_commit').split("\n")[1] - tree = Tree.content_from_string(None, text) + tree = Tree.content__from_string(None, text) assert_none(tree) @raises(TypeError) def test_content_from_string_invalid_type_should_raise(self): - Tree.content_from_string(None, "040000 bogus 650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44 test") + Tree.content__from_string(None, "040000 bogus 650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44 test") @patch_object(Blob, 'size') @patch_object(Git, '_call_process') -- cgit v1.2.3 From beb76aba0c835669629d95c905551f58cc927299 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 12 Oct 2009 17:41:00 +0200 Subject: repo.active_branch now returns a Head object, not a string --- test/git/test_repo.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'test/git') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 3e2fb3dc..e999ffe8 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -91,13 +91,12 @@ class TestRepo(object): def test_tree(self, git): git.return_value = fixture('ls_tree_a') - tree = self.repo.tree('master') + tree = self.repo.tree(Head(self.repo, 'master')) assert_equal(4, len([c for c in tree.values() if isinstance(c, Blob)])) assert_equal(3, len([c for c in tree.values() if isinstance(c, Tree)])) assert_true(git.called) - assert_equal(git.call_args, (('ls_tree', 'master'), {})) @patch_object(Git, '_call_process') def test_blob(self, git): @@ -255,7 +254,7 @@ class TestRepo(object): @patch_object(Git, '_call_process') def test_active_branch(self, git): git.return_value = 'refs/heads/major-refactoring' - assert_equal(self.repo.active_branch, 'major-refactoring') + assert_equal(self.repo.active_branch.name, 'major-refactoring') assert_equal(git.call_args, (('symbolic_ref', 'HEAD'), {})) @patch_object(Git, '_call_process') -- cgit v1.2.3 From ff3d142387e1f38b0ed390333ea99e2e23d96e35 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 12 Oct 2009 18:02:07 +0200 Subject: test_base: Improved basic object creation as well as set hash tests --- test/git/test_base.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'test/git') diff --git a/test/git/test_base.py b/test/git/test_base.py index a153eb83..aff0947d 100644 --- a/test/git/test_base.py +++ b/test/git/test_base.py @@ -24,14 +24,14 @@ class TestBase(object): def test_base_object(self): # test interface of base object classes - fcreators = (self.repo.blob, self.repo.tree, self.repo.commit, lambda id: TagObject(self.repo,id) ) - assert len(fcreators) == len(self.type_tuples) + types = (Blob, Tree, Commit, TagObject) + assert len(types) == len(self.type_tuples) s = set() num_objs = 0 num_index_objs = 0 - for fcreator, (typename, hexsha) in zip(fcreators, self.type_tuples): - item = fcreator(hexsha) + for obj_type, (typename, hexsha) in zip(types, self.type_tuples): + item = obj_type(self.repo,hexsha) num_objs += 1 assert item.id == hexsha assert item.type == typename @@ -53,6 +53,7 @@ class TestBase(object): # each has a unique sha assert len(s) == num_objs + assert len(s|s) == num_objs assert num_index_objs == 2 @@ -70,6 +71,7 @@ class TestBase(object): s.add(ref) # END for each ref assert len(s) == ref_count + assert len(s|s) == ref_count def test_get_object_type_by_name(self): for tname in base.Object.TYPES: -- cgit v1.2.3 From a58a60ac5f322eb4bfd38741469ff21b5a33d2d5 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 12 Oct 2009 23:18:43 +0200 Subject: tree: now behaves like a list with string indexing functionality - using a dict as cache is a problem as the tree is ordered, added blobs, trees and traverse method repo: remove blob function as blobs are created directly or iterated - primitve types should not clutter the repo interface --- test/git/test_repo.py | 6 ++--- test/git/test_tree.py | 68 +++++++++++++++++++++++++++++++++------------------ 2 files changed, 47 insertions(+), 27 deletions(-) (limited to 'test/git') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index e999ffe8..7f87f78b 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -93,8 +93,8 @@ class TestRepo(object): tree = self.repo.tree(Head(self.repo, 'master')) - assert_equal(4, len([c for c in tree.values() if isinstance(c, Blob)])) - assert_equal(3, len([c for c in tree.values() if isinstance(c, Tree)])) + assert_equal(4, len([c for c in tree if isinstance(c, Blob)])) + assert_equal(3, len([c for c in tree if isinstance(c, Tree)])) assert_true(git.called) @@ -102,7 +102,7 @@ class TestRepo(object): def test_blob(self, git): git.return_value = fixture('cat_file_blob') - blob = self.repo.blob("abc") + blob = Blob(self.repo,"abc") assert_equal("Hello world", blob.data) assert_true(git.called) diff --git a/test/git/test_tree.py b/test/git/test_tree.py index cb8ebb04..e0429db1 100644 --- a/test/git/test_tree.py +++ b/test/git/test_tree.py @@ -7,19 +7,20 @@ from test.testlib import * from git import * -class TestTree(object): - def setup(self): +class TestTree(TestCase): + + def setUp(self): self.repo = Repo(GIT_REPO) @patch_object(Git, '_call_process') def test_contents_should_cache(self, git): git.return_value = fixture('ls_tree_a') + fixture('ls_tree_b') - tree = self.repo.tree('master') + tree = self.repo.tree(Head(self.repo,'master')) child = tree['grit'] - child.items() - child.items() + len(child) + len(child) assert_true(git.called) assert_equal(2, git.call_count) @@ -27,7 +28,7 @@ class TestTree(object): def test_content_from_string_tree_should_return_tree(self): text = fixture('ls_tree_a').splitlines()[-1] - tree = Tree.content__from_string(None, text) + tree = Tree.content_from_string(None, text) assert_equal(Tree, tree.__class__) assert_equal("650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44", tree.id) @@ -37,7 +38,7 @@ class TestTree(object): def test_content_from_string_tree_should_return_blob(self): text = fixture('ls_tree_b').split("\n")[0] - tree = Tree.content__from_string(None, text) + tree = Tree.content_from_string(None, text) assert_equal(Blob, tree.__class__) assert_equal("aa94e396335d2957ca92606f909e53e7beaf3fbb", tree.id) @@ -47,12 +48,12 @@ class TestTree(object): def test_content_from_string_tree_should_return_commit(self): text = fixture('ls_tree_commit').split("\n")[1] - tree = Tree.content__from_string(None, text) + tree = Tree.content_from_string(None, text) assert_none(tree) @raises(TypeError) def test_content_from_string_invalid_type_should_raise(self): - Tree.content__from_string(None, "040000 bogus 650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44 test") + Tree.content_from_string(None, "040000 bogus 650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44 test") @patch_object(Blob, 'size') @patch_object(Git, '_call_process') @@ -60,13 +61,37 @@ class TestTree(object): git.return_value = fixture('ls_tree_a') blob.return_value = 1 - tree = self.repo.tree('master') + tree = self.repo.tree(Head(self.repo,'master')) assert_equal('aa06ba24b4e3f463b3c4a85469d0fb9e5b421cf8', (tree/'lib').id) assert_equal('8b1e02c0fb554eed2ce2ef737a68bb369d7527df', (tree/'README.txt').id) assert_true(git.called) - assert_equal(git.call_args, (('ls_tree', 'master'), {})) + + def test_traverse(self): + root = self.repo.tree() + num_recursive = 0 + all_items = list() + for obj in root.traverse(): + if "/" in obj.path: + num_recursive += 1 + + assert isinstance(obj, (Blob, Tree)) + all_items.append(obj) + # END for each object + # limit recursion level to 0 - should be same as default iteration + assert all_items + assert 'CHANGES' in root + assert len(list(root)) == len(list(root.traverse(max_depth=0))) + + # only choose trees + trees_only = lambda i: i.type == "tree" + trees = list(root.traverse(predicate = trees_only)) + assert len(trees) == len(list( i for i in root.traverse() if trees_only(i) )) + + # trees and blobs + assert len(set(trees)|set(root.trees)) == len(trees) + assert len(set(b for b in root if isinstance(b, Blob)) | set(root.blobs)) == len( root.blobs ) @patch_object(Blob, 'size') @patch_object(Git, '_call_process') @@ -74,26 +99,24 @@ class TestTree(object): git.return_value = fixture('ls_tree_a') blob.return_value = 0 - tree = self.repo.tree('master') + tree = self.repo.tree(Head(self.repo,'master')) assert_not_none(tree/'README.txt') assert_equal('8b1e02c0fb554eed2ce2ef737a68bb369d7527df', (tree/'README.txt').id) assert_true(git.called) - assert_equal(git.call_args, (('ls_tree', 'master'), {})) @patch_object(Git, '_call_process') def test_slash_with_commits(self, git): git.return_value = fixture('ls_tree_commit') - tree = self.repo.tree('master') + tree = self.repo.tree(Head(self.repo,'master')) - assert_none(tree/'bar') + self.failUnlessRaises(KeyError, tree.__div__, 'bar') assert_equal('2afb47bcedf21663580d5e6d2f406f08f3f65f19', (tree/'foo').id) assert_equal('f623ee576a09ca491c4a27e48c0dfe04be5f4a2e', (tree/'baz').id) assert_true(git.called) - assert_equal(git.call_args, (('ls_tree', 'master'), {})) @patch_object(Blob, 'size') @patch_object(Git, '_call_process') @@ -101,13 +124,12 @@ class TestTree(object): git.return_value = fixture('ls_tree_a') blob.return_value = 1 - tree = self.repo.tree('master') + tree = self.repo.tree(Head(self.repo,'master')) assert_equal('aa06ba24b4e3f463b3c4a85469d0fb9e5b421cf8', tree['lib'].id) assert_equal('8b1e02c0fb554eed2ce2ef737a68bb369d7527df', tree['README.txt'].id) assert_true(git.called) - assert_equal(git.call_args, (('ls_tree', 'master'), {})) @patch_object(Blob, 'size') @patch_object(Git, '_call_process') @@ -115,33 +137,31 @@ class TestTree(object): git.return_value = fixture('ls_tree_a') blob.return_value = 0 - tree = self.repo.tree('master') + tree = self.repo.tree(Head(self.repo,'master')) assert_not_none(tree['README.txt']) assert_equal('8b1e02c0fb554eed2ce2ef737a68bb369d7527df', tree['README.txt'].id) assert_true(git.called) - assert_equal(git.call_args, (('ls_tree', 'master'), {})) @patch_object(Git, '_call_process') def test_dict_with_commits(self, git): git.return_value = fixture('ls_tree_commit') - tree = self.repo.tree('master') + tree = self.repo.tree(Head(self.repo,'master')) - assert_none(tree.get('bar')) + self.failUnlessRaises(KeyError, tree.__getitem__, 'bar') assert_equal('2afb47bcedf21663580d5e6d2f406f08f3f65f19', tree['foo'].id) assert_equal('f623ee576a09ca491c4a27e48c0dfe04be5f4a2e', tree['baz'].id) assert_true(git.called) - assert_equal(git.call_args, (('ls_tree', 'master'), {})) @patch_object(Git, '_call_process') @raises(KeyError) def test_dict_with_non_existant_file(self, git): git.return_value = fixture('ls_tree_commit') - tree = self.repo.tree('master') + tree = self.repo.tree(Head(self.repo,'master')) tree['bar'] def test_repr(self): -- cgit v1.2.3 From 86fa577e135713e56b287169d69d976cde27ac97 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 13 Oct 2009 17:36:27 +0200 Subject: tree: renamed content_from_string to _from_string to make it private. Removed tests that were testing that method --- test/git/test_tree.py | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) (limited to 'test/git') diff --git a/test/git/test_tree.py b/test/git/test_tree.py index e0429db1..0104a16b 100644 --- a/test/git/test_tree.py +++ b/test/git/test_tree.py @@ -25,35 +25,10 @@ class TestTree(TestCase): assert_true(git.called) assert_equal(2, git.call_count) assert_equal(git.call_args, (('ls_tree', '34868e6e7384cb5ee51c543a8187fdff2675b5a7'), {})) - - def test_content_from_string_tree_should_return_tree(self): - text = fixture('ls_tree_a').splitlines()[-1] - tree = Tree.content_from_string(None, text) - - assert_equal(Tree, tree.__class__) - assert_equal("650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44", tree.id) - assert_equal(0,tree.mode) # git tree objects always use this mode - assert_equal("test", tree.path) - - def test_content_from_string_tree_should_return_blob(self): - text = fixture('ls_tree_b').split("\n")[0] - - tree = Tree.content_from_string(None, text) - - assert_equal(Blob, tree.__class__) - assert_equal("aa94e396335d2957ca92606f909e53e7beaf3fbb", tree.id) - assert_mode_644(tree.mode) - assert_equal("grit.rb", tree.path) - - def test_content_from_string_tree_should_return_commit(self): - text = fixture('ls_tree_commit').split("\n")[1] - - tree = Tree.content_from_string(None, text) - assert_none(tree) @raises(TypeError) - def test_content_from_string_invalid_type_should_raise(self): - Tree.content_from_string(None, "040000 bogus 650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44 test") + def test__from_string_invalid_type_should_raise(self): + Tree._from_string(None, "040000 bogus 650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44 test") @patch_object(Blob, 'size') @patch_object(Git, '_call_process') -- cgit v1.2.3 From 5eb0f2c241718bc7462be44e5e8e1e36e35f9b15 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 13 Oct 2009 17:50:26 +0200 Subject: unified name of utils module, recently it was named util and utils in different packages --- test/git/test_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/git') diff --git a/test/git/test_base.py b/test/git/test_base.py index aff0947d..97dfc255 100644 --- a/test/git/test_base.py +++ b/test/git/test_base.py @@ -10,7 +10,7 @@ from git import * import git.objects.base as base import git.refs as refs from itertools import chain -from git.objects.util import get_object_type_by_name +from git.objects.utils import get_object_type_by_name class TestBase(object): -- cgit v1.2.3 From 6acec357c7609fdd2cb0f5fdb1d2756726c7fe98 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 13 Oct 2009 21:26:19 +0200 Subject: renamed find_all to list_all, changed commit to use iterable interface in preparation for command changes --- test/git/test_commit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/git') diff --git a/test/git/test_commit.py b/test/git/test_commit.py index fa49821d..0fb4bceb 100644 --- a/test/git/test_commit.py +++ b/test/git/test_commit.py @@ -216,7 +216,7 @@ class TestCommit(object): bisect_all=True) assert_true(git.called) - commits = Commit._list_from_string(self.repo, revs) + commits = Commit._iter_from_stream(self.repo, iter(revs.splitlines(False))) expected_ids = ( 'cf37099ea8d1d8c7fbf9b6d12d7ec0249d3acb8b', '33ebe7acec14b25c5f84f35a664803fcab2f7781', -- cgit v1.2.3 From ead94f267065bb55303f79a0a6df477810b3c68d Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 14 Oct 2009 14:33:51 +0200 Subject: cmd: added option to return the process directly, allowing to read the output directly from the output stream commit: now reads commit information directly from the output stream of the process by implementing its iterator method repo: removed log method as it was redundant ( equal to the commits method ) --- test/git/test_commit.py | 28 ++++++++-------------------- test/git/test_repo.py | 22 ++-------------------- 2 files changed, 10 insertions(+), 40 deletions(-) (limited to 'test/git') diff --git a/test/git/test_commit.py b/test/git/test_commit.py index 0fb4bceb..00af6b52 100644 --- a/test/git/test_commit.py +++ b/test/git/test_commit.py @@ -11,18 +11,13 @@ class TestCommit(object): def setup(self): self.repo = Repo(GIT_REPO) - @patch_object(Git, '_call_process') - def test_bake(self, git): - git.return_value = fixture('rev_list_single') + def test_bake(self): - commit = Commit(self.repo, **{'id': '4c8124ffcf4039d292442eeccabdeca5af5c5017'}) + commit = Commit(self.repo, **{'id': '2454ae89983a4496a445ce347d7a41c0bb0ea7ae'}) commit.author # bake - assert_equal("Tom Preston-Werner", commit.author.name) - assert_equal("tom@mojombo.com", commit.author.email) - - assert_true(git.called) - assert_equal(git.call_args, (('rev_list', '4c8124ffcf4039d292442eeccabdeca5af5c5017', '--', ''), {'pretty': 'raw', 'max_count': 1})) + assert_equal("Sebastian Thiel", commit.author.name) + assert_equal("byronimo@gmail.com", commit.author.email) @patch_object(Git, '_call_process') @@ -159,17 +154,10 @@ class TestCommit(object): assert diff.deleted_file and isinstance(diff.deleted_file, bool) # END for each diff in initial import commit - @patch_object(Git, '_call_process') - def test_diffs_on_initial_import_with_empty_commit(self, git): - git.return_value = fixture('show_empty_commit') - - commit = Commit(self.repo, id='634396b2f541a9f2d58b00be1a07f0c358b999b3') + def test_diffs_on_initial_import_without_parents(self): + commit = Commit(self.repo, id='33ebe7acec14b25c5f84f35a664803fcab2f7781') diffs = commit.diffs - - assert_equal([], diffs) - - assert_true(git.called) - assert_equal(git.call_args, (('show', '634396b2f541a9f2d58b00be1a07f0c358b999b3', '-M'), {'full_index': True, 'pretty': 'raw'})) + assert diffs def test_diffs_with_mode_only_change(self): commit = Commit(self.repo, id='ccde80b7a3037a004a7807a6b79916ce2a1e9729') @@ -216,7 +204,7 @@ class TestCommit(object): bisect_all=True) assert_true(git.called) - commits = Commit._iter_from_stream(self.repo, iter(revs.splitlines(False))) + commits = Commit._iter_from_process(self.repo, ListProcessAdapter(revs)) expected_ids = ( 'cf37099ea8d1d8c7fbf9b6d12d7ec0249d3acb8b', '33ebe7acec14b25c5f84f35a664803fcab2f7781', diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 7f87f78b..f0687050 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -41,7 +41,7 @@ class TestRepo(object): @patch_object(Git, '_call_process') def test_commits(self, git): - git.return_value = fixture('rev_list') + git.return_value = ListProcessAdapter(fixture('rev_list')) commits = self.repo.commits('master', max_count=10) @@ -65,7 +65,6 @@ class TestRepo(object): assert_equal("Merge branch 'site'", c.summary) assert_true(git.called) - assert_equal(git.call_args, (('rev_list', 'master', '--', ''), {'skip': 0, 'pretty': 'raw', 'max_count': 10})) @patch_object(Git, '_call_process') def test_commit_count(self, git): @@ -78,14 +77,13 @@ class TestRepo(object): @patch_object(Git, '_call_process') def test_commit(self, git): - git.return_value = fixture('rev_list_single') + git.return_value = ListProcessAdapter(fixture('rev_list_single')) commit = self.repo.commit('4c8124ffcf4039d292442eeccabdeca5af5c5017') assert_equal("4c8124ffcf4039d292442eeccabdeca5af5c5017", commit.id) assert_true(git.called) - assert_equal(git.call_args, (('rev_list', '4c8124ffcf4039d292442eeccabdeca5af5c5017', '--', ''), {'pretty': 'raw', 'max_count': 1})) @patch_object(Git, '_call_process') def test_tree(self, git): @@ -217,22 +215,6 @@ class TestRepo(object): path = os.path.join(os.path.abspath(GIT_REPO), '.git') assert_equal('' % path, repr(self.repo)) - @patch_object(Git, '_call_process') - def test_log(self, git): - git.return_value = fixture('rev_list') - assert_equal('4c8124ffcf4039d292442eeccabdeca5af5c5017', self.repo.log()[0].id) - assert_equal('ab25fd8483882c3bda8a458ad2965d2248654335', self.repo.log()[-1].id) - assert_true(git.called) - assert_equal(git.call_count, 2) - assert_equal(git.call_args, (('log', 'master', '--'), {'pretty': 'raw'})) - - @patch_object(Git, '_call_process') - def test_log_with_path_and_options(self, git): - git.return_value = fixture('rev_list') - self.repo.log('master', 'file.rb', **{'max_count': 1}) - assert_true(git.called) - assert_equal(git.call_args, (('log', 'master', '--', 'file.rb'), {'pretty': 'raw', 'max_count': 1})) - def test_is_dirty_with_bare_repository(self): self.repo.bare = True assert_false(self.repo.is_dirty) -- cgit v1.2.3 From 6eeae8b24135b4de05f6d725b009c287577f053d Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 14 Oct 2009 17:24:15 +0200 Subject: test: Added time-consuming test which could also be a benchmark in fact - currently it cause hundreds of command invocations which is slow Fixed issue with trees not properly initialized with their default mode _set_cache_: some objects checked whether the attribute was within their __slots__ although it should have been accessed through its class --- test/git/test_commit.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/git') diff --git a/test/git/test_commit.py b/test/git/test_commit.py index 00af6b52..fd8fc51e 100644 --- a/test/git/test_commit.py +++ b/test/git/test_commit.py @@ -229,3 +229,18 @@ class TestCommit(object): commit3 = Commit(self.repo, id='zyx') assert_equal(commit1, commit2) assert_not_equal(commit2, commit3) + + def test_iteration(self): + root = self.repo.tree() + head = self.repo.active_branch + num_objs = 0 + + # find the first commit containing the given path - always do a full + # iteration ( restricted to the path in question ), but in fact it should + # return quite a lot of commits, we just take one and hence abort the operation + for obj in root.traverse(): + num_objs += 1 + commit = Commit.iter_items( self.repo, head, obj.path ).next() + assert obj in commit.tree.traverse() + # END for each object + -- cgit v1.2.3 From a28d3d18f9237af5101eb22e506a9ddda6d44025 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 14 Oct 2009 18:50:55 +0200 Subject: Implemented git command facility to keep persistent commands for fast object information retrieval --- test/git/test_git.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'test/git') diff --git a/test/git/test_git.py b/test/git/test_git.py index c9f399cc..591d5939 100644 --- a/test/git/test_git.py +++ b/test/git/test_git.py @@ -10,8 +10,7 @@ from git import Git, GitCommandError class TestGit(object): def setup(self): - base = os.path.join(os.path.dirname(__file__), "../..") - self.git = Git(base) + self.git = Git(GIT_REPO) @patch_object(Git, 'execute') def test_call_process_calls_execute(self, git): @@ -56,3 +55,35 @@ class TestGit(object): # this_should_not_be_ignored=False implies it *should* be ignored output = self.git.version(pass_this_kwarg=False) assert_true("pass_this_kwarg" not in git.call_args[1]) + + def test_persistent_cat_file_command(self): + # read header only + import subprocess as sp + hexsha = "b2339455342180c7cc1e9bba3e9f181f7baa5167" + g = self.git.cat_file(batch_check=True, istream=sp.PIPE,as_process=True) + g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n") + g.stdin.flush() + obj_info = g.stdout.readline() + + # read header + data + g = self.git.cat_file(batch=True, istream=sp.PIPE,as_process=True) + g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n") + g.stdin.flush() + obj_info_two = g.stdout.readline() + assert obj_info == obj_info_two + + # read data - have to read it in one large chunk + size = int(obj_info.split()[2]) + data = g.stdout.read(size) + terminating_newline = g.stdout.read(1) + + # now we should be able to read a new object + g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n") + g.stdin.flush() + assert g.stdout.readline() == obj_info + + + # same can be achived using the respective command functions + typename, size = self.git.get_object_header(hexsha) + typename_two, size_two, data = self.git.get_object_data(hexsha) + assert typename == typename_two and size == size_two -- cgit v1.2.3 From 6745f4542cfb74bbf3b933dba7a59ef2f54a4380 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 14 Oct 2009 19:34:45 +0200 Subject: test_blob: removed many redundant tests that would fail now as the mock cannot handle the complexity of the command backend All objects but Tree now use the persistent command to read their object information - Trees get binary data and would need their own pretty-printing or they need to parse the data themselves which is my favorite --- test/git/test_base.py | 10 ++++++++++ test/git/test_blob.py | 49 ++++++------------------------------------------- test/git/test_commit.py | 2 +- test/git/test_repo.py | 10 ---------- 4 files changed, 17 insertions(+), 54 deletions(-) (limited to 'test/git') diff --git a/test/git/test_base.py b/test/git/test_base.py index 97dfc255..6e3aad7f 100644 --- a/test/git/test_base.py +++ b/test/git/test_base.py @@ -73,6 +73,16 @@ class TestBase(object): assert len(s) == ref_count assert len(s|s) == ref_count + def test_heads(self): + # see how it dynmically updates its object + for head in self.repo.heads: + head.name + head.path + cur_obj = head.object + del( head.object ) + assert cur_obj == head.object + # END for each head + def test_get_object_type_by_name(self): for tname in base.Object.TYPES: assert base.Object in get_object_type_by_name(tname).mro() diff --git a/test/git/test_blob.py b/test/git/test_blob.py index ebb53d0c..266f3a23 100644 --- a/test/git/test_blob.py +++ b/test/git/test_blob.py @@ -12,51 +12,14 @@ class TestBlob(object): def setup(self): self.repo = Repo(GIT_REPO) - @patch_object(Git, '_call_process') - def test_should_return_blob_contents(self, git): - git.return_value = fixture('cat_file_blob') - blob = Blob(self.repo, **{'id': 'abc'}) - assert_equal("Hello world", blob.data) - assert_true(git.called) - assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True, 'with_raw_output': True})) - - @patch_object(Git, '_call_process') - def test_should_return_blob_contents_with_newline(self, git): - git.return_value = fixture('cat_file_blob_nl') - blob = Blob(self.repo, **{'id': 'abc'}) - assert_equal("Hello world\n", blob.data) - assert_true(git.called) - assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True, 'with_raw_output': True})) - - @patch_object(Git, '_call_process') - def test_should_cache_data(self, git): - git.return_value = fixture('cat_file_blob') - bid = '787b92b63f629398f3d2ceb20f7f0c2578259e84' + def test_should_cache_data(self): + bid = 'a802c139d4767c89dcad79d836d05f7004d39aac' blob = Blob(self.repo, bid) blob.data - blob.data - assert_true(git.called) - assert_equal(git.call_count, 1) - assert_equal(git.call_args, (('cat_file', bid), {'p': True, 'with_raw_output': True})) - - @patch_object(Git, '_call_process') - def test_should_return_file_size(self, git): - git.return_value = fixture('cat_file_blob_size') - blob = Blob(self.repo, **{'id': 'abc'}) - assert_equal(11, blob.size) - assert_true(git.called) - assert_equal(git.call_args, (('cat_file', 'abc'), {'s': True})) - - @patch_object(Git, '_call_process') - def test_should_cache_file_size(self, git): - git.return_value = fixture('cat_file_blob_size') - blob = Blob(self.repo, **{'id': 'abc'}) - assert_equal(11, blob.size) - assert_equal(11, blob.size) - assert_true(git.called) - assert_equal(git.call_count, 1) - assert_equal(git.call_args, (('cat_file', 'abc'), {'s': True})) - + assert blob.data + blob.size + blob.size + def test_mime_type_should_return_mime_type_for_known_types(self): blob = Blob(self.repo, **{'id': 'abc', 'path': 'foo.png'}) assert_equal("image/png", blob.mime_type) diff --git a/test/git/test_commit.py b/test/git/test_commit.py index fd8fc51e..c050fd11 100644 --- a/test/git/test_commit.py +++ b/test/git/test_commit.py @@ -204,7 +204,7 @@ class TestCommit(object): bisect_all=True) assert_true(git.called) - commits = Commit._iter_from_process(self.repo, ListProcessAdapter(revs)) + commits = Commit._iter_from_process_or_stream(self.repo, ListProcessAdapter(revs)) expected_ids = ( 'cf37099ea8d1d8c7fbf9b6d12d7ec0249d3acb8b', '33ebe7acec14b25c5f84f35a664803fcab2f7781', diff --git a/test/git/test_repo.py b/test/git/test_repo.py index f0687050..b882752d 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -96,16 +96,6 @@ class TestRepo(object): assert_true(git.called) - @patch_object(Git, '_call_process') - def test_blob(self, git): - git.return_value = fixture('cat_file_blob') - - blob = Blob(self.repo,"abc") - assert_equal("Hello world", blob.data) - - assert_true(git.called) - assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True, 'with_raw_output': True})) - @patch_object(Repo, '__init__') @patch_object(Git, '_call_process') def test_init_bare(self, git, repo): -- cgit v1.2.3 From c5df44408218003eb49e3b8fc94329c5e8b46c7d Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 14 Oct 2009 19:41:27 +0200 Subject: persistent command signature changed to also return the hexsha from a possible input ref - the objects pointed to by refs are now baked on demand - perhaps it should change to always be re-retrieved using a property as it is relatively fast - this way refs can always be cached --- test/git/test_git.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/git') diff --git a/test/git/test_git.py b/test/git/test_git.py index 591d5939..1f44aebc 100644 --- a/test/git/test_git.py +++ b/test/git/test_git.py @@ -84,6 +84,6 @@ class TestGit(object): # same can be achived using the respective command functions - typename, size = self.git.get_object_header(hexsha) - typename_two, size_two, data = self.git.get_object_data(hexsha) + hexsha, typename, size = self.git.get_object_header(hexsha) + hexsha, typename_two, size_two, data = self.git.get_object_data(hexsha) assert typename == typename_two and size == size_two -- cgit v1.2.3 From 832b56394b079c9f6e4c777934447a9e224facfe Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 14 Oct 2009 19:46:24 +0200 Subject: Refs are now truly dynamic - this costs a little bit of (persistent command) work, but assures refs behave as expected --- test/git/test_base.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'test/git') diff --git a/test/git/test_base.py b/test/git/test_base.py index 6e3aad7f..402cdba3 100644 --- a/test/git/test_base.py +++ b/test/git/test_base.py @@ -78,9 +78,10 @@ class TestBase(object): for head in self.repo.heads: head.name head.path - cur_obj = head.object - del( head.object ) - assert cur_obj == head.object + prev_object = head.object + cur_object = head.object + assert prev_object == cur_object # represent the same git object + assert prev_object is not cur_object # but are different instances # END for each head def test_get_object_type_by_name(self): -- cgit v1.2.3 From 2e6d110fbfa1f2e6a96bc8329e936d0cf1192844 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 14 Oct 2009 23:37:45 +0200 Subject: tree: now reads tress directly by parsing the binary data, allowing it to safe possibly hundreds of command calls --- test/git/test_repo.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'test/git') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index b882752d..e998ac6d 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -84,18 +84,7 @@ class TestRepo(object): assert_equal("4c8124ffcf4039d292442eeccabdeca5af5c5017", commit.id) assert_true(git.called) - - @patch_object(Git, '_call_process') - def test_tree(self, git): - git.return_value = fixture('ls_tree_a') - - tree = self.repo.tree(Head(self.repo, 'master')) - - assert_equal(4, len([c for c in tree if isinstance(c, Blob)])) - assert_equal(3, len([c for c in tree if isinstance(c, Tree)])) - - 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 7cdfaceebe916c91acdf8de3f9506989bc70ad65 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 14 Oct 2009 23:41:48 +0200 Subject: Removed plenty of mocked tree tests as they cannot work anymore with persistent commands that require stdin AND binary data - not even an adapter would help here. These tests will have to be replaced. test_commit: Improved efficiency of traversal test --- test/git/test_commit.py | 6 ++- test/git/test_tree.py | 100 ------------------------------------------------ 2 files changed, 4 insertions(+), 102 deletions(-) (limited to 'test/git') diff --git a/test/git/test_commit.py b/test/git/test_commit.py index c050fd11..1966d198 100644 --- a/test/git/test_commit.py +++ b/test/git/test_commit.py @@ -233,14 +233,16 @@ class TestCommit(object): def test_iteration(self): root = self.repo.tree() head = self.repo.active_branch + head_commit = self.repo.active_branch.object num_objs = 0 # find the first commit containing the given path - always do a full # iteration ( restricted to the path in question ), but in fact it should # return quite a lot of commits, we just take one and hence abort the operation + for obj in root.traverse(): num_objs += 1 - commit = Commit.iter_items( self.repo, head, obj.path ).next() - assert obj in commit.tree.traverse() + del( head_commit.tree ) # force it to clear the cache, just to make it harder + assert obj in head_commit.tree.traverse() # END for each object diff --git a/test/git/test_tree.py b/test/git/test_tree.py index 0104a16b..dafb6f3f 100644 --- a/test/git/test_tree.py +++ b/test/git/test_tree.py @@ -12,36 +12,7 @@ class TestTree(TestCase): def setUp(self): self.repo = Repo(GIT_REPO) - @patch_object(Git, '_call_process') - def test_contents_should_cache(self, git): - git.return_value = fixture('ls_tree_a') + fixture('ls_tree_b') - tree = self.repo.tree(Head(self.repo,'master')) - - child = tree['grit'] - len(child) - len(child) - - assert_true(git.called) - assert_equal(2, git.call_count) - assert_equal(git.call_args, (('ls_tree', '34868e6e7384cb5ee51c543a8187fdff2675b5a7'), {})) - - @raises(TypeError) - def test__from_string_invalid_type_should_raise(self): - Tree._from_string(None, "040000 bogus 650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44 test") - - @patch_object(Blob, 'size') - @patch_object(Git, '_call_process') - def test_slash(self, git, blob): - git.return_value = fixture('ls_tree_a') - blob.return_value = 1 - - tree = self.repo.tree(Head(self.repo,'master')) - - assert_equal('aa06ba24b4e3f463b3c4a85469d0fb9e5b421cf8', (tree/'lib').id) - assert_equal('8b1e02c0fb554eed2ce2ef737a68bb369d7527df', (tree/'README.txt').id) - - assert_true(git.called) def test_traverse(self): root = self.repo.tree() @@ -68,77 +39,6 @@ class TestTree(TestCase): assert len(set(trees)|set(root.trees)) == len(trees) assert len(set(b for b in root if isinstance(b, Blob)) | set(root.blobs)) == len( root.blobs ) - @patch_object(Blob, 'size') - @patch_object(Git, '_call_process') - def test_slash_with_zero_length_file(self, git, blob): - git.return_value = fixture('ls_tree_a') - blob.return_value = 0 - - tree = self.repo.tree(Head(self.repo,'master')) - - assert_not_none(tree/'README.txt') - assert_equal('8b1e02c0fb554eed2ce2ef737a68bb369d7527df', (tree/'README.txt').id) - - assert_true(git.called) - - @patch_object(Git, '_call_process') - def test_slash_with_commits(self, git): - git.return_value = fixture('ls_tree_commit') - - tree = self.repo.tree(Head(self.repo,'master')) - - self.failUnlessRaises(KeyError, tree.__div__, 'bar') - assert_equal('2afb47bcedf21663580d5e6d2f406f08f3f65f19', (tree/'foo').id) - assert_equal('f623ee576a09ca491c4a27e48c0dfe04be5f4a2e', (tree/'baz').id) - - assert_true(git.called) - - @patch_object(Blob, 'size') - @patch_object(Git, '_call_process') - def test_dict(self, git, blob): - git.return_value = fixture('ls_tree_a') - blob.return_value = 1 - - tree = self.repo.tree(Head(self.repo,'master')) - - assert_equal('aa06ba24b4e3f463b3c4a85469d0fb9e5b421cf8', tree['lib'].id) - assert_equal('8b1e02c0fb554eed2ce2ef737a68bb369d7527df', tree['README.txt'].id) - - assert_true(git.called) - - @patch_object(Blob, 'size') - @patch_object(Git, '_call_process') - def test_dict_with_zero_length_file(self, git, blob): - git.return_value = fixture('ls_tree_a') - blob.return_value = 0 - - tree = self.repo.tree(Head(self.repo,'master')) - - assert_not_none(tree['README.txt']) - assert_equal('8b1e02c0fb554eed2ce2ef737a68bb369d7527df', tree['README.txt'].id) - - assert_true(git.called) - - @patch_object(Git, '_call_process') - def test_dict_with_commits(self, git): - git.return_value = fixture('ls_tree_commit') - - tree = self.repo.tree(Head(self.repo,'master')) - - self.failUnlessRaises(KeyError, tree.__getitem__, 'bar') - assert_equal('2afb47bcedf21663580d5e6d2f406f08f3f65f19', tree['foo'].id) - assert_equal('f623ee576a09ca491c4a27e48c0dfe04be5f4a2e', tree['baz'].id) - - assert_true(git.called) - - @patch_object(Git, '_call_process') - @raises(KeyError) - def test_dict_with_non_existant_file(self, git): - git.return_value = fixture('ls_tree_commit') - - tree = self.repo.tree(Head(self.repo,'master')) - tree['bar'] - def test_repr(self): tree = Tree(self.repo, id='abc') assert_equal('', repr(tree)) -- cgit v1.2.3 From 1a4bfd979e5d4ea0d0457e552202eb2effc36cac Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 15 Oct 2009 00:06:08 +0200 Subject: test_performance: module containing benchmarks to get an idea of the achieved throughput repo.commits: max_count is None by default moved benchmark-like test from test_commit to test_performance --- test/git/test_commit.py | 16 ---------------- test/git/test_performance.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 test/git/test_performance.py (limited to 'test/git') diff --git a/test/git/test_commit.py b/test/git/test_commit.py index 1966d198..a95fb675 100644 --- a/test/git/test_commit.py +++ b/test/git/test_commit.py @@ -230,19 +230,3 @@ class TestCommit(object): assert_equal(commit1, commit2) assert_not_equal(commit2, commit3) - def test_iteration(self): - root = self.repo.tree() - head = self.repo.active_branch - head_commit = self.repo.active_branch.object - num_objs = 0 - - # find the first commit containing the given path - always do a full - # iteration ( restricted to the path in question ), but in fact it should - # return quite a lot of commits, we just take one and hence abort the operation - - for obj in root.traverse(): - num_objs += 1 - del( head_commit.tree ) # force it to clear the cache, just to make it harder - assert obj in head_commit.tree.traverse() - # END for each object - diff --git a/test/git/test_performance.py b/test/git/test_performance.py new file mode 100644 index 00000000..96f13a2e --- /dev/null +++ b/test/git/test_performance.py @@ -0,0 +1,38 @@ +# test_performance.py +# Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors +# +# This module is part of GitPython and is released under +# the BSD License: http://www.opensource.org/licenses/bsd-license.php + +from test.testlib import * +from git import * +from time import time + +class TestPerformance(object): + def setup(self): + self.repo = Repo(GIT_REPO) + + def test_iteration(self): + num_objs = 0 + num_commits = 0 + + # find the first commit containing the given path - always do a full + # iteration ( restricted to the path in question ), but in fact it should + # return quite a lot of commits, we just take one and hence abort the operation + + st = time() + for c in self.repo.commits(): + num_commits += 1 + c.author + c.authored_date + c.committer + c.committed_date + c.message + for obj in c.tree.traverse(): + obj.size + num_objs += 1 + # END for each object + # END for each commit + elapsed_time = time() - st + print "Traversed %i Trees and a total of %i unchached objects in %s [s] ( %f objs/s )" % (num_commits, num_objs, elapsed_time, num_objs/elapsed_time) + -- cgit v1.2.3