def test_diff_revisions(self): r = GitRepo(self._temp_repo) a = GitRevision('refs/heads/topic', r) b = GitRevision('refs/heads/master', r) diff = r.diff_revisions(a, b) self.assertTrue(isinstance(diff, GitDiff))
class GitDiffTest(StandardFixturesMixin, TempGitRepoTest): def setUp(self): super(GitDiffTest, self).setUp() self._gitrepo = GitRepo(self._temp_repo) self.maxDiff = None def test_common_ancestor_typical(self): """Test typical usage of the method where b was branched from a""" a = GitRevision('refs/heads/master', self._gitrepo) b = GitRevision('refs/heads/topic', self._gitrepo) self.assertEquals( self._gitrepo._common_ancestor(a.id, b.id), self._commits['commit #3 on master'] ) def test_common_ancestor_reverse(self): """Testing the same thing, but a was branched from b. Result should be the same as test_common_ancestor_typical""" a = GitRevision('refs/heads/topic', self._gitrepo) b = GitRevision('refs/heads/master', self._gitrepo) self.assertEquals( self._gitrepo._common_ancestor(a.id, b.id), self._commits['commit #3 on master'] ) def test_common_ancestor_initial_commit(self): self.assertEquals( self._gitrepo._common_ancestor( self._commits['commit #1 on master'], self._commits['commit #2 on master'] ), self._commits['commit #1 on master'] ) def test_common_ancestor_same_commit(self): self.assertEquals( self._gitrepo._common_ancestor( self._commits['commit #3 on master'], self._commits['commit #3 on master'] ), self._commits['commit #3 on master'] ) def test_diff_revisions_output(self): a = GitRevision('refs/heads/topic', self._gitrepo) b = GitRevision('refs/heads/master', self._gitrepo) diff = self._gitrepo.diff_revisions(a, b) unified_diff = [ud[1] for ud in diff.unified_diff()] self.assertEquals( unified_diff, [ textwrap.dedent('''\ diff --git a/dir_1/file_3 /dev/null deleted mode 100644 index da2940c..0000000 --- a/dir_1/file_3 +++ /dev/null @@ -1,7 +1,0 @@ -first line -second line - - - - -seventh line \\ No newline at end of file ''' ), textwrap.dedent('''\ diff --git a/file_2 b/file_2 index 9a2973f..fa58e34 100644 --- a/file_2 +++ b/file_2 @@ -1,4 +1,3 @@ line one line two -line three -line four \\ No newline at end of file +line three \\ No newline at end of file ''' ), textwrap.dedent('''\ diff --git /dev/null b/file_\xe2\x98\x83 new mode 100644 index 0000000..0d7e5f8 100644 --- /dev/null +++ b/file_\xe2\x98\x83 @@ -1,0 +1,1 @@ +\xe2\x98\x83 \\ No newline at end of file ''') ] )