From a5cf1bc1d3e38ab32a20707d66b08f1bb0beae91 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 17 Oct 2009 20:13:02 +0200 Subject: 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 --- test/git/test_diff.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'test/git/test_diff.py') diff --git a/test/git/test_diff.py b/test/git/test_diff.py index b2339455..ea83145d 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,5 @@ class TestDiff(object): assert_equal(diff.rename_from, 'AUTHORS') assert_equal(diff.rename_to, 'CONTRIBUTORS') + def test_diff_interface(self): + self.fail( "TODO: Test full diff interface on commits, trees, index, patch and non-patch" ) -- cgit v1.2.1 From 9946e0ce07c8d93a43bd7b8900ddf5d913fe3b03 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 18 Oct 2009 12:33:06 +0200 Subject: implemented diff tests, but will have to move the diff module as it needs to create objects, whose import would create a dependency cycle --- test/git/test_diff.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test/git/test_diff.py') diff --git a/test/git/test_diff.py b/test/git/test_diff.py index ea83145d..166ce310 100644 --- a/test/git/test_diff.py +++ b/test/git/test_diff.py @@ -28,5 +28,35 @@ class TestDiff(TestCase): 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 + 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.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 diff_index + # END for each patch option + # END for each path option + # END for each other side + # END for each commit + + self.fail( "TODO: Test full diff interface on commits, trees, index, patch and non-patch" ) -- cgit v1.2.1 From e063d101face690b8cf4132fa419c5ce3857ef44 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 18 Oct 2009 13:24:04 +0200 Subject: diff: implemented raw diff parsing which appears to be able to handle possible input types, DiffIndex still requires implementation though --- test/git/test_diff.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test/git/test_diff.py') diff --git a/test/git/test_diff.py b/test/git/test_diff.py index 166ce310..c9604faf 100644 --- a/test/git/test_diff.py +++ b/test/git/test_diff.py @@ -52,11 +52,12 @@ class TestDiff(TestCase): for paths in (None, "CHANGES", ("CHANGES", "lib")): for create_patch in range(2): diff_index = diff_item.diff(other, paths, create_patch) - assert diff_index + assert isinstance(diff_index, DiffIndex) + + # TODO: test diff index # END for each patch option # END for each path option # END for each other side # END for each commit - self.fail( "TODO: Test full diff interface on commits, trees, index, patch and non-patch" ) -- cgit v1.2.1 From 9acc7806d6bdb306a929c460437d3d03e5e48dcd Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 18 Oct 2009 14:24:30 +0200 Subject: DiffIndex implemented including test --- test/git/test_diff.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'test/git/test_diff.py') diff --git a/test/git/test_diff.py b/test/git/test_diff.py index c9604faf..deae7cfc 100644 --- a/test/git/test_diff.py +++ b/test/git/test_diff.py @@ -42,22 +42,35 @@ class TestDiff(TestCase): 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.parents[0]): + 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) - # TODO: test diff index + 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 - self.fail( "TODO: Test full diff interface on commits, trees, index, patch and non-patch" ) + # 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 + -- cgit v1.2.1 From a4fb3091a75005b047fbea72f812c53d27b15412 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 21 Oct 2009 17:04:24 +0200 Subject: diff: added test to be sure index-vs-working copy diffs are solved properly --- test/git/test_diff.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/git/test_diff.py') diff --git a/test/git/test_diff.py b/test/git/test_diff.py index deae7cfc..501d937d 100644 --- a/test/git/test_diff.py +++ b/test/git/test_diff.py @@ -74,3 +74,6 @@ class TestDiff(TestCase): assert value, "Did not find diff for %s" % key # END for each iteration type + def test_diff_index_working_tree(self): + self.fail("""Find a good way to diff an index against the working tree +which is not possible with the current interface""") -- cgit v1.2.1 From b197b2dbb527de9856e6e808339ab0ceaf0a512d Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 22 Oct 2009 16:20:24 +0200 Subject: Adjusted all remaining test suites to use the new TestBase class where appropriate --- test/git/test_diff.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'test/git/test_diff.py') diff --git a/test/git/test_diff.py b/test/git/test_diff.py index 501d937d..d7505987 100644 --- a/test/git/test_diff.py +++ b/test/git/test_diff.py @@ -7,19 +7,17 @@ from test.testlib import * from git import * -class TestDiff(TestCase): - def setUp(self): - self.repo = Repo(GIT_REPO) - +class TestDiff(TestBase): + def test_list_from_string_new_mode(self): output = ListProcessAdapter(fixture('diff_new_mode')) - diffs = Diff._index_from_patch_format(self.repo, output.stdout) + diffs = Diff._index_from_patch_format(self.rorepo, output.stdout) assert_equal(1, len(diffs)) assert_equal(10, len(diffs[0].diff.splitlines())) def test_diff_with_rename(self): output = ListProcessAdapter(fixture('diff_rename')) - diffs = Diff._index_from_patch_format(self.repo, output.stdout) + diffs = Diff._index_from_patch_format(self.rorepo, output.stdout) assert_equal(1, len(diffs)) @@ -37,13 +35,13 @@ class TestDiff(TestCase): for fixture_name in fixtures: diff_proc = ListProcessAdapter(fixture(fixture_name)) - diffs = Diff._index_from_patch_format(self.repo, diff_proc.stdout) + diffs = Diff._index_from_patch_format(self.rorepo, 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)): + for i, commit in enumerate(self.rorepo.iter_commits('0.1.6', max_count=10)): diff_item = commit if i%2 == 0: diff_item = commit.tree -- cgit v1.2.1 From ea33fe8b21d2b02f902b131aba0d14389f2f8715 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 22 Oct 2009 22:14:02 +0200 Subject: Index: Is now diffable and appears to properly implement diffing against other items as well as the working tree Diff.Diffable: added callback allowing superclasses to preprocess diff arguments Diff.Diff: added eq, ne and hash methods, string methods would be nice --- test/git/test_diff.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'test/git/test_diff.py') diff --git a/test/git/test_diff.py b/test/git/test_diff.py index d7505987..ead231e5 100644 --- a/test/git/test_diff.py +++ b/test/git/test_diff.py @@ -59,6 +59,14 @@ class TestDiff(TestBase): assertion_map.setdefault(key, 0) assertion_map[key] = assertion_map[key]+len(list(diff_index.iter_change_type(ct))) # END for each changetype + + # check entries + diff_set = set() + diff_set.add(diff_index[0]) + diff_set.add(diff_index[0]) + assert len(diff_set) == 1 + assert diff_index[0] == diff_index[0] + assert not (diff_index[0] != diff_index[0]) # END diff index checking # END for each patch option # END for each path option @@ -71,7 +79,4 @@ class TestDiff(TestBase): for key,value in assertion_map.items(): assert value, "Did not find diff for %s" % key # END for each iteration type - - def test_diff_index_working_tree(self): - self.fail("""Find a good way to diff an index against the working tree -which is not possible with the current interface""") + -- cgit v1.2.1 From 52bb0046c0bf0e50598c513e43b76d593f2cbbff Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 4 Nov 2009 16:26:03 +0100 Subject: added query for 'M' modified diffs to DiffIndex including test. The latter one was made faster by reducing the amount of permutations to the minimal value --- test/git/test_diff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/git/test_diff.py') diff --git a/test/git/test_diff.py b/test/git/test_diff.py index ead231e5..9335aced 100644 --- a/test/git/test_diff.py +++ b/test/git/test_diff.py @@ -41,7 +41,7 @@ class TestDiff(TestBase): def test_diff_interface(self): # test a few variations of the main diff routine assertion_map = dict() - for i, commit in enumerate(self.rorepo.iter_commits('0.1.6', max_count=10)): + for i, commit in enumerate(self.rorepo.iter_commits('0.1.6', max_count=2)): diff_item = commit if i%2 == 0: diff_item = commit.tree -- cgit v1.2.1