summaryrefslogtreecommitdiff
path: root/git/test/test_diff.py
diff options
context:
space:
mode:
Diffstat (limited to 'git/test/test_diff.py')
-rw-r--r--git/test/test_diff.py119
1 files changed, 65 insertions, 54 deletions
diff --git a/git/test/test_diff.py b/git/test/test_diff.py
index 9fdb26a2..d34d84e3 100644
--- a/git/test/test_diff.py
+++ b/git/test/test_diff.py
@@ -15,7 +15,7 @@ from git.test.lib import (
)
-from gitdb.test.lib import with_rw_directory
+from git.test.lib import with_rw_directory
from git import (
Repo,
@@ -24,10 +24,16 @@ from git import (
DiffIndex,
NULL_TREE,
)
+import ddt
+@ddt.ddt
class TestDiff(TestBase):
+ def tearDown(self):
+ import gc
+ gc.collect()
+
def _assert_diff_format(self, diffs):
# verify that the format of the diff is sane
for diff in diffs:
@@ -66,13 +72,14 @@ class TestDiff(TestBase):
self.failUnlessRaises(GitCommandError, r.git.cherry_pick, 'master')
# Now do the actual testing - this should just work
- assert len(r.index.diff(None)) == 2
+ self.assertEqual(len(r.index.diff(None)), 2)
- assert len(r.index.diff(None, create_patch=True)) == 0, "This should work, but doesn't right now ... it's OK"
+ self.assertEqual(len(r.index.diff(None, create_patch=True)), 0,
+ "This should work, but doesn't right now ... it's OK")
def test_list_from_string_new_mode(self):
output = StringProcessAdapter(fixture('diff_new_mode'))
- diffs = Diff._index_from_patch_format(self.rorepo, output.stdout)
+ diffs = Diff._index_from_patch_format(self.rorepo, output)
self._assert_diff_format(diffs)
assert_equal(1, len(diffs))
@@ -80,7 +87,7 @@ class TestDiff(TestBase):
def test_diff_with_rename(self):
output = StringProcessAdapter(fixture('diff_rename'))
- diffs = Diff._index_from_patch_format(self.rorepo, output.stdout)
+ diffs = Diff._index_from_patch_format(self.rorepo, output)
self._assert_diff_format(diffs)
assert_equal(1, len(diffs))
@@ -95,42 +102,46 @@ class TestDiff(TestBase):
assert isinstance(str(diff), str)
output = StringProcessAdapter(fixture('diff_rename_raw'))
- diffs = Diff._index_from_raw_format(self.rorepo, output.stdout)
- assert len(diffs) == 1
+ diffs = Diff._index_from_raw_format(self.rorepo, output)
+ self.assertEqual(len(diffs), 1)
diff = diffs[0]
- assert diff.renamed_file
- assert diff.renamed
- assert diff.rename_from == 'this'
- assert diff.rename_to == 'that'
- assert len(list(diffs.iter_change_type('R'))) == 1
+ self.assertIsNotNone(diff.renamed_file)
+ self.assertIsNotNone(diff.renamed)
+ self.assertEqual(diff.rename_from, 'this')
+ self.assertEqual(diff.rename_to, 'that')
+ self.assertEqual(len(list(diffs.iter_change_type('R'))), 1)
def test_diff_of_modified_files_not_added_to_the_index(self):
output = StringProcessAdapter(fixture('diff_abbrev-40_full-index_M_raw_no-color'))
- diffs = Diff._index_from_raw_format(self.rorepo, output.stdout)
-
- assert len(diffs) == 1, 'one modification'
- assert len(list(diffs.iter_change_type('M'))) == 1, 'one modification'
- assert diffs[0].change_type == 'M'
- assert diffs[0].b_blob is None
-
- def test_binary_diff(self):
- for method, file_name in ((Diff._index_from_patch_format, 'diff_patch_binary'),
- (Diff._index_from_raw_format, 'diff_raw_binary')):
- res = method(None, StringProcessAdapter(fixture(file_name)).stdout)
- assert len(res) == 1
- assert len(list(res.iter_change_type('M'))) == 1
- if res[0].diff:
- assert res[0].diff == b"Binary files a/rps and b/rps differ\n", "in patch mode, we get a diff text"
- assert str(res[0]), "This call should just work"
- # end for each method to test
+ diffs = Diff._index_from_raw_format(self.rorepo, output)
+
+ self.assertEqual(len(diffs), 1, 'one modification')
+ self.assertEqual(len(list(diffs.iter_change_type('M'))), 1, 'one modification')
+ self.assertEqual(diffs[0].change_type, 'M')
+ self.assertIsNone(diffs[0].b_blob,)
+
+ @ddt.data(
+ (Diff._index_from_patch_format, 'diff_patch_binary'),
+ (Diff._index_from_raw_format, 'diff_raw_binary')
+ )
+ def test_binary_diff(self, case):
+ method, file_name = case
+ res = method(None, StringProcessAdapter(fixture(file_name)))
+ self.assertEqual(len(res), 1)
+ self.assertEqual(len(list(res.iter_change_type('M'))), 1)
+ if res[0].diff:
+ self.assertEqual(res[0].diff,
+ b"Binary files a/rps and b/rps differ\n",
+ "in patch mode, we get a diff text")
+ self.assertIsNotNone(str(res[0]), "This call should just work")
def test_diff_index(self):
output = StringProcessAdapter(fixture('diff_index_patch'))
- res = Diff._index_from_patch_format(None, output.stdout)
- assert len(res) == 6
+ res = Diff._index_from_patch_format(None, output)
+ self.assertEqual(len(res), 6)
for dr in res:
- assert dr.diff.startswith(b'@@')
- assert str(dr), "Diff to string conversion should be possible"
+ self.assertTrue(dr.diff.startswith(b'@@'), dr)
+ self.assertIsNotNone(str(dr), "Diff to string conversion should be possible")
# end for each diff
dr = res[3]
@@ -138,29 +149,29 @@ class TestDiff(TestBase):
def test_diff_index_raw_format(self):
output = StringProcessAdapter(fixture('diff_index_raw'))
- res = Diff._index_from_raw_format(None, output.stdout)
- assert res[0].deleted_file
- assert res[0].b_path is None
+ res = Diff._index_from_raw_format(None, output)
+ self.assertIsNotNone(res[0].deleted_file)
+ self.assertIsNone(res[0].b_path,)
def test_diff_initial_commit(self):
initial_commit = self.rorepo.commit('33ebe7acec14b25c5f84f35a664803fcab2f7781')
# Without creating a patch...
diff_index = initial_commit.diff(NULL_TREE)
- assert diff_index[0].b_path == 'CHANGES'
- assert diff_index[0].new_file
- assert diff_index[0].diff == ''
+ self.assertEqual(diff_index[0].b_path, 'CHANGES')
+ self.assertIsNotNone(diff_index[0].new_file)
+ self.assertEqual(diff_index[0].diff, '')
# ...and with creating a patch
diff_index = initial_commit.diff(NULL_TREE, create_patch=True)
- assert diff_index[0].a_path is None, repr(diff_index[0].a_path)
- assert diff_index[0].b_path == 'CHANGES', repr(diff_index[0].b_path)
- assert diff_index[0].new_file
- assert diff_index[0].diff == fixture('diff_initial')
+ self.assertIsNone(diff_index[0].a_path, repr(diff_index[0].a_path))
+ self.assertEqual(diff_index[0].b_path, 'CHANGES', repr(diff_index[0].b_path))
+ self.assertIsNotNone(diff_index[0].new_file)
+ self.assertEqual(diff_index[0].diff, fixture('diff_initial'))
def test_diff_unsafe_paths(self):
output = StringProcessAdapter(fixture('diff_patch_unsafe_paths'))
- res = Diff._index_from_patch_format(None, output.stdout)
+ res = Diff._index_from_patch_format(None, output)
# The "Additions"
self.assertEqual(res[0].b_path, u'path/ starting with a space')
@@ -196,14 +207,14 @@ class TestDiff(TestBase):
for fixture_name in fixtures:
diff_proc = StringProcessAdapter(fixture(fixture_name))
- Diff._index_from_patch_format(self.rorepo, diff_proc.stdout)
+ Diff._index_from_patch_format(self.rorepo, diff_proc)
# END for each fixture
def test_diff_with_spaces(self):
data = StringProcessAdapter(fixture('diff_file_with_spaces'))
- diff_index = Diff._index_from_patch_format(self.rorepo, data.stdout)
- assert diff_index[0].a_path is None, repr(diff_index[0].a_path)
- assert diff_index[0].b_path == u'file with spaces', repr(diff_index[0].b_path)
+ diff_index = Diff._index_from_patch_format(self.rorepo, data)
+ self.assertIsNone(diff_index[0].a_path, repr(diff_index[0].a_path))
+ self.assertEqual(diff_index[0].b_path, u'file with spaces', repr(diff_index[0].b_path))
def test_diff_interface(self):
# test a few variations of the main diff routine
@@ -232,12 +243,12 @@ class TestDiff(TestBase):
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])
+ self.assertEqual(len(diff_set), 1)
+ self.assertEqual(diff_index[0], diff_index[0])
+ self.assertFalse(diff_index[0] != diff_index[0])
for dr in diff_index:
- assert str(dr), "Diff to string conversion should be possible"
+ self.assertIsNotNone(str(dr), "Diff to string conversion should be possible")
# END diff index checking
# END for each patch option
# END for each path option
@@ -248,11 +259,11 @@ class TestDiff(TestBase):
# 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
+ self.assertIsNotNone(value, "Did not find diff for %s" % key)
# END for each iteration type
# test path not existing in the index - should be ignored
c = self.rorepo.head.commit
cp = c.parents[0]
diff_index = c.diff(cp, ["does/not/exist"])
- assert len(diff_index) == 0
+ self.assertEqual(len(diff_index), 0)