~abentley/bzrtools/bzrtools.dev

702 by Aaron Bentley
Get conflict-diff under test.
1
# Copyright (C) 2009 Aaron Bentley <aaron@aaronbentley.com>
2
#
3
#    This program is free software; you can redistribute it and/or modify
4
#    it under the terms of the GNU General Public License as published by
5
#    the Free Software Foundation; either version 2 of the License, or
6
#    (at your option) any later version.
7
#
8
#    This program is distributed in the hope that it will be useful,
9
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
10
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
#    GNU General Public License for more details.
12
#
13
#    You should have received a copy of the GNU General Public License
14
#    along with this program; if not, write to the Free Software
15
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
18
from cStringIO import StringIO
19
import os
20
21
from bzrlib.tests import TestCaseWithTransport
22
from bzrlib.plugins.bzrtools import errors
23
from bzrlib.plugins.bzrtools.conflict_diff import (
733 by Aaron Bentley
Conflict differ works with no file specified or many files specified.
24
    ConflictDiffer
702 by Aaron Bentley
Get conflict-diff under test.
25
)
26
27
28
class TestConflictDiff(TestCaseWithTransport):
29
30
    def test_conflict_diff_this(self):
31
        self.build_tree_contents(
32
            [('foo.THIS', 'this\n'), ('foo.BASE', 'base\n')])
33
        s = StringIO()
733 by Aaron Bentley
Conflict differ works with no file specified or many files specified.
34
        ConflictDiffer().conflict_diff(s, 'foo', 'this')
702 by Aaron Bentley
Get conflict-diff under test.
35
        self.assertEqual('--- foo.BASE\n+++ foo.THIS\n'
36
                         '@@ -1,1 +1,1 @@\n'
37
                         '-base\n+this\n\n', s.getvalue())
38
39
    def test_no_conflict(self):
40
        tree = self.make_branch_and_tree('.')
41
        self.build_tree_contents([('foo', 'base\n')])
42
        tree.add('foo')
733 by Aaron Bentley
Conflict differ works with no file specified or many files specified.
43
        e = self.assertRaises(errors.NoConflictFiles,
44
                              ConflictDiffer().get_old_lines,
45
                              'foo',
702 by Aaron Bentley
Get conflict-diff under test.
46
                              'foo.BASE')
47
        self.assertEqual('foo.BASE does not exist and there are no pending'
48
                         ' merges.', str(e))
49
50
    def test_get_old_lines(self):
51
        self.build_tree_contents([('foo.BASE', 'base\n')])
733 by Aaron Bentley
Conflict differ works with no file specified or many files specified.
52
        old_lines = ConflictDiffer().get_old_lines('foo', 'foo.BASE')
702 by Aaron Bentley
Get conflict-diff under test.
53
        self.assertEqual(['base\n'], old_lines)
54
55
    def test_get_old_lines_no_base(self):
56
        tree = self.make_branch_and_tree('tree')
57
        self.build_tree_contents([('tree/foo', 'base\n')])
58
        tree.add('foo')
59
        tree.commit('added foo')
60
        other = tree.bzrdir.sprout('other').open_workingtree()
61
        self.build_tree_contents([('other/foo', 'other\n')])
62
        other.commit('Changed foo text')
63
        self.build_tree_contents([('tree/foo', 'this\n')])
64
        tree.commit('Changed foo text')
65
        tree.merge_from_branch(other.branch)
66
        os.unlink('tree/foo.BASE')
733 by Aaron Bentley
Conflict differ works with no file specified or many files specified.
67
        old_lines = ConflictDiffer().get_old_lines('tree/foo', 'tree/foo.BASE')
702 by Aaron Bentley
Get conflict-diff under test.
68
        self.assertEqual(['base\n'], old_lines)