/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

(John Arbash Meinel)  Fix bug #158333,
        make sure that Repository.fetch(self) is properly a no-op for all
        Repository implementations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 by Canonical Ltd
2
 
 
 
1
# Copyright (C) 2005 Canonical Ltd
 
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
 
 
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
import os
19
19
 
 
20
from bzrlib import bzrdir
20
21
from bzrlib.tests import TestCaseWithTransport, TestCase
21
22
from bzrlib.branch import Branch
22
 
from bzrlib.conflicts import *
 
23
from bzrlib.conflicts import (MissingParent, ContentsConflict, TextConflict,
 
24
        PathConflict, DuplicateID, DuplicateEntry, ParentLoop, UnversionedParent,
 
25
        ConflictList, 
 
26
        restore)
23
27
from bzrlib.errors import NotConflicted
24
28
 
25
29
 
26
30
# TODO: Test commit with some added, and added-but-missing files
27
31
# RBC 20060124 is that not tested in test_commit.py ?
28
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?)
29
38
example_conflicts = ConflictList([ 
30
 
    ContentsConflict('patha', 'ida'), 
31
 
    TextConflict('patha'),
32
 
    PathConflict('pathb', 'pathc', 'idb'),
33
 
    DuplicateID('Unversioned existing file', 'pathc', 'pathc2', 'idc', 'idc'),
34
 
    DuplicateEntry('Moved existing file to',  'pathdd.moved', 'pathd', 'idd', 
35
 
                   None),
36
 
    ParentLoop('Cancelled move', 'pathe', 'path2e', None, 'id2e'),
37
 
    UnversionedParent('Versioned directory', 'pathf', 'idf'),
38
 
    MissingParent('Not deleting', 'pathg', 'idg'),
 
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'),
39
50
])
40
51
 
41
52
 
43
54
 
44
55
    def test_conflicts(self):
45
56
        """Conflicts are detected properly"""
46
 
        tree = self.make_branch_and_tree('.')
 
57
        tree = self.make_branch_and_tree('.',
 
58
            format=bzrdir.BzrDirFormat6())
47
59
        b = tree.branch
48
60
        file('hello', 'w').write('hello world4')
49
61
        file('hello.THIS', 'w').write('hello world2')
51
63
        file('hello.OTHER', 'w').write('hello world3')
52
64
        file('hello.sploo.BASE', 'w').write('yellow world')
53
65
        file('hello.sploo.OTHER', 'w').write('yellow world2')
 
66
        tree.lock_read()
54
67
        self.assertEqual(len(list(tree.list_files())), 6)
 
68
        tree.unlock()
55
69
        conflicts = tree.conflicts()
56
70
        self.assertEqual(len(conflicts), 2)
57
71
        self.assert_('hello' in conflicts[0].path)
75
89
        l = ConflictList([TextConflict('hello')])
76
90
        l.remove_files(tree)
77
91
 
 
92
    def test_select_conflicts(self):
 
93
        tree = self.make_branch_and_tree('.')
 
94
        tree_conflicts = ConflictList([ContentsConflict('foo'),
 
95
                                       ContentsConflict('bar')])
 
96
        self.assertEqual((ConflictList([ContentsConflict('bar')]),
 
97
                          ConflictList([ContentsConflict('foo')])),
 
98
                         tree_conflicts.select_conflicts(tree, ['foo']))
 
99
        self.assertEqual((ConflictList(), tree_conflicts),
 
100
                         tree_conflicts.select_conflicts(tree, [''],
 
101
                         ignore_misses=True, recurse=True))
 
102
        tree_conflicts = ConflictList([ContentsConflict('foo/baz'),
 
103
                                       ContentsConflict('bar')])
 
104
        self.assertEqual((ConflictList([ContentsConflict('bar')]),
 
105
                          ConflictList([ContentsConflict('foo/baz')])),
 
106
                         tree_conflicts.select_conflicts(tree, ['foo'],
 
107
                                                         recurse=True,
 
108
                                                         ignore_misses=True))
 
109
        tree_conflicts = ConflictList([PathConflict('qux', 'foo/baz')])
 
110
        self.assertEqual((ConflictList(), tree_conflicts),
 
111
                         tree_conflicts.select_conflicts(tree, ['foo'],
 
112
                                                         recurse=True,
 
113
                                                         ignore_misses=True))
 
114
        self.assertEqual((tree_conflicts, ConflictList()),
 
115
                         tree_conflicts.select_conflicts(tree, ['foo'],
 
116
                                                         ignore_misses=True))
 
117
 
78
118
 
79
119
class TestConflictStanzas(TestCase):
 
120
 
80
121
    def test_stanza_roundtrip(self):
 
122
        # write and read our example stanza.
81
123
        stanza_iter = example_conflicts.to_stanzas()
82
124
        processed = ConflictList.from_stanzas(stanza_iter)
83
 
        for o,p in zip(processed, example_conflicts):
 
125
        for o, p in zip(processed, example_conflicts):
84
126
            self.assertEqual(o, p)
85
127
 
 
128
            self.assertIsInstance(o.path, unicode)
 
129
 
 
130
            if o.file_id is not None:
 
131
                self.assertIsInstance(o.file_id, str)
 
132
 
 
133
            conflict_path = getattr(o, 'conflict_path', None)
 
134
            if conflict_path is not None:
 
135
                self.assertIsInstance(conflict_path, unicode)
 
136
 
 
137
            conflict_file_id = getattr(o, 'conflict_file_id', None)
 
138
            if conflict_file_id is not None:
 
139
                self.assertIsInstance(conflict_file_id, str)
 
140
 
86
141
    def test_stanzification(self):
87
142
        for stanza in example_conflicts.to_stanzas():
88
 
            try:
89
 
                self.assertStartsWith(stanza['file_id'], 'id')
90
 
            except KeyError:
91
 
                pass
92
 
            self.assertStartsWith(stanza['path'], 'path')
93
 
            try:
94
 
                self.assertStartsWith(stanza['conflict_file_id'], 'id')
95
 
                self.assertStartsWith(stanza['conflict_file_path'], 'path')
96
 
            except KeyError:
97
 
                pass
 
143
            if 'file_id' in stanza:
 
144
                # In Stanza form, the file_id has to be unicode.
 
145
                self.assertStartsWith(stanza['file_id'], u'\xeed')
 
146
            self.assertStartsWith(stanza['path'], u'p\xe5th')
 
147
            if 'conflict_path' in stanza:
 
148
                self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
 
149
            if 'conflict_file_id' in stanza:
 
150
                self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')