~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/test_conflict_diff.py

  • Committer: Aaron Bentley
  • Date: 2011-09-25 01:18:55 UTC
  • mfrom: (776.2.1 unused-imports)
  • Revision ID: aaron@aaronbentley.com-20110925011855-3dil4ijgluvzq7q5
Remove unused imports, fix the importing of two error classes. (jelmer)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
    ConflictDiffer
 
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()
 
34
        ConflictDiffer().conflict_diff(s, 'foo', 'this')
 
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')
 
43
        e = self.assertRaises(errors.NoConflictFiles,
 
44
                              ConflictDiffer().get_old_lines,
 
45
                              'foo',
 
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')])
 
52
        old_lines = ConflictDiffer().get_old_lines('foo', 'foo.BASE')
 
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')
 
67
        old_lines = ConflictDiffer().get_old_lines('tree/foo', 'tree/foo.BASE')
 
68
        self.assertEqual(['base\n'], old_lines)