/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_conflicts.py

  • Committer: John Arbash Meinel
  • Date: 2007-03-06 15:43:47 UTC
  • mto: This revision was merged to the branch mainline in revision 2321.
  • Revision ID: john@arbash-meinel.com-20070306154347-ilhp9u2chs2nxm3b
The parameter is 'conflict_path' not 'conflict_file_path'

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 Canonical Ltd
 
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
import os
 
19
 
 
20
from bzrlib import bzrdir
 
21
from bzrlib.tests import TestCaseWithTransport, TestCase
 
22
from bzrlib.branch import Branch
 
23
from bzrlib.conflicts import (MissingParent, ContentsConflict, TextConflict,
 
24
        PathConflict, DuplicateID, DuplicateEntry, ParentLoop, UnversionedParent,
 
25
        ConflictList, 
 
26
        restore)
 
27
from bzrlib.errors import NotConflicted
 
28
 
 
29
 
 
30
# TODO: Test commit with some added, and added-but-missing files
 
31
# RBC 20060124 is that not tested in test_commit.py ?
 
32
 
 
33
# The order of 'path' here is important - do not let it
 
34
# be a sorted list.
 
35
# u'\xe5' == a with circle
 
36
# '\xc3\xae' == u'\xee' == i with hat
 
37
# So these are u'pathg' and 'idg' only with a circle and a hat. (shappo?)
 
38
example_conflicts = ConflictList([ 
 
39
    MissingParent('Not deleting', u'p\xe5thg', '\xc3\xaedg'),
 
40
    ContentsConflict(u'p\xe5tha', None, '\xc3\xaeda'), 
 
41
    TextConflict(u'p\xe5tha'),
 
42
    PathConflict(u'p\xe5thb', u'p\xe5thc', '\xc3\xaedb'),
 
43
    DuplicateID('Unversioned existing file', u'p\xe5thc', u'p\xe5thc2',
 
44
                '\xc3\xaedc', '\xc3\xaedc'),
 
45
    DuplicateEntry('Moved existing file to',  u'p\xe5thdd.moved', u'p\xe5thd',
 
46
                   '\xc3\xaedd', None),
 
47
    ParentLoop('Cancelled move', u'p\xe5the', u'p\xe5th2e',
 
48
               None, '\xc3\xaed2e'),
 
49
    UnversionedParent('Versioned directory', u'p\xe5thf', '\xc3\xaedf'),
 
50
])
 
51
 
 
52
 
 
53
class TestConflicts(TestCaseWithTransport):
 
54
 
 
55
    def test_conflicts(self):
 
56
        """Conflicts are detected properly"""
 
57
        tree = self.make_branch_and_tree('.',
 
58
            format=bzrdir.BzrDirFormat6())
 
59
        b = tree.branch
 
60
        file('hello', 'w').write('hello world4')
 
61
        file('hello.THIS', 'w').write('hello world2')
 
62
        file('hello.BASE', 'w').write('hello world1')
 
63
        file('hello.OTHER', 'w').write('hello world3')
 
64
        file('hello.sploo.BASE', 'w').write('yellow world')
 
65
        file('hello.sploo.OTHER', 'w').write('yellow world2')
 
66
        self.assertEqual(len(list(tree.list_files())), 6)
 
67
        conflicts = tree.conflicts()
 
68
        self.assertEqual(len(conflicts), 2)
 
69
        self.assert_('hello' in conflicts[0].path)
 
70
        self.assert_('hello.sploo' in conflicts[1].path)
 
71
        restore('hello')
 
72
        restore('hello.sploo')
 
73
        self.assertEqual(len(tree.conflicts()), 0)
 
74
        self.assertFileEqual('hello world2', 'hello')
 
75
        assert not os.path.lexists('hello.sploo')
 
76
        self.assertRaises(NotConflicted, restore, 'hello')
 
77
        self.assertRaises(NotConflicted, restore, 'hello.sploo')
 
78
 
 
79
    def test_resolve_conflict_dir(self):
 
80
        tree = self.make_branch_and_tree('.')
 
81
        b = tree.branch
 
82
        file('hello', 'w').write('hello world4')
 
83
        tree.add('hello', 'q')
 
84
        file('hello.THIS', 'w').write('hello world2')
 
85
        file('hello.BASE', 'w').write('hello world1')
 
86
        os.mkdir('hello.OTHER')
 
87
        l = ConflictList([TextConflict('hello')])
 
88
        l.remove_files(tree)
 
89
 
 
90
 
 
91
class TestConflictStanzas(TestCase):
 
92
 
 
93
    def test_stanza_roundtrip(self):
 
94
        # write and read our example stanza.
 
95
        stanza_iter = example_conflicts.to_stanzas()
 
96
        processed = ConflictList.from_stanzas(stanza_iter)
 
97
        for o, p in zip(processed, example_conflicts):
 
98
            self.assertEqual(o, p)
 
99
 
 
100
            self.assertIsInstance(o.path, unicode)
 
101
 
 
102
            if o.file_id is not None:
 
103
                self.assertIsInstance(o.file_id, str)
 
104
 
 
105
            conflict_path = getattr(o, 'conflict_path', None)
 
106
            if conflict_path is not None:
 
107
                self.assertIsInstance(conflict_path, unicode)
 
108
 
 
109
            conflict_file_id = getattr(o, 'conflict_file_id', None)
 
110
            if conflict_file_id is not None:
 
111
                self.assertIsInstance(conflict_file_id, str)
 
112
 
 
113
    def test_stanzification(self):
 
114
        for stanza in example_conflicts.to_stanzas():
 
115
            if 'file_id' in stanza:
 
116
                # In Stanza form, the file_id has to be unicode.
 
117
                self.assertStartsWith(stanza['file_id'], u'\xeed')
 
118
            self.assertStartsWith(stanza['path'], u'p\xe5th')
 
119
            if 'conflict_path' in stanza:
 
120
                self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
 
121
            if 'conflict_file_id' in stanza:
 
122
                self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')