summaryrefslogtreecommitdiff
path: root/test/git
diff options
context:
space:
mode:
Diffstat (limited to 'test/git')
-rw-r--r--test/git/test_base.py3
-rw-r--r--test/git/test_commit.py150
-rw-r--r--test/git/test_diff.py58
-rw-r--r--test/git/test_repo.py39
4 files changed, 59 insertions, 191 deletions
diff --git a/test/git/test_base.py b/test/git/test_base.py
index 04222e2e..71576048 100644
--- a/test/git/test_base.py
+++ b/test/git/test_base.py
@@ -90,3 +90,6 @@ class TestBase(object):
assert_raises( ValueError, get_object_type_by_name, "doesntexist" )
+ def test_object_resolution(self):
+ # objects must be resolved to shas so they compare equal
+ assert self.repo.head.object == self.repo.active_branch.object
diff --git a/test/git/test_commit.py b/test/git/test_commit.py
index 4e698ed0..c8bca564 100644
--- a/test/git/test_commit.py
+++ b/test/git/test_commit.py
@@ -20,156 +20,6 @@ class TestCommit(object):
assert_equal("byronimo@gmail.com", commit.author.email)
- @patch_object(Git, '_call_process')
- def test_diff(self, git):
- git.return_value = fixture('diff_p')
-
- diffs = Commit.diff(self.repo, 'master')
-
- assert_equal(15, len(diffs))
-
- diff = diffs[0]
- assert_equal('.gitignore', diff.a_blob.path)
- assert_equal('.gitignore', diff.b_blob.path)
- assert_equal('4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diff.a_blob.id)
- assert_equal('2dd02534615434d88c51307beb0f0092f21fd103', diff.b_blob.id)
-
- assert_mode_644(diff.b_blob.mode)
-
- assert_equal(False, diff.new_file)
- assert_equal(False, diff.deleted_file)
- assert_equal("--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg", diff.diff)
-
- 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
-
- def test_diffs_on_initial_import_without_parents(self):
- commit = Commit(self.repo, id='33ebe7acec14b25c5f84f35a664803fcab2f7781')
- diffs = commit.diffs
- assert diffs
-
- 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
diff --git a/test/git/test_diff.py b/test/git/test_diff.py
index b2339455..deae7cfc 100644
--- a/test/git/test_diff.py
+++ b/test/git/test_diff.py
@@ -7,19 +7,19 @@
from test.testlib import *
from git import *
-class TestDiff(object):
- def setup(self):
+class TestDiff(TestCase):
+ 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)
+ output = ListProcessAdapter(fixture('diff_new_mode'))
+ diffs = Diff._index_from_patch_format(self.repo, output.stdout)
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)
+ output = ListProcessAdapter(fixture('diff_rename'))
+ diffs = Diff._index_from_patch_format(self.repo, output.stdout)
assert_equal(1, len(diffs))
@@ -28,3 +28,49 @@ class TestDiff(object):
assert_equal(diff.rename_from, 'AUTHORS')
assert_equal(diff.rename_to, 'CONTRIBUTORS')
+ def test_diff_patch_format(self):
+ # test all of the 'old' format diffs for completness - it should at least
+ # be able to deal with it
+ fixtures = ("diff_2", "diff_2f", "diff_f", "diff_i", "diff_mode_only",
+ "diff_new_mode", "diff_numstat", "diff_p", "diff_rename",
+ "diff_tree_numstat_root" )
+
+ for fixture_name in fixtures:
+ diff_proc = ListProcessAdapter(fixture(fixture_name))
+ diffs = Diff._index_from_patch_format(self.repo, diff_proc.stdout)
+ # END for each fixture
+
+ def test_diff_interface(self):
+ # test a few variations of the main diff routine
+ assertion_map = dict()
+ for i, commit in enumerate(self.repo.iter_commits('0.1.6', max_count=10)):
+ diff_item = commit
+ if i%2 == 0:
+ diff_item = commit.tree
+ # END use tree every second item
+
+ for other in (None, commit.Index, commit.parents[0]):
+ for paths in (None, "CHANGES", ("CHANGES", "lib")):
+ for create_patch in range(2):
+ diff_index = diff_item.diff(other, paths, create_patch)
+ assert isinstance(diff_index, DiffIndex)
+
+ if diff_index:
+ for ct in DiffIndex.change_type:
+ key = 'ct_%s'%ct
+ assertion_map.setdefault(key, 0)
+ assertion_map[key] = assertion_map[key]+len(list(diff_index.iter_change_type(ct)))
+ # END for each changetype
+ # END diff index checking
+ # END for each patch option
+ # END for each path option
+ # END for each other side
+ # END for each commit
+
+ # assert we could always find at least one instance of the members we
+ # can iterate in the diff index - if not this indicates its not working correctly
+ # or our test does not span the whole range of possibilities
+ for key,value in assertion_map.items():
+ assert value, "Did not find diff for %s" % key
+ # END for each iteration type
+
diff --git a/test/git/test_repo.py b/test/git/test_repo.py
index 250974a5..87332067 100644
--- a/test/git/test_repo.py
+++ b/test/git/test_repo.py
@@ -43,7 +43,7 @@ class TestRepo(object):
git.return_value = ListProcessAdapter(fixture('rev_list'))
commits = list( self.repo.iter_commits('master', max_count=10) )
-
+
c = commits[0]
assert_equal('4c8124ffcf4039d292442eeccabdeca5af5c5017', c.id)
assert_equal(["634396b2f541a9f2d58b00be1a07f0c358b999b3"], [p.id for p in c.parents])
@@ -116,40 +116,6 @@ class TestRepo(object):
{ 'template': '/awesome'}))
assert_true(repo.called)
- @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', '--'), {}))
-
- self.repo.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')
-
- 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(self):
- args = ( tuple(), (self.repo.heads[-1],),(None,"hello") )
- for arg_list in args:
- ftmp = os.tmpfile()
- self.repo.archive(ftmp, *arg_list)
- ftmp.seek(0,2)
- assert ftmp.tell()
- # END for each arg-list
-
@patch('git.utils.touch')
def test_enable_daemon_serve(self, touch):
self.repo.daemon_serve = False
@@ -199,6 +165,9 @@ class TestRepo(object):
assert_equal(self.repo.active_branch.name, 'major-refactoring')
assert_equal(git.call_args, (('symbolic_ref', 'HEAD'), {}))
+ def test_head(self):
+ assert self.repo.head.object == self.repo.active_branch.object
+
@patch_object(Git, '_call_process')
def test_should_display_blame_information(self, git):
git.return_value = fixture('blame')