summaryrefslogtreecommitdiff
path: root/test/git
diff options
context:
space:
mode:
Diffstat (limited to 'test/git')
-rw-r--r--test/git/test_actor.py28
-rw-r--r--test/git/test_base.py78
-rw-r--r--test/git/test_blob.py159
-rw-r--r--test/git/test_commit.py453
-rw-r--r--test/git/test_diff.py30
-rw-r--r--test/git/test_git.py94
-rw-r--r--test/git/test_head.py32
-rw-r--r--test/git/test_repo.py409
-rw-r--r--test/git/test_stats.py34
-rw-r--r--test/git/test_tag.py45
-rw-r--r--test/git/test_tree.py236
-rw-r--r--test/git/test_utils.py18
12 files changed, 839 insertions, 777 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_base.py b/test/git/test_base.py
new file mode 100644
index 00000000..8f522cec
--- /dev/null
+++ b/test/git/test_base.py
@@ -0,0 +1,78 @@
+# 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 *
+import git.base as base
+from itertools import chain
+
+class TestBase(object):
+
+ type_tuples = ( ("blob", "8741fc1d09d61f02ffd8cded15ff603eff1ec070"),
+ ("tree", "3a6a5e3eeed3723c09f1ef0399f81ed6b8d82e79"),
+ ("commit", "4251bd59fb8e11e40c40548cba38180a9536118c"),
+ ("tag", "e56a60e8e9cd333cfba0140a77cd12b0d9398f10") )
+
+ def setup(self):
+ self.repo = Repo(GIT_REPO)
+
+ 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)
+
+ 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
+
+ # 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
+ 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:
+ 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_blob.py b/test/git/test_blob.py
index 8741fc1d..94d3a33b 100644
--- a/test/git/test_blob.py
+++ b/test/git/test_blob.py
@@ -9,89 +9,90 @@ 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')
+ 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', 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_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','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
-
+ @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..71dad562 100644
--- a/test/git/test_commit.py
+++ b/test/git/test_commit.py
@@ -8,241 +8,236 @@ 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_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))
+
+ 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)
-
- 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')
-
- diffs = Commit.diff(self.repo, 'rename')
-
- assert_equal(1, len(diffs))
-
- 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}))
-
- @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')
-
- assert_equal(3, len(diffs))
-
- 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')
-
- diffs = Commit.diff(self.repo, '59ddc32', ['lib'])
-
- 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}))
-
- @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'])
-
- 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}))
-
- @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
-
- 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)
-
- 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
-
- 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'}))
-
- @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)
+ 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}))
+
+ @patch_object(Git, '_call_process')
+ def test_diff_with_rename(self, git):
+ git.return_value = fixture('diff_rename')
+
+ diffs = Commit.diff(self.repo, 'rename')
+
+ assert_equal(1, len(diffs))
+
+ 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}))
+
+ @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')
+
+ assert_equal(3, len(diffs))
+
+ 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')
+
+ diffs = Commit.diff(self.repo, '59ddc32', ['lib'])
+
+ 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}))
+
+ @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'])
+
+ 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}))
+
+ @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
+
+ 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)
+
+ 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',
+ '038af8c329ef7c1bae4568b98bd5c58510465493',
+ '91169e1f5fa4de2eaea3f176461f5dc784796769',
+ ), {'full_index': True}))
+
+ 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)
+
+ 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:
+ 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):
+ 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'}))
+
+ 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(1, len(diffs))
+ assert_equal(None, diffs[0].a_blob)
+ assert_equal(None, diffs[0].b_blob)
+ assert_mode_644(diffs[0].a_mode)
+ assert_mode_755(diffs[0].b_mode)
+
+ def test_stats(self):
+ commit = Commit(self.repo, id='33ebe7acec14b25c5f84f35a664803fcab2f7781')
+ stats = commit.stats
+
+ 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):
+ """
+ '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..b8380838 100644
--- a/test/git/test_head.py
+++ b/test/git/test_head.py
@@ -8,25 +8,19 @@ 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)'}))
+ 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):
- 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)
diff --git a/test/git/test_repo.py b/test/git/test_repo.py
index a9d3beaf..421b8256 100644
--- a/test/git/test_repo.py
+++ b/test/git/test_repo.py
@@ -10,255 +10,250 @@ 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')
+ 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):
+ git.return_value = fixture('rev_list')
- head = self.repo.heads[0]
- assert_equal('master', head.name)
- assert_equal('634396b2f541a9f2d58b00be1a07f0c358b999b3', head.commit.id)
+ commits = self.repo.commits('master', max_count=10)
- assert_true(git.called)
- assert_equal(git.call_args, (('for_each_ref', 'refs/heads'), {'sort': 'committerdate', 'format': '%(refname)%00%(objectname)'}))
+ 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)
- @patch_object(Git, '_call_process')
- def test_commits(self, git):
- git.return_value = fixture('rev_list')
+ c = commits[1]
+ assert_equal(tuple(), c.parents)
+
+ 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}))
+
+ @patch_object(Git, '_call_process')
+ def test_commit_count(self, git):
+ git.return_value = fixture('rev_list_count')
- commits = self.repo.commits('master', max_count=10)
+ assert_equal(655, self.repo.commit_count('master'))
- 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)
+ assert_true(git.called)
+ assert_equal(git.call_args, (('rev_list', 'master', '--', ''), {}))
- c = commits[1]
- assert_equal([], c.parents)
+ @patch_object(Git, '_call_process')
+ def test_commit(self, git):
+ git.return_value = fixture('rev_list_single')
- c = commits[2]
- assert_equal(["6e64c55896aabb9a7d8e9f8f296f426d21a78c2c", "7f874954efb9ba35210445be456c74e037ba6af2"], map(lambda p: p.id, c.parents))
- assert_equal("Merge branch 'site'", c.summary)
+ commit = self.repo.commit('4c8124ffcf4039d292442eeccabdeca5af5c5017')
- assert_true(git.called)
- assert_equal(git.call_args, (('rev_list', 'master', '--', ''), {'skip': 0, 'pretty': 'raw', 'max_count': 10}))
+ assert_equal("4c8124ffcf4039d292442eeccabdeca5af5c5017", commit.id)
- @patch_object(Git, '_call_process')
- def test_commit_count(self, git):
- git.return_value = fixture('rev_list_count')
+ assert_true(git.called)
+ assert_equal(git.call_args, (('rev_list', '4c8124ffcf4039d292442eeccabdeca5af5c5017', '--', ''), {'pretty': 'raw', 'max_count': 1}))
- assert_equal(655, self.repo.commit_count('master'))
+ @patch_object(Git, '_call_process')
+ def test_tree(self, git):
+ git.return_value = fixture('ls_tree_a')
- assert_true(git.called)
- assert_equal(git.call_args, (('rev_list', 'master', '--', ''), {}))
+ tree = self.repo.tree('master')
- @patch_object(Git, '_call_process')
- def test_commit(self, git):
- git.return_value = fixture('rev_list_single')
+ 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)]))
- commit = self.repo.commit('4c8124ffcf4039d292442eeccabdeca5af5c5017')
+ assert_true(git.called)
+ assert_equal(git.call_args, (('ls_tree', 'master'), {}))
- assert_equal("4c8124ffcf4039d292442eeccabdeca5af5c5017", commit.id)
+ @patch_object(Git, '_call_process')
+ def test_blob(self, git):
+ git.return_value = fixture('cat_file_blob')
- assert_true(git.called)
- assert_equal(git.call_args, (('rev_list', '4c8124ffcf4039d292442eeccabdeca5af5c5017', '--', ''), {'pretty': 'raw', 'max_count': 1}))
+ blob = self.repo.blob("abc")
+ assert_equal("Hello world", blob.data)
- @patch_object(Git, '_call_process')
- def test_tree(self, git):
- git.return_value = fixture('ls_tree_a')
+ assert_true(git.called)
+ assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True, 'with_raw_output': True}))
- tree = self.repo.tree('master')
+ @patch_object(Repo, '__init__')
+ @patch_object(Git, '_call_process')
+ def test_init_bare(self, git, repo):
+ git.return_value = True
+ repo.return_value = None
- 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)]))
+ Repo.init_bare("repos/foo/bar.git")
- assert_true(git.called)
- assert_equal(git.call_args, (('ls_tree', 'master'), {}))
+ 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(Git, '_call_process')
- def test_blob(self, git):
- git.return_value = fixture('cat_file_blob')
+ @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
- blob = self.repo.blob("abc")
- assert_equal("Hello world", blob.data)
+ Repo.init_bare("repos/foo/bar.git", **{'template': "/baz/sweet"})
- 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, (('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_init_bare(self, git, repo):
- git.return_value = True
- 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
- Repo.init_bare("repos/foo/bar.git")
+ self.repo.fork_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)
+ 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_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_fork_bare_with_options(self, git, repo):
+ git.return_value = None
+ repo.return_value = None
- Repo.init_bare("repos/foo/bar.git", **{'template': "/baz/sweet"})
+ self.repo.fork_bare("repos/foo/bar.git", **{'template': '/awesome'})
- 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)
+ 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(Repo, '__init__')
- @patch_object(Git, '_call_process')
- def test_fork_bare(self, git, repo):
- git.return_value = None
- repo.return_value = None
+ @patch_object(Git, '_call_process')
+ def test_diff(self, git):
+ self.repo.diff('master^', 'master')
- self.repo.fork_bare("repos/foo/bar.git")
+ assert_true(git.called)
+ assert_equal(git.call_args, (('diff', 'master^', 'master', '--'), {}))
- 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)
+ self.repo.diff('master^', 'master', 'foo/bar')
- @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
+ assert_true(git.called)
+ assert_equal(git.call_args, (('diff', 'master^', 'master', '--', 'foo/bar'), {}))
- self.repo.fork_bare("repos/foo/bar.git", **{'template': '/awesome'})
+ self.repo.diff('master^', 'master', 'foo/bar', 'foo/baz')
- 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)
+ assert_equal(git.call_args, (('diff', 'master^', 'master', '--', 'foo/bar', 'foo/baz'), {}))
- @patch_object(Git, '_call_process')
- def test_diff(self, git):
- self.repo.diff('master^', 'master')
+ @patch_object(Git, '_call_process')
+ def test_diff_with_parents(self, git):
+ git.return_value = fixture('diff_p')
- assert_true(git.called)
- assert_equal(git.call_args, (('diff', 'master^', 'master', '--'), {}))
+ diffs = self.repo.commit_diff('master')
+ assert_equal(15, len(diffs))
+ assert_true(git.called)
- self.repo.diff('master^', 'master', 'foo/bar')
+ def test_archive_tar(self):
+ assert self.repo.archive_tar()
- assert_true(git.called)
- assert_equal(git.call_args, (('diff', 'master^', 'master', '--', 'foo/bar'), {}))
+ def test_archive_tar_gz(self):
+ assert self.repo.archive_tar_gz()
- self.repo.diff('master^', 'master', 'foo/bar', 'foo/baz')
+ @patch('git.utils.touch')
+ def test_enable_daemon_serve(self, touch):
+ self.repo.daemon_serve = False
+ assert_false(self.repo.daemon_serve)
- 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')
-
- 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_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)
-
- 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_tag.py b/test/git/test_tag.py
index 732bbd45..fe3f78cc 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 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('<git.Tag "%s">' % tag.name, repr(tag))
-
- assert_true(git.called)
- assert_equal(git.call_args, (('for_each_ref', 'refs/tags'), {'sort': 'committerdate', 'format': '%(refname)%00%(objectname)'}))
diff --git a/test/git/test_tree.py b/test/git/test_tree.py
index 3946a33c..50d34006 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(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_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_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")
+
+ @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'))