1
# Copyright (C) 2009 Aaron Bentley <aaron@aaronbentley.com>
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.
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.
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
18
from cStringIO import StringIO
21
from bzrlib.tests import TestCaseWithTransport
22
from bzrlib.plugins.bzrtools import errors
23
from bzrlib.plugins.bzrtools.conflict_diff import (
28
class TestConflictDiff(TestCaseWithTransport):
30
def test_conflict_diff_this(self):
31
self.build_tree_contents(
32
[('foo.THIS', 'this\n'), ('foo.BASE', 'base\n')])
34
ConflictDiffer().conflict_diff(s, 'foo', 'this')
35
self.assertEqual('--- foo.BASE\n+++ foo.THIS\n'
37
'-base\n+this\n\n', s.getvalue())
39
def test_no_conflict(self):
40
tree = self.make_branch_and_tree('.')
41
self.build_tree_contents([('foo', 'base\n')])
43
e = self.assertRaises(errors.NoConflictFiles,
44
ConflictDiffer().get_old_lines,
47
self.assertEqual('foo.BASE does not exist and there are no pending'
50
def test_get_old_lines(self):
51
self.build_tree_contents([('foo.BASE', 'base\n')])
52
old_lines = ConflictDiffer().get_old_lines('foo', 'foo.BASE')
53
self.assertEqual(['base\n'], old_lines)
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')])
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')
67
old_lines = ConflictDiffer().get_old_lines('tree/foo', 'tree/foo.BASE')
68
self.assertEqual(['base\n'], old_lines)