/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1185.14.8 by Aaron Bentley
Added test_commit.py
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1185.14.8 by Aaron Bentley
Added test_commit.py
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1185.14.8 by Aaron Bentley
Added test_commit.py
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1185.14.8 by Aaron Bentley
Added test_commit.py
16
17
18
import os
19
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
20
from bzrlib import (
21
    bzrdir,
22
    conflicts,
23
    errors,
24
    tests,
25
    )
1185.14.8 by Aaron Bentley
Added test_commit.py
26
1534.10.4 by Aaron Bentley
Implemented conflict serialization
27
1185.14.8 by Aaron Bentley
Added test_commit.py
28
# TODO: Test commit with some added, and added-but-missing files
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
29
# RBC 20060124 is that not tested in test_commit.py ?
1185.14.8 by Aaron Bentley
Added test_commit.py
30
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
31
# The order of 'path' here is important - do not let it
32
# be a sorted list.
2309.4.13 by John Arbash Meinel
Conflicts go through Stanza so the need to be aware of utf8 versus unicode file ids.
33
# u'\xe5' == a with circle
34
# '\xc3\xae' == u'\xee' == i with hat
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
35
# So these are u'path' and 'id' only with a circle and a hat. (shappo?)
36
example_conflicts = conflicts.ConflictList(
37
    [conflicts.MissingParent('Not deleting', u'p\xe5thg', '\xc3\xaedg'),
38
     conflicts.ContentsConflict(u'p\xe5tha', None, '\xc3\xaeda'),
39
     conflicts.TextConflict(u'p\xe5tha'),
40
     conflicts.PathConflict(u'p\xe5thb', u'p\xe5thc', '\xc3\xaedb'),
41
     conflicts.DuplicateID('Unversioned existing file',
42
                           u'p\xe5thc', u'p\xe5thc2',
43
                           '\xc3\xaedc', '\xc3\xaedc'),
44
    conflicts.DuplicateEntry('Moved existing file to',
45
                             u'p\xe5thdd.moved', u'p\xe5thd',
46
                             '\xc3\xaedd', None),
47
    conflicts.ParentLoop('Cancelled move', u'p\xe5the', u'p\xe5th2e',
48
                         None, '\xc3\xaed2e'),
49
    conflicts.UnversionedParent('Versioned directory',
50
                                u'p\xe5thf', '\xc3\xaedf'),
51
    conflicts.NonDirectoryParent('Created directory',
52
                                 u'p\xe5thg', '\xc3\xaedg'),
1534.10.22 by Aaron Bentley
Got ConflictList implemented
53
])
1534.10.4 by Aaron Bentley
Implemented conflict serialization
54
55
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
56
class TestConflictStanzas(tests.TestCase):
57
58
    def test_stanza_roundtrip(self):
59
        # write and read our example stanza.
60
        stanza_iter = example_conflicts.to_stanzas()
61
        processed = conflicts.ConflictList.from_stanzas(stanza_iter)
62
        for o, p in zip(processed, example_conflicts):
63
            self.assertEqual(o, p)
64
65
            self.assertIsInstance(o.path, unicode)
66
67
            if o.file_id is not None:
68
                self.assertIsInstance(o.file_id, str)
69
70
            conflict_path = getattr(o, 'conflict_path', None)
71
            if conflict_path is not None:
72
                self.assertIsInstance(conflict_path, unicode)
73
74
            conflict_file_id = getattr(o, 'conflict_file_id', None)
75
            if conflict_file_id is not None:
76
                self.assertIsInstance(conflict_file_id, str)
77
78
    def test_stanzification(self):
79
        for stanza in example_conflicts.to_stanzas():
80
            if 'file_id' in stanza:
81
                # In Stanza form, the file_id has to be unicode.
82
                self.assertStartsWith(stanza['file_id'], u'\xeed')
83
            self.assertStartsWith(stanza['path'], u'p\xe5th')
84
            if 'conflict_path' in stanza:
85
                self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
86
            if 'conflict_file_id' in stanza:
87
                self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
88
89
90
class TestConflicts(tests.TestCaseWithTransport):
1185.14.8 by Aaron Bentley
Added test_commit.py
91
92
    def test_conflicts(self):
93
        """Conflicts are detected properly"""
4597.2.3 by Vincent Ladeuil
More cleanup.
94
        # Use BzrDirFormat6 so we can fake conflicts
95
        tree = self.make_branch_and_tree('.', format=bzrdir.BzrDirFormat6())
96
        self.build_tree_contents([('hello', 'hello world4'),
97
                                  ('hello.THIS', 'hello world2'),
98
                                  ('hello.BASE', 'hello world1'),
99
                                  ('hello.OTHER', 'hello world3'),
100
                                  ('hello.sploo.BASE', 'yellowworld'),
101
                                  ('hello.sploo.OTHER', 'yellowworld2'),
102
                                  ])
