diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-18 14:25:14 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-18 14:25:14 +0200 |
commit | 225999e9442c746333a8baa17a6dbf7341c135ca (patch) | |
tree | 82e4bdf8a59fae869bae41aa6b9b048fee2d3e09 /test/git/test_diff.py | |
parent | 919164df96d9f956c8be712f33a9a037b097745b (diff) | |
parent | 9acc7806d6bdb306a929c460437d3d03e5e48dcd (diff) | |
download | gitpython-225999e9442c746333a8baa17a6dbf7341c135ca.tar.gz |
Merge branch 'diffing' into improvements
* diffing:
DiffIndex implemented including test
diff: implemented raw diff parsing which appears to be able to handle possible input types, DiffIndex still requires implementation though
resolved cyclic inclusion issue by moving the Diffable interface into the diff module, which probably is the right thing to do anyway
repo: fixed untracked files function which used git-commit before, it can open vim to get a message though which makes the program appear to freeze - using git-status now
implemented diff tests, but will have to move the diff module as it needs to create objects, whose import would create a dependency cycle
Removed a few diff-related test cases that fail now as the respective method is missing - these tests have to be redone in test-diff module accordingly
added Diffable interface to objects.base, its used by Commit and Tree objects.
Fixed object bug that would cause object ids not to be resolved to sha's as this was assumed - now there is a test for it as well
Diffstat (limited to 'test/git/test_diff.py')
-rw-r--r-- | test/git/test_diff.py | 58 |
1 files changed, 52 insertions, 6 deletions
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 + |