~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 (
24
    conflict_diff,
25
    get_old_lines,
26
)
27
28
29
class TestConflictDiff(TestCaseWithTransport):
30
31
    def test_conflict_diff_this(self):
32
        self.build_tree_contents(
33
            [('foo.THIS', 'this\n'), ('foo.BASE', 'base\n')])
34
        s = StringIO()
35
        conflict_diff(s, 'foo', 'this')
36
        self.assertEqual('--- foo.BASE\n+++ foo.THIS\n'
37
                         '@@ -1,1 +1,1 @@\n'
38
                         '-base\n+this\n\n', s.getvalue())
39
40
    def test_no_conflict(self):
41
        tree = self.make_branch_and_tree('.')
42
        self.build_tree_contents([('foo', 'base\n')])
43
        tree.add('foo')
44
        e = self.assertRaises(errors.NoConflictFiles, get_old_lines, 'foo',
45
                              'foo.BASE')
46
        self.assertEqual('foo.BASE does not exist and there are no pending'
47
                         ' merges.', str(e))
48
49
    def test_get_old_lines(self):
50
        self.build_tree_contents([('foo.BASE', 'base\n')])
51
        old_lines = get_old_lines('foo', 'foo.BASE')
52
        self.assertEqual(['base\n'], old_lines)
53
54
    def test_get_old_lines_no_base(self):
55
        tree = self.make_branch_and_tree('tree')
56
        self.build_tree_contents([('tree/foo', 'base\n')])
57
        tree.add('foo')
58
        tree.commit('added foo')
59
        other = tree.bzrdir.sprout('other').open_workingtree()
60
        self.build_tree_contents([('other/foo', 'other\n')])
61
        other.commit('Changed foo text')
62
        self.build_tree_contents([('tree/foo', 'this\n')])
63
        tree.commit('Changed foo text')
64
        tree.merge_from_branch(other.branch)
65
        os.unlink('tree/foo.BASE')
66
        old_lines = get_old_lines('tree/foo', 'tree/foo.BASE')
67
        self.assertEqual(['base\n'], old_lines)