2255.2.61 by John Arbash Meinel
Find callers of list_files() and make sure the tree is always locked.
103
        tree.lock_read()
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
104
        self.assertEqual(6, len(list(tree.list_files())))
2255.2.61 by John Arbash Meinel
Find callers of list_files() and make sure the tree is always locked.
105
        tree.unlock()
4597.2.3 by Vincent Ladeuil
More cleanup.
106
        tree_conflicts = tree.conflicts()
107
        self.assertEqual(2, len(tree_conflicts))
108
        self.assertTrue('hello' in tree_conflicts[0].path)
109
        self.assertTrue('hello.sploo' in tree_conflicts[1].path)
110
        conflicts.restore('hello')
111
        conflicts.restore('hello.sploo')
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
112
        self.assertEqual(0, len(tree.conflicts()))
1185.35.1 by Aaron Bentley
Implemented conflicts.restore
113
        self.assertFileEqual('hello world2', 'hello')
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
114
        self.assertFalse(os.path.lexists('hello.sploo'))
4597.2.3 by Vincent Ladeuil
More cleanup.
115
        self.assertRaises(errors.NotConflicted, conflicts.restore, 'hello')
116
        self.assertRaises(errors.NotConflicted,
117
                          conflicts.restore, 'hello.sploo')
1534.10.4 by Aaron Bentley
Implemented conflict serialization
118
1558.12.9 by Aaron Bentley
Handle resolving conflicts with directories properly
119
    def test_resolve_conflict_dir(self):
120
        tree = self.make_branch_and_tree('.')
4597.2.3 by Vincent Ladeuil
More cleanup.
121
        self.build_tree_contents([('hello', 'hello world4'),
122
                                  ('hello.THIS', 'hello world2'),
123
                                  ('hello.BASE', 'hello world1'),
124
                                  ])
125
        os.mkdir('hello.OTHER')
1558.12.9 by Aaron Bentley
Handle resolving conflicts with directories properly
126
        tree.add('hello', 'q')
4597.2.3 by Vincent Ladeuil
More cleanup.
127
        l = conflicts.ConflictList([conflicts.TextConflict('hello')])
1558.12.9 by Aaron Bentley
Handle resolving conflicts with directories properly
128
        l.remove_files(tree)
129
1551.15.58 by Aaron Bentley
Status honours selected paths for conflicts (#127606)
130
    def test_select_conflicts(self):
131
        tree = self.make_branch_and_tree('.')
4597.2.3 by Vincent Ladeuil
More cleanup.
132
        clist = conflicts.ConflictList
133
134
        def check_select(not_selected, selected, paths, **kwargs):
135
            self.assertEqual(
136
                (not_selected, selected),
137
                tree_conflicts.select_conflicts(tree, paths, **kwargs))
138
139
        foo = conflicts.ContentsConflict('foo')
140
        bar = conflicts.ContentsConflict('bar')
141
        tree_conflicts = clist([foo, bar])
142
143
        check_select(clist([bar]), clist([foo]), ['foo'])
144
        check_select(clist(), tree_conflicts,
145
                     [''], ignore_misses=True, recurse=True)
146
147
        foobaz  = conflicts.ContentsConflict('foo/baz')
148
        tree_conflicts = clist([foobaz, bar])
149
150
        check_select(clist([bar]), clist([foobaz]),
151
                     ['foo'], ignore_misses=True, recurse=True)
152
153
        qux = conflicts.PathConflict('qux', 'foo/baz')
154
        tree_conflicts = clist([qux])
155
156
        check_select(clist(), tree_conflicts,
157
                     ['foo'], ignore_misses=True, recurse=True)
158
        check_select (tree_conflicts, clist(), ['foo'], ignore_misses=True)
1551.15.58 by Aaron Bentley
Status honours selected paths for conflicts (#127606)
159
3017.2.1 by Aaron Bentley
Revert now resolves conflicts recursively (#102739)
160
    def test_resolve_conflicts_recursive(self):
161
        tree = self.make_branch_and_tree('.')
162
        self.build_tree(['dir/', 'dir/hello'])
163
        tree.add(['dir', 'dir/hello'])
4597.2.3 by Vincent Ladeuil
More cleanup.
164
165
        dirhello = conflicts.ConflictList([conflicts.TextConflict('dir/hello')])
166
        tree.set_conflicts(dirhello)
167
168
        conflicts.resolve(tree, ['dir'], recursive=False, ignore_misses=True)
169
        self.assertEqual(dirhello, tree.conflicts())
170
171
        conflicts.resolve(tree, ['dir'], recursive=True, ignore_misses=True)
172
        self.assertEqual(conflicts.ConflictList([]), tree.conflicts())
4773.1.1 by Vincent Ladeuil
Cleanup imports in test_conflicts
173
174