diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/git/test_actor.py | 28 | ||||
-rw-r--r-- | test/git/test_blob.py | 158 | ||||
-rw-r--r-- | test/git/test_commit.py | 394 | ||||
-rw-r--r-- | test/git/test_diff.py | 30 | ||||
-rw-r--r-- | test/git/test_git.py | 94 | ||||
-rw-r--r-- | test/git/test_head.py | 38 | ||||
-rw-r--r-- | test/git/test_repo.py | 402 | ||||
-rw-r--r-- | test/git/test_stats.py | 34 | ||||
-rw-r--r-- | test/git/test_tree.py | 234 | ||||
-rw-r--r-- | test/git/test_utils.py | 18 | ||||
-rw-r--r-- | test/testlib/__init__.py | 2 | ||||
-rw-r--r-- | test/testlib/asserts.py | 30 | ||||
-rw-r--r-- | test/testlib/helper.py | 8 |
13 files changed, 735 insertions, 735 deletions
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 <mtrier@example.com>") - 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 <mtrier@example.com>") + 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 <mtrier@example.com>") - assert_equal('<git.Actor "Michael Trier <mtrier@example.com>">', repr(a)) + def test_should_display_representation(self): + a = Actor.from_string("Michael Trier <mtrier@example.com>") + assert_equal('<git.Actor "Michael Trier <mtrier@example.com>">', repr(a)) - def test_str_should_alias_name(self): - a = Actor.from_string("Michael Trier <mtrier@example.com>") - 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 <mtrier@example.com>") + 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('<git.Blob "abc">', repr(blob)) + def test_should_return_appropriate_representation(self): + blob = Blob(self.repo, **{'id': 'abc'}) + assert_equal('<git.Blob "abc">', 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('<git.Commit "abc">', 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('<git.Commit "abc">', 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('<git.Head "%s">' % 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('<git.Head "%s">' % 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('<git.Repo "%s">' % 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('<git.Repo "%s">' % 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('<git.Tree "abc">', repr(tree)) + def test_repr(self): + tree = Tree(self.repo, id='abc') + assert_equal('<git.Tree "abc">', 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')) diff --git a/test/testlib/__init__.py b/test/testlib/__init__.py index 77512794..2133eb8c 100644 --- a/test/testlib/__init__.py +++ b/test/testlib/__init__.py @@ -10,4 +10,4 @@ from asserts import * from helper import * __all__ = [ name for name, obj in locals().items() - if not (name.startswith('_') or inspect.ismodule(obj)) ] + if not (name.startswith('_') or inspect.ismodule(obj)) ] diff --git a/test/testlib/asserts.py b/test/testlib/asserts.py index f66af122..8f2acdc9 100644 --- a/test/testlib/asserts.py +++ b/test/testlib/asserts.py @@ -10,29 +10,29 @@ from nose import tools from nose.tools import * __all__ = ['assert_instance_of', 'assert_not_instance_of', - 'assert_none', 'assert_not_none', - 'assert_match', 'assert_not_match'] + tools.__all__ + 'assert_none', 'assert_not_none', + 'assert_match', 'assert_not_match'] + tools.__all__ def assert_instance_of(expected, actual, msg=None): - """Verify that object is an instance of expected """ - assert isinstance(actual, expected), msg + """Verify that object is an instance of expected """ + assert isinstance(actual, expected), msg def assert_not_instance_of(expected, actual, msg=None): - """Verify that object is not an instance of expected """ - assert not isinstance(actual, expected, msg) - + """Verify that object is not an instance of expected """ + assert not isinstance(actual, expected, msg) + def assert_none(actual, msg=None): - """verify that item is None""" - assert_equal(None, actual, msg) + """verify that item is None""" + assert_equal(None, actual, msg) def assert_not_none(actual, msg=None): - """verify that item is None""" - assert_not_equal(None, actual, msg) + """verify that item is None""" + assert_not_equal(None, actual, msg) def assert_match(pattern, string, msg=None): - """verify that the pattern matches the string""" - assert_not_none(re.search(pattern, string), msg) + """verify that the pattern matches the string""" + assert_not_none(re.search(pattern, string), msg) def assert_not_match(pattern, string, msg=None): - """verify that the pattern does not match the string""" - assert_none(re.search(pattern, string), msg)
\ No newline at end of file + """verify that the pattern does not match the string""" + assert_none(re.search(pattern, string), msg)
\ No newline at end of file diff --git a/test/testlib/helper.py b/test/testlib/helper.py index ca262ee4..74f48447 100644 --- a/test/testlib/helper.py +++ b/test/testlib/helper.py @@ -9,11 +9,11 @@ import os GIT_REPO = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) def fixture_path(name): - test_dir = os.path.dirname(os.path.dirname(__file__)) - return os.path.join(test_dir, "fixtures", name) + test_dir = os.path.dirname(os.path.dirname(__file__)) + return os.path.join(test_dir, "fixtures", name) def fixture(name): - return open(fixture_path(name)).read() + return open(fixture_path(name)).read() def absolute_project_path(): - return os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) + return os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) |