summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-10-11 21:17:59 +0200
committerSebastian Thiel <byronimo@gmail.com>2009-10-11 21:17:59 +0200
commit708b8dda8e7b87841a5f39c60b799c514e75a9c7 (patch)
tree0726d95c0ad6270278c6695381522e8a5f8a2b76
parentccde80b7a3037a004a7807a6b79916ce2a1e9729 (diff)
downloadgitpython-708b8dda8e7b87841a5f39c60b799c514e75a9c7.tar.gz
commit: fixed failing commit tests as the mocked git command would always return the same thing which does not work anymore - re-implemented it in a more dynamic manner, but in the end tests will have to be revised anyway
Added slots to Diff and Stats type respectively
-rw-r--r--lib/git/blob.py2
-rw-r--r--lib/git/commit.py15
-rw-r--r--lib/git/diff.py4
-rw-r--r--lib/git/stats.py7
-rw-r--r--test/git/test_commit.py82
-rw-r--r--test/git/test_repo.py15
6 files changed, 57 insertions, 68 deletions
diff --git a/lib/git/blob.py b/lib/git/blob.py
index b0e47a3c..1fafb128 100644
--- a/lib/git/blob.py
+++ b/lib/git/blob.py
@@ -57,7 +57,7 @@ class Blob(base.IndexObject):
blames = []
info = None
- for line in data.splitlines():
+ for line in data.splitlines(False):
parts = cls.re_whitespace.split(line, 1)
firstpart = parts[0]
if cls.re_hexsha_only.search(firstpart):
diff --git a/lib/git/commit.py b/lib/git/commit.py
index 5d494621..9bf753e0 100644
--- a/lib/git/commit.py
+++ b/lib/git/commit.py
@@ -162,8 +162,7 @@ class Commit(base.Object):
Returns
git.Commit[]
"""
- lines = [l for l in text.splitlines() if l.strip('\r\n')]
-
+ lines =text.splitlines(False)
commits = []
while lines:
@@ -173,18 +172,22 @@ class Commit(base.Object):
parents = []
while lines and lines[0].startswith('parent'):
parents.append(lines.pop(0).split()[-1])
+ # END while there are parent lines
author, authored_date = cls._actor(lines.pop(0))
committer, committed_date = cls._actor(lines.pop(0))
-
+
+ # free line
+ lines.pop(0)
+
messages = []
- while lines and lines[0].startswith(' '):
+ while lines and not lines[0].startswith('commit'):
messages.append(lines.pop(0).strip())
-
+ # END while there are message lines
message = '\n'.join(messages)
commits.append(Commit(repo, id=id, parents=parents, tree=tree, author=author, authored_date=authored_date,
committer=committer, committed_date=committed_date, message=message))
-
+ # END while lines
return commits
@classmethod
diff --git a/lib/git/diff.py b/lib/git/diff.py
index ef58cb0e..7200b7e3 100644
--- a/lib/git/diff.py
+++ b/lib/git/diff.py
@@ -45,12 +45,12 @@ class Diff(object):
\.\.(?P<b_blob_id>[0-9A-Fa-f]+)[ ]?(?P<b_mode>.+)?(?:\n|$))?
""", re.VERBOSE | re.MULTILINE)
re_is_null_hexsha = re.compile( r'^0{40}$' )
+ __slots__ = ("a_blob", "b_blob", "a_mode", "b_mode", "new_file", "deleted_file",
+ "rename_from", "rename_to", "renamed", "diff")
def __init__(self, repo, a_path, b_path, a_blob_id, b_blob_id, a_mode,
b_mode, new_file, deleted_file, rename_from,
rename_to, diff):
- self.repo = repo
-
if not a_blob_id or self.re_is_null_hexsha.search(a_blob_id):
self.a_blob = None
else:
diff --git a/lib/git/stats.py b/lib/git/stats.py
index a39d1dab..19b1591f 100644
--- a/lib/git/stats.py
+++ b/lib/git/stats.py
@@ -31,8 +31,9 @@ class Stats(object):
files = number of changed files as int
"""
- def __init__(self, repo, total, files):
- self.repo = repo
+ __slots__ = ("total", "files")
+
+ def __init__(self, total, files):
self.total = total
self.files = files
@@ -56,4 +57,4 @@ class Stats(object):
hsh['files'][filename.strip()] = {'insertions': insertions,
'deletions': deletions,
'lines': insertions + deletions}
- return Stats(repo, hsh['total'], hsh['files'])
+ return Stats(hsh['total'], hsh['files'])
diff --git a/test/git/test_commit.py b/test/git/test_commit.py
index 341d72e2..79768c3f 100644
--- a/test/git/test_commit.py
+++ b/test/git/test_commit.py
@@ -135,30 +135,21 @@ class TestCommit(object):
'91169e1f5fa4de2eaea3f176461f5dc784796769',
), {'full_index': True}))
- @patch_object(Git, '_call_process')
- def test_diffs_on_initial_import(self, git):
- git.return_value = fixture('diff_i')
-
- commit = Commit(self.repo, id='634396b2f541a9f2d58b00be1a07f0c358b999b3')
- diffs = commit.diffs
-
- assert_equal(10, len(diffs))
-
- assert_equal('History.txt', diffs[0].b_blob.path)
- assert_equal(None, diffs[0].a_blob)
- assert_equal('100644', diffs[0].b_blob.mode)
- assert_equal('81d2c27608b352814cbe979a6acd678d30219678', diffs[0].b_blob.id)
- assert_equal(True, diffs[0].new_file)
- assert_equal(False, diffs[0].deleted_file)
- assert_equal("--- /dev/null\n+++ b/History.txt\n@@ -0,0 +1,5 @@\n+== 1.0.0 / 2007-10-09\n+\n+* 1 major enhancement\n+ * Birthday!\n+", diffs[0].diff)
-
- assert_equal('lib/grit.rb', diffs[5].b_blob.path)
- assert_equal(None, diffs[5].a_blob)
- assert_equal('32cec87d1e78946a827ddf6a8776be4d81dcf1d1', diffs[5].b_blob.id)
- assert_equal(True, diffs[5].new_file)
-
- assert_true(git.called)
- assert_equal(git.call_args, (('show', '634396b2f541a9f2d58b00be1a07f0c358b999b3', '-M'), {'full_index': True, 'pretty': 'raw'}))
+ def test_diffs_on_initial_import(self):
+ commit = Commit(self.repo, '33ebe7acec14b25c5f84f35a664803fcab2f7781')
+
+ for diff in commit.diffs:
+ assert isinstance(diff, Diff)
+ assert isinstance(diff.a_blob, Blob) or isinstance(diff.b_blob, Blob)
+ assert isinstance(diff.a_mode, int) and isinstance(diff.b_mode, int)
+ assert diff.diff
+ if diff.renamed:
+ assert diff.rename_from and diff.rename_to and diff.rename_from != diff.rename_to
+ if diff.a_blob is None:
+ assert diff.new_file and isinstance(diff.new_file, bool)
+ if diff.b_blob is None:
+ assert diff.deleted_file and isinstance(diff.deleted_file, bool)
+ # END for each diff in initial import commit
@patch_object(Git, '_call_process')
def test_diffs_on_initial_import_with_empty_commit(self, git):
@@ -172,37 +163,36 @@ class TestCommit(object):
assert_true(git.called)
assert_equal(git.call_args, (('show', '634396b2f541a9f2d58b00be1a07f0c358b999b3', '-M'), {'full_index': True, 'pretty': 'raw'}))
- @patch_object(Git, '_call_process')
- def test_diffs_with_mode_only_change(self, git):
- git.return_value = fixture('diff_mode_only')
-
- commit = Commit(self.repo, id='91169e1f5fa4de2eaea3f176461f5dc784796769')
+ def test_diffs_with_mode_only_change(self):
+ commit = Commit(self.repo, id='ccde80b7a3037a004a7807a6b79916ce2a1e9729')
diffs = commit.diffs
# in case of mode-only changes, there is no blob
- assert_equal(23, len(diffs))
+ assert_equal(1, len(diffs))
assert_equal(None, diffs[0].a_blob)
assert_equal(None, diffs[0].b_blob)
assert_equal('100644', diffs[0].a_mode)
assert_equal('100755', diffs[0].b_mode)
- assert_true(git.called)
- assert_equal(git.call_args, (('show', '91169e1f5fa4de2eaea3f176461f5dc784796769', '-M'), {'full_index': True, 'pretty': 'raw'}))
-
- @patch_object(Git, '_call_process')
- def test_stats(self, git):
- git.return_value = fixture('diff_tree_numstat_root')
-
- commit = Commit(self.repo, id='634396b2f541a9f2d58b00be1a07f0c358b999b3')
+ def test_stats(self):
+ commit = Commit(self.repo, id='33ebe7acec14b25c5f84f35a664803fcab2f7781')
stats = commit.stats
-
- keys = stats.files.keys()
- keys.sort()
- assert_equal(["a.txt", "b.txt"], keys)
-
- assert_true(git.called)
- assert_equal(git.call_args, (('diff_tree', '634396b2f541a9f2d58b00be1a07f0c358b999b3', '--'), {'numstat': True, 'root': True }))
-
+
+ def check_entries(d):
+ assert isinstance(d, dict)
+ for key in ("insertions", "deletions", "lines"):
+ assert key in d
+ # END assertion helper
+ assert stats.files
+ assert stats.total
+
+ check_entries(stats.total)
+ assert "files" in stats.total
+
+ for filepath, d in stats.files.items():
+ check_entries(d)
+ # END for each stated file
+
@patch_object(Git, '_call_process')
def test_rev_list_bisect_all(self, git):
"""
diff --git a/test/git/test_repo.py b/test/git/test_repo.py
index e232b065..d4316981 100644
--- a/test/git/test_repo.py
+++ b/test/git/test_repo.py
@@ -33,16 +33,11 @@ class TestRepo(object):
for head in self.repo.heads:
assert_equal(Head, head.__class__)
- @patch_object(Git, '_call_process')
- def test_heads_should_populate_head_data(self, git):
- git.return_value = fixture('for_each_ref')
-
- head = self.repo.heads[0]
- assert_equal('master', head.name)
- assert_equal('634396b2f541a9f2d58b00be1a07f0c358b999b3', head.commit.id)
-
- assert_true(git.called)
- assert_equal(git.call_args, (('for_each_ref', 'refs/heads'), {'sort': 'committerdate', 'format': '%(refname)%00%(objectname)'}))
+ def test_heads_should_populate_head_data(self):
+ for head in self.repo.heads:
+ assert head.name
+ assert isinstance(head.commit,Commit)
+ # END for each head
@patch_object(Git, '_call_process')
def test_commits(self, git):