/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.7 by John Arbash Meinel
Merge in the bzr.dev 5582
1
# Copyright (C) 2005-2011 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
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
20
from .. import (
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
21
    conflicts,
22
    errors,
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
23
    option,
5609.17.1 by Vincent Ladeuil
Reproduce bug #715068.
24
    osutils,
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
25
    tests,
26
    )
6973.6.2 by Jelmer Vernooij
Fix more tests.
27
from ..sixish import text_type
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
28
from . import (
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
29
    script,
30
    scenarios,
31
    )
32
33
34
load_tests = scenarios.load_tests_apply_scenarios
4597.2.26 by Vincent Ladeuil
Fix bug #529968 by renaming the kept file on content conflicts.
35
36
1185.14.8 by Aaron Bentley
Added test_commit.py
37
# 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.
38
# RBC 20060124 is that not tested in test_commit.py ?
1185.14.8 by Aaron Bentley
Added test_commit.py
39
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
40
# The order of 'path' here is important - do not let it
41
# 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.
42
# u'\xe5' == a with circle
43
# '\xc3\xae' == u'\xee' == i with hat
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
44
# So these are u'path' and 'id' only with a circle and a hat. (shappo?)
45
example_conflicts = conflicts.ConflictList(
7058.4.6 by Jelmer Vernooij
Fix some conflict tests.
46
    [conflicts.MissingParent('Not deleting', u'p\xe5thg', b'\xc3\xaedg'),
47
     conflicts.ContentsConflict(u'p\xe5tha', None, b'\xc3\xaeda'),
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
48
     conflicts.TextConflict(u'p\xe5tha'),
7058.4.6 by Jelmer Vernooij
Fix some conflict tests.
49
     conflicts.PathConflict(u'p\xe5thb', u'p\xe5thc', b'\xc3\xaedb'),
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
50
     conflicts.DuplicateID('Unversioned existing file',
51
                           u'p\xe5thc', u'p\xe5thc2',
7058.4.6 by Jelmer Vernooij
Fix some conflict tests.
52
                           b'\xc3\xaedc', b'\xc3\xaedc'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
53
     conflicts.DuplicateEntry('Moved existing file to',
54
                              u'p\xe5thdd.moved', u'p\xe5thd',
55
                              b'\xc3\xaedd', None),
56
     conflicts.ParentLoop('Cancelled move', u'p\xe5the', u'p\xe5th2e',
57
                          None, b'\xc3\xaed2e'),
58
     conflicts.UnversionedParent('Versioned directory',
59
                                 u'p\xe5thf', b'\xc3\xaedf'),
60
     conflicts.NonDirectoryParent('Created directory',
61
                                  u'p\xe5thg', b'\xc3\xaedg'),
62
     ])
1534.10.4 by Aaron Bentley
Implemented conflict serialization
63
64
5898.1.1 by Martin
Refactor conflict stanzas tests to use scenarios
65
def vary_by_conflicts():
66
    for conflict in example_conflicts:
67
        yield (conflict.__class__.__name__, {"conflict": conflict})
68
69
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
70
class TestConflicts(tests.TestCaseWithTransport):
1185.14.8 by Aaron Bentley
Added test_commit.py
71
1558.12.9 by Aaron Bentley
Handle resolving conflicts with directories properly
72
    def test_resolve_conflict_dir(self):
73
        tree = self.make_branch_and_tree('.')
6855.4.1 by Jelmer Vernooij
Yet more bees.
74
        self.build_tree_contents([('hello', b'hello world4'),
75
                                  ('hello.THIS', b'hello world2'),
76
                                  ('hello.BASE', b'hello world1'),
4597.2.3 by Vincent Ladeuil
More cleanup.
77
                                  ])
78
        os.mkdir('hello.OTHER')
6973.11.7 by Jelmer Vernooij
Fix more tests.
79
        tree.add('hello', b'q')
4597.2.3 by Vincent Ladeuil
More cleanup.
80
        l = conflicts.ConflictList([conflicts.TextConflict('hello')])
1558.12.9 by Aaron Bentley
Handle resolving conflicts with directories properly
81
        l.remove_files(tree)
82
1551.15.58 by Aaron Bentley
Status honours selected paths for conflicts (#127606)
83
    def test_select_conflicts(self):
84
        tree = self.make_branch_and_tree('.')
4597.2.3 by Vincent Ladeuil
More cleanup.
85
        clist = conflicts.ConflictList
86
87
        def check_select(not_selected, selected, paths, **kwargs):
88
            self.assertEqual(
89
                (not_selected, selected),
90
                tree_conflicts.select_conflicts(tree, paths, **kwargs))
91
92
        foo = conflicts.ContentsConflict('foo')
93
        bar = conflicts.ContentsConflict('bar')
94
        tree_conflicts = clist([foo, bar])
95
96
        check_select(clist([bar]), clist([foo]), ['foo'])
97
        check_select(clist(), tree_conflicts,
98
                     [''], ignore_misses=True, recurse=True)
99
7143.15.2 by Jelmer Vernooij
Run autopep8.
100
        foobaz = conflicts.ContentsConflict('foo/baz')
4597.2.3 by Vincent Ladeuil
More cleanup.
101
        tree_conflicts = clist([foobaz, bar])
102
103
        check_select(clist([bar]), clist([foobaz]),
104
                     ['foo'], ignore_misses=True, recurse=True)
105
106
        qux = conflicts.PathConflict('qux', 'foo/baz')
107
        tree_conflicts = clist([qux])
108
109
        check_select(clist(), tree_conflicts,
110
                     ['foo'], ignore_misses=True, recurse=True)
7143.15.2 by Jelmer Vernooij
Run autopep8.
111
        check_select(tree_conflicts, clist(), ['foo'], ignore_misses=True)
1551.15.58 by Aaron Bentley
Status honours selected paths for conflicts (#127606)
112
3017.2.1 by Aaron Bentley
Revert now resolves conflicts recursively (#102739)
113
    def test_resolve_conflicts_recursive(self):
114
        tree = self.make_branch_and_tree('.')
115
        self.build_tree(['dir/', 'dir/hello'])
116
        tree.add(['dir', 'dir/hello'])
4597.2.3 by Vincent Ladeuil
More cleanup.
117
7143.15.2 by Jelmer Vernooij
Run autopep8.
118
        dirhello = conflicts.ConflictList(
119
            [conflicts.TextConflict('dir/hello')])
4597.2.3 by Vincent Ladeuil
More cleanup.
120
        tree.set_conflicts(dirhello)
121
122
        conflicts.resolve(tree, ['dir'], recursive=False, ignore_misses=True)
123
        self.assertEqual(dirhello, tree.conflicts())
124
125
        conflicts.resolve(tree, ['dir'], recursive=True, ignore_misses=True)
126
        self.assertEqual(conflicts.ConflictList([]), tree.conflicts())
4773.1.1 by Vincent Ladeuil
Cleanup imports in test_conflicts
127
128
5898.1.3 by Martin
Add tests for non-ascii conflict serialisation
129
class TestPerConflict(tests.TestCase):
4597.3.43 by Vincent Ladeuil
Cleanups, ready to record.
130
5898.1.1 by Martin
Refactor conflict stanzas tests to use scenarios
131
    scenarios = scenarios.multiply_scenarios(vary_by_conflicts())
132
5898.1.3 by Martin
Add tests for non-ascii conflict serialisation
133
    def test_stringification(self):
6973.6.2 by Jelmer Vernooij
Fix more tests.
134
        text = text_type(self.conflict)
5898.1.3 by Martin
Add tests for non-ascii conflict serialisation
135
        self.assertContainsString(text, self.conflict.path)
136
        self.assertContainsString(text.lower(), "conflict")
137
        self.assertContainsString(repr(self.conflict),
7143.15.2 by Jelmer Vernooij
Run autopep8.
138
                                  self.conflict.__class__.__name__)
5898.1.3 by Martin
Add tests for non-ascii conflict serialisation
139
4597.3.43 by Vincent Ladeuil
Cleanups, ready to record.
140
    def test_stanza_roundtrip(self):
5898.1.1 by Martin
Refactor conflict stanzas tests to use scenarios
141
        p = self.conflict
142
        o = conflicts.Conflict.factory(**p.as_stanza().as_dict())
143
        self.assertEqual(o, p)
144
6973.6.2 by Jelmer Vernooij
Fix more tests.
145
        self.assertIsInstance(o.path, text_type)
5898.1.1 by Martin
Refactor conflict stanzas tests to use scenarios
146
147
        if o.file_id is not None:
6973.11.7 by Jelmer Vernooij
Fix more tests.
148
            self.assertIsInstance(o.file_id, bytes)
5898.1.1 by Martin
Refactor conflict stanzas tests to use scenarios
149
150
        conflict_path = getattr(o, 'conflict_path', None)
151
        if conflict_path is not None:
6973.6.2 by Jelmer Vernooij
Fix more tests.
152
            self.assertIsInstance(conflict_path, text_type)
5898.1.1 by Martin
Refactor conflict stanzas tests to use scenarios
153
154
        conflict_file_id = getattr(o, 'conflict_file_id', None)
155
        if conflict_file_id is not None:
6973.11.7 by Jelmer Vernooij
Fix more tests.
156
            self.assertIsInstance(conflict_file_id, bytes)
4597.3.43 by Vincent Ladeuil
Cleanups, ready to record.
157
158
    def test_stanzification(self):
5898.1.1 by Martin
Refactor conflict stanzas tests to use scenarios
159
        stanza = self.conflict.as_stanza()
160
        if 'file_id' in stanza:
161
            # In Stanza form, the file_id has to be unicode.
162
            self.assertStartsWith(stanza['file_id'], u'\xeed')
163
        self.assertStartsWith(stanza['path'], u'p\xe5th')
164
        if 'conflict_path' in stanza:
165
            self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
166
        if 'conflict_file_id' in stanza:
167
            self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
168
169
5898.1.3 by Martin
Add tests for non-ascii conflict serialisation
170
class TestConflictList(tests.TestCase):
5898.1.1 by Martin
Refactor conflict stanzas tests to use scenarios
171
172
    def test_stanzas_roundtrip(self):
173
        stanzas_iter = example_conflicts.to_stanzas()
174
        processed = conflicts.ConflictList.from_stanzas(stanzas_iter)
175
        self.assertEqual(example_conflicts, processed)
4597.3.43 by Vincent Ladeuil
Cleanups, ready to record.
176
5898.1.3 by Martin
Add tests for non-ascii conflict serialisation
177
    def test_stringification(self):
178
        for text, o in zip(example_conflicts.to_strings(), example_conflicts):
6973.6.2 by Jelmer Vernooij
Fix more tests.
179
            self.assertEqual(text, text_type(o))
5898.1.3 by Martin
Add tests for non-ascii conflict serialisation
180
4597.3.43 by Vincent Ladeuil
Cleanups, ready to record.
181
4597.3.74 by Vincent Ladeuil
Add a FIXME about rewriting shell-like tests into real whitebox tests.
182
# FIXME: The shell-like tests should be converted to real whitebox tests... or
183
# moved to a blackbox module -- vila 20100205
184
4597.7.11 by Vincent Ladeuil
Fix #531967 by creating helpers for PathConflicts when a deletion
185
# FIXME: test missing for multiple conflicts
186
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
187
# FIXME: Tests missing for DuplicateID conflict type
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
188
class TestResolveConflicts(script.TestCaseWithTransportAndScript):
189
7143.15.2 by Jelmer Vernooij
Run autopep8.
190
    preamble = None  # The setup script set by daughter classes
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
191
192
    def setUp(self):
193
        super(TestResolveConflicts, self).setUp()
194
        self.run_script(self.preamble)
195
196
4597.10.11 by Vincent Ladeuil
Turn mirror_scenarios into a simple function.
197
def mirror_scenarios(base_scenarios):
198
    """Return a list of mirrored scenarios.
199
200
    Each scenario in base_scenarios is duplicated switching the roles of 'this'
201
    and 'other'
202
    """
203
    scenarios = []
4597.10.14 by Vincent Ladeuil
Some more cleanup and typos.
204
    for common, (lname, ldict), (rname, rdict) in base_scenarios:
4597.10.11 by Vincent Ladeuil
Turn mirror_scenarios into a simple function.
205
        a = tests.multiply_scenarios([(lname, dict(_this=ldict))],
206
                                     [(rname, dict(_other=rdict))])
207
        b = tests.multiply_scenarios([(rname, dict(_this=rdict))],
208
                                     [(lname, dict(_other=ldict))])
209
        # Inject the common parameters in all scenarios
210
        for name, d in a + b:
211
            d.update(common)
212
        scenarios.extend(a + b)
213
    return scenarios
214
215
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
216
# FIXME: Get rid of parametrized (in the class name) once we delete
217
# TestResolveConflicts -- vila 20100308
4597.7.4 by Vincent Ladeuil
Abstract the test class some more to address more conflict
218
class TestParametrizedResolveConflicts(tests.TestCaseWithTransport):
4597.7.18 by Vincent Ladeuil
Start addressing Andrew's concerns.
219
    """This class provides a base to test single conflict resolution.
220
4597.10.7 by Vincent Ladeuil
Simplify scenarios mirroring and give a better docstring for TestParametrizedResolveConflicts.
221
    Since all conflict objects are created with specific semantics for their
222
    attributes, each class should implement the necessary functions and
223
    attributes described below.
224
225
    Each class should define the scenarios that create the expected (single)
226
    conflict.
227
228
    Each scenario describes:
229
    * how to create 'base' tree (and revision)
230
    * how to create 'left' tree (and revision, parent rev 'base')
231
    * how to create 'right' tree (and revision, parent rev 'base')
232
    * how to check that changes in 'base'->'left' have been taken
233
    * how to check that changes in 'base'->'right' have been taken
234
235
    From each base scenario, we generate two concrete scenarios where:
236
    * this=left, other=right
237
    * this=right, other=left
238
239
    Then the test case verifies each concrete scenario by:
240
    * creating a branch containing the 'base', 'this' and 'other' revisions
241
    * creating a working tree for the 'this' revision
242
    * performing the merge of 'other' into 'this'
243
    * verifying the expected conflict was generated
244
    * resolving with --take-this or --take-other, and running the corresponding
245
      checks (for either 'base'->'this', or 'base'->'other')
246
247
    :cvar _conflict_type: The expected class of the generated conflict.
248
249
    :cvar _assert_conflict: A method receiving the working tree and the
250
        conflict object and checking its attributes.
251
4597.10.9 by Vincent Ladeuil
More doc.
252
    :cvar _base_actions: The branchbuilder actions to create the 'base'
253
        revision.
254
255
    :cvar _this: The dict related to 'base' -> 'this'. It contains at least:
256
      * 'actions': The branchbuilder actions to create the 'this'
257
          revision.
4597.10.10 by Vincent Ladeuil
Fix typo.
258
      * 'check': how to check the changes after resolution with --take-this.
4597.10.9 by Vincent Ladeuil
More doc.
259
260
    :cvar _other: The dict related to 'base' -> 'other'. It contains at least:
261
      * 'actions': The branchbuilder actions to create the 'other'
262
          revision.
4597.10.10 by Vincent Ladeuil
Fix typo.
263
      * 'check': how to check the changes after resolution with --take-other.
4597.7.18 by Vincent Ladeuil
Start addressing Andrew's concerns.
264
    """
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
265
4597.7.16 by Vincent Ladeuil
Some cleanup.
266
    # Set by daughter classes
267
    _conflict_type = None
268
    _assert_conflict = None
269
4597.2.26 by Vincent Ladeuil
Fix bug #529968 by renaming the kept file on content conflicts.
270
    # Set by load_tests
4597.7.6 by Vincent Ladeuil
Cleanup TestParametrizedResolveConflicts some more.
271
    _base_actions = None
4597.10.7 by Vincent Ladeuil
Simplify scenarios mirroring and give a better docstring for TestParametrizedResolveConflicts.
272
    _this = None
273
    _other = None
4597.7.7 by Vincent Ladeuil
Reproduce bug #531967 on various aspects.
274
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
275
    scenarios = []
276
    """The scenario list for the conflict type defined by the class.
277
278
    Each scenario is of the form:
279
    (common, (left_name, left_dict), (right_name, right_dict))
280
281
    * common is a dict
282
283
    * left_name and right_name are the scenario names that will be combined
284
285
    * left_dict and right_dict are the attributes specific to each half of
286
      the scenario. They should include at least 'actions' and 'check' and
287
      will be available as '_this' and '_other' test instance attributes.
288
289
    Daughters classes are free to add their specific attributes as they see
290
    fit in any of the three dicts.
291
292
    This is a class method so that load_tests can find it.
293
294
    '_base_actions' in the common dict, 'actions' and 'check' in the left
295
    and right dicts use names that map to methods in the test classes. Some
296
    prefixes are added to these names to get the correspong methods (see
297
    _get_actions() and _get_check()). The motivation here is to avoid
298
    collisions in the class namespace.
299
    """
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
300
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
301
    def setUp(self):
4597.7.4 by Vincent Ladeuil
Abstract the test class some more to address more conflict
302
        super(TestParametrizedResolveConflicts, self).setUp()
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
303
        builder = self.make_branch_builder('trunk')
304
        builder.start_series()
4597.7.6 by Vincent Ladeuil
Cleanup TestParametrizedResolveConflicts some more.
305
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
306
        # Create an empty trunk
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
307
        builder.build_snapshot(None, [
7143.15.2 by Jelmer Vernooij
Run autopep8.
308
            ('add', (u'', b'root-id', 'directory', ''))],
309
            revision_id=b'start')
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
310
        # Add a minimal base content
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
311
        base_actions = self._get_actions(self._base_actions)()
6973.11.7 by Jelmer Vernooij
Fix more tests.
312
        builder.build_snapshot([b'start'], base_actions, revision_id=b'base')
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
313
        # Modify the base content in branch
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
314
        actions_other = self._get_actions(self._other['actions'])()
6973.11.7 by Jelmer Vernooij
Fix more tests.
315
        builder.build_snapshot([b'base'], actions_other, revision_id=b'other')
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
316
        # Modify the base content in trunk
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
317
        actions_this = self._get_actions(self._this['actions'])()
6973.11.7 by Jelmer Vernooij
Fix more tests.
318
        builder.build_snapshot([b'base'], actions_this, revision_id=b'this')
4597.7.7 by Vincent Ladeuil
Reproduce bug #531967 on various aspects.
319
        # builder.get_branch() tip is now 'this'
4597.7.6 by Vincent Ladeuil
Cleanup TestParametrizedResolveConflicts some more.
320
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
321
        builder.finish_series()
322
        self.builder = builder
323
4597.2.26 by Vincent Ladeuil
Fix bug #529968 by renaming the kept file on content conflicts.
324
    def _get_actions(self, name):
325
        return getattr(self, 'do_%s' % name)
326
327
    def _get_check(self, name):
328
        return getattr(self, 'check_%s' % name)
329
4597.2.24 by Vincent Ladeuil
Translate one more test.
330
    def _merge_other_into_this(self):
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
331
        b = self.builder.get_branch()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
332
        wt = b.controldir.sprout('branch').open_workingtree()
6973.11.7 by Jelmer Vernooij
Fix more tests.
333
        wt.merge_from_branch(b, b'other')
4597.2.24 by Vincent Ladeuil
Translate one more test.
334
        return wt
335
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
336
    def assertConflict(self, wt):
337
        confs = wt.conflicts()
338
        self.assertLength(1, confs)
339
        c = confs[0]
340
        self.assertIsInstance(c, self._conflict_type)
341
        self._assert_conflict(wt, c)
342
343
    def _get_resolve_path_arg(self, wt, action):
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
344
        raise NotImplementedError(self._get_resolve_path_arg)
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
345
346
    def check_resolved(self, wt, action):
347
        path = self._get_resolve_path_arg(wt, action)
348
        conflicts.resolve(wt, [path], action=action)
349
        # Check that we don't have any conflicts nor unknown left
350
        self.assertLength(0, wt.conflicts())
351
        self.assertLength(0, list(wt.unknowns()))
352
4597.2.24 by Vincent Ladeuil
Translate one more test.
353
    def test_resolve_taking_this(self):
354
        wt = self._merge_other_into_this()
4597.7.7 by Vincent Ladeuil
Reproduce bug #531967 on various aspects.
355
        self.assertConflict(wt)
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
356
        self.check_resolved(wt, 'take_this')
4597.10.7 by Vincent Ladeuil
Simplify scenarios mirroring and give a better docstring for TestParametrizedResolveConflicts.
357
        check_this = self._get_check(self._this['check'])
4597.2.26 by Vincent Ladeuil
Fix bug #529968 by renaming the kept file on content conflicts.
358
        check_this()
4597.2.24 by Vincent Ladeuil
Translate one more test.
359
360
    def test_resolve_taking_other(self):
361
        wt = self._merge_other_into_this()
4597.7.7 by Vincent Ladeuil
Reproduce bug #531967 on various aspects.
362
        self.assertConflict(wt)
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
363
        self.check_resolved(wt, 'take_other')
4597.10.7 by Vincent Ladeuil
Simplify scenarios mirroring and give a better docstring for TestParametrizedResolveConflicts.
364
        check_other = self._get_check(self._other['check'])
4597.2.26 by Vincent Ladeuil
Fix bug #529968 by renaming the kept file on content conflicts.
365
        check_other()
4597.3.28 by Vincent Ladeuil
Implement --interactive for ContentsConflict.
366
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
367
4597.14.2 by Vincent Ladeuil
Implements --take-this and --take-other when resolving text conflicts
368
class TestResolveTextConflicts(TestParametrizedResolveConflicts):
369
370
    _conflict_type = conflicts.TextConflict
371
372
    # Set by the scenarios
373
    # path and file-id for the file involved in the conflict
374
    _path = None
375
    _file_id = None
376
377
    scenarios = mirror_scenarios(
378
        [
5609.17.1 by Vincent Ladeuil
Reproduce bug #715068.
379
            # File modified on both sides
4597.14.2 by Vincent Ladeuil
Implements --take-this and --take-other when resolving text conflicts
380
            (dict(_base_actions='create_file',
6973.11.7 by Jelmer Vernooij
Fix more tests.
381
                  _path='file', _file_id=b'file-id'),
4597.14.2 by Vincent Ladeuil
Implements --take-this and --take-other when resolving text conflicts
382
             ('filed_modified_A',
383
              dict(actions='modify_file_A', check='file_has_content_A')),
384
             ('file_modified_B',
385
              dict(actions='modify_file_B', check='file_has_content_B')),),
5609.17.1 by Vincent Ladeuil
Reproduce bug #715068.
386
            # File modified on both sides in dir
387
            (dict(_base_actions='create_file_in_dir',
6973.11.7 by Jelmer Vernooij
Fix more tests.
388
                  _path='dir/file', _file_id=b'file-id'),
5609.17.1 by Vincent Ladeuil
Reproduce bug #715068.
389
             ('filed_modified_A_in_dir',
6883.22.4 by Jelmer Vernooij
Fix some conflict tests.
390
              dict(actions='modify_file_A_in_dir',
5609.17.1 by Vincent Ladeuil
Reproduce bug #715068.
391
                   check='file_in_dir_has_content_A')),
392
             ('file_modified_B',
6883.22.4 by Jelmer Vernooij
Fix some conflict tests.
393
              dict(actions='modify_file_B_in_dir',
5609.17.1 by Vincent Ladeuil
Reproduce bug #715068.
394
                   check='file_in_dir_has_content_B')),),
4597.14.2 by Vincent Ladeuil
Implements --take-this and --take-other when resolving text conflicts
395
            ])
396
5609.17.1 by Vincent Ladeuil
Reproduce bug #715068.
397
    def do_create_file(self, path='file'):
6973.11.7 by Jelmer Vernooij
Fix more tests.
398
        return [('add', (path, b'file-id', 'file', b'trunk content\n'))]
4597.14.2 by Vincent Ladeuil
Implements --take-this and --take-other when resolving text conflicts
399
400
    def do_modify_file_A(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
401
        return [('modify', ('file', b'trunk content\nfeature A\n'))]
4597.14.2 by Vincent Ladeuil
Implements --take-this and --take-other when resolving text conflicts
402
403
    def do_modify_file_B(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
404
        return [('modify', ('file', b'trunk content\nfeature B\n'))]
6883.22.4 by Jelmer Vernooij
Fix some conflict tests.
405
406
    def do_modify_file_A_in_dir(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
407
        return [('modify', ('dir/file', b'trunk content\nfeature A\n'))]
6883.22.4 by Jelmer Vernooij
Fix some conflict tests.
408
409
    def do_modify_file_B_in_dir(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
410
        return [('modify', ('dir/file', b'trunk content\nfeature B\n'))]
4597.14.2 by Vincent Ladeuil
Implements --take-this and --take-other when resolving text conflicts
411
5609.17.1 by Vincent Ladeuil
Reproduce bug #715068.
412
    def check_file_has_content_A(self, path='file'):
6973.11.7 by Jelmer Vernooij
Fix more tests.
413
        self.assertFileEqual(b'trunk content\nfeature A\n',
5609.17.1 by Vincent Ladeuil
Reproduce bug #715068.
414
                             osutils.pathjoin('branch', path))
415
416
    def check_file_has_content_B(self, path='file'):
6973.11.7 by Jelmer Vernooij
Fix more tests.
417
        self.assertFileEqual(b'trunk content\nfeature B\n',
5609.17.1 by Vincent Ladeuil
Reproduce bug #715068.
418
                             osutils.pathjoin('branch', path))
419
420
    def do_create_file_in_dir(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
421
        return [('add', ('dir', b'dir-id', 'directory', '')),
7143.15.2 by Jelmer Vernooij
Run autopep8.
422
                ] + self.do_create_file('dir/file')
5609.17.1 by Vincent Ladeuil
Reproduce bug #715068.
423
424
    def check_file_in_dir_has_content_A(self):
425
        self.check_file_has_content_A('dir/file')
426
427
    def check_file_in_dir_has_content_B(self):
428
        self.check_file_has_content_B('dir/file')
4597.14.2 by Vincent Ladeuil
Implements --take-this and --take-other when resolving text conflicts
429
430
    def _get_resolve_path_arg(self, wt, action):
431
        return self._path
432
433
    def assertTextConflict(self, wt, c):
434
        self.assertEqual(self._file_id, c.file_id)
435
        self.assertEqual(self._path, c.path)
436
    _assert_conflict = assertTextConflict
437
438
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
439
class TestResolveContentsConflict(TestParametrizedResolveConflicts):
440
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
441
    _conflict_type = conflicts.ContentsConflict
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
442
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
443
    # Set by the scenarios
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
444
    # path and file-id for the file involved in the conflict
445
    _path = None
446
    _file_id = None
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
447
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
448
    scenarios = mirror_scenarios(
449
        [
4597.10.12 by Vincent Ladeuil
Some more doc.
450
            # File modified/deleted
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
451
            (dict(_base_actions='create_file',
6973.11.7 by Jelmer Vernooij
Fix more tests.
452
                  _path='file', _file_id=b'file-id'),
4597.10.12 by Vincent Ladeuil
Some more doc.
453
             ('file_modified',
454
              dict(actions='modify_file', check='file_has_more_content')),
455
             ('file_deleted',
456
              dict(actions='delete_file', check='file_doesnt_exist')),),
5988.2.1 by Vincent Ladeuil
Do not generate path conflicts if a corresponding content conflict exists
457
            # File renamed-modified/deleted
458
            (dict(_base_actions='create_file',
6973.11.7 by Jelmer Vernooij
Fix more tests.
459
                  _path='new-file', _file_id=b'file-id'),
5988.2.1 by Vincent Ladeuil
Do not generate path conflicts if a corresponding content conflict exists
460
             ('file_renamed_and_modified',
461
              dict(actions='modify_and_rename_file',
462
                   check='file_renamed_and_more_content')),
463
             ('file_deleted',
464
              dict(actions='delete_file', check='file_doesnt_exist')),),
5050.63.3 by Vincent Ladeuil
Correctly resolve content conflicts for files in subdirs
465
            # File modified/deleted in dir
466
            (dict(_base_actions='create_file_in_dir',
6973.11.7 by Jelmer Vernooij
Fix more tests.
467
                  _path='dir/file', _file_id=b'file-id'),
5050.63.3 by Vincent Ladeuil
Correctly resolve content conflicts for files in subdirs
468
             ('file_modified_in_dir',
469
              dict(actions='modify_file_in_dir',
470
                   check='file_in_dir_has_more_content')),
471
             ('file_deleted_in_dir',
6883.22.6 by Jelmer Vernooij
Fix some more tests.
472
              dict(actions='delete_file_in_dir',
5050.63.3 by Vincent Ladeuil
Correctly resolve content conflicts for files in subdirs
473
                   check='file_in_dir_doesnt_exist')),),
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
474
            ])
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
475
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
476
    def do_create_file(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
477
        return [('add', ('file', b'file-id', 'file', b'trunk content\n'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
478
479
    def do_modify_file(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
480
        return [('modify', ('file', b'trunk content\nmore content\n'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
481
5988.2.1 by Vincent Ladeuil
Do not generate path conflicts if a corresponding content conflict exists
482
    def do_modify_and_rename_file(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
483
        return [('modify', ('new-file', b'trunk content\nmore content\n')),
5988.2.1 by Vincent Ladeuil
Do not generate path conflicts if a corresponding content conflict exists
484
                ('rename', ('file', 'new-file'))]
485
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
486
    def check_file_has_more_content(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
487
        self.assertFileEqual(b'trunk content\nmore content\n', 'branch/file')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
488
5988.2.1 by Vincent Ladeuil
Do not generate path conflicts if a corresponding content conflict exists
489
    def check_file_renamed_and_more_content(self):
7143.15.2 by Jelmer Vernooij
Run autopep8.
490
        self.assertFileEqual(
491
            b'trunk content\nmore content\n', 'branch/new-file')
5988.2.1 by Vincent Ladeuil
Do not generate path conflicts if a corresponding content conflict exists
492
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
493
    def do_delete_file(self):
6883.22.5 by Jelmer Vernooij
Fix more tests.
494
        return [('unversion', 'file')]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
495
6883.22.6 by Jelmer Vernooij
Fix some more tests.
496
    def do_delete_file_in_dir(self):
497
        return [('unversion', 'dir/file')]
498
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
499
    def check_file_doesnt_exist(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
500
        self.assertPathDoesNotExist('branch/file')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
501
5050.63.3 by Vincent Ladeuil
Correctly resolve content conflicts for files in subdirs
502
    def do_create_file_in_dir(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
503
        return [('add', ('dir', b'dir-id', 'directory', '')),
504
                ('add', ('dir/file', b'file-id', 'file', b'trunk content\n'))]
5050.63.3 by Vincent Ladeuil
Correctly resolve content conflicts for files in subdirs
505
506
    def do_modify_file_in_dir(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
507
        return [('modify', ('dir/file', b'trunk content\nmore content\n'))]
5050.63.3 by Vincent Ladeuil
Correctly resolve content conflicts for files in subdirs
508
509
    def check_file_in_dir_has_more_content(self):
7143.15.2 by Jelmer Vernooij
Run autopep8.
510
        self.assertFileEqual(
511
            b'trunk content\nmore content\n', 'branch/dir/file')
5050.63.3 by Vincent Ladeuil
Correctly resolve content conflicts for files in subdirs
512
513
    def check_file_in_dir_doesnt_exist(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
514
        self.assertPathDoesNotExist('branch/dir/file')
5050.63.3 by Vincent Ladeuil
Correctly resolve content conflicts for files in subdirs
515
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
516
    def _get_resolve_path_arg(self, wt, action):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
517
        return self._path
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
518
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
519
    def assertContentsConflict(self, wt, c):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
520
        self.assertEqual(self._file_id, c.file_id)
521
        self.assertEqual(self._path, c.path)
4597.7.16 by Vincent Ladeuil
Some cleanup.
522
    _assert_conflict = assertContentsConflict
523
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
524
525
class TestResolvePathConflict(TestParametrizedResolveConflicts):
526
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
527
    _conflict_type = conflicts.PathConflict
4597.7.16 by Vincent Ladeuil
Some cleanup.
528
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
529
    def do_nothing(self):
530
        return []
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
531
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
532
    # Each side dict additionally defines:
533
    # - path path involved (can be '<deleted>')
534
    # - file-id involved
535
    scenarios = mirror_scenarios(
536
        [
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
537
            # File renamed/deleted
538
            (dict(_base_actions='create_file'),
539
             ('file_renamed',
540
              dict(actions='rename_file', check='file_renamed',
6973.11.7 by Jelmer Vernooij
Fix more tests.
541
                   path='new-file', file_id=b'file-id')),
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
542
             ('file_deleted',
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
543
              dict(actions='delete_file', check='file_doesnt_exist',
544
                   # PathConflicts deletion handling requires a special
545
                   # hard-coded value
6973.11.7 by Jelmer Vernooij
Fix more tests.
546
                   path='<deleted>', file_id=b'file-id')),),
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
547
            # File renamed/deleted in dir
548
            (dict(_base_actions='create_file_in_dir'),
549
             ('file_renamed_in_dir',
550
              dict(actions='rename_file_in_dir', check='file_in_dir_renamed',
6973.11.7 by Jelmer Vernooij
Fix more tests.
551
                   path='dir/new-file', file_id=b'file-id')),
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
552
             ('file_deleted',
6883.22.5 by Jelmer Vernooij
Fix more tests.
553
              dict(actions='delete_file_in_dir', check='file_in_dir_doesnt_exist',
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
554
                   # PathConflicts deletion handling requires a special
555
                   # hard-coded value
6973.11.7 by Jelmer Vernooij
Fix more tests.
556
                   path='<deleted>', file_id=b'file-id')),),
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
557
            # File renamed/renamed differently
558
            (dict(_base_actions='create_file'),
559
             ('file_renamed',
560
              dict(actions='rename_file', check='file_renamed',
6973.11.7 by Jelmer Vernooij
Fix more tests.
561
                   path='new-file', file_id=b'file-id')),
4597.8.4 by Vincent Ladeuil
Delete PathConflict bloackbox tests.
562
             ('file_renamed2',
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
563
              dict(actions='rename_file2', check='file_renamed2',
6973.11.7 by Jelmer Vernooij
Fix more tests.
564
                   path='new-file2', file_id=b'file-id')),),
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
565
            # Dir renamed/deleted
566
            (dict(_base_actions='create_dir'),
567
             ('dir_renamed',
568
              dict(actions='rename_dir', check='dir_renamed',
6973.11.7 by Jelmer Vernooij
Fix more tests.
569
                   path='new-dir', file_id=b'dir-id')),
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
570
             ('dir_deleted',
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
571
              dict(actions='delete_dir', check='dir_doesnt_exist',
572
                   # PathConflicts deletion handling requires a special
573
                   # hard-coded value
6973.11.7 by Jelmer Vernooij
Fix more tests.
574
                   path='<deleted>', file_id=b'dir-id')),),
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
575
            # Dir renamed/renamed differently
576
            (dict(_base_actions='create_dir'),
577
             ('dir_renamed',
578
              dict(actions='rename_dir', check='dir_renamed',
6973.11.7 by Jelmer Vernooij
Fix more tests.
579
                   path='new-dir', file_id=b'dir-id')),
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
580
             ('dir_renamed2',
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
581
              dict(actions='rename_dir2', check='dir_renamed2',
6973.11.7 by Jelmer Vernooij
Fix more tests.
582
                   path='new-dir2', file_id=b'dir-id')),),
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
583
            ])
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
584
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
585
    def do_create_file(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
586
        return [('add', ('file', b'file-id', 'file', b'trunk content\n'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
587
588
    def do_create_dir(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
589
        return [('add', ('dir', b'dir-id', 'directory', ''))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
590
591
    def do_rename_file(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
592
        return [('rename', ('file', 'new-file'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
593
594
    def check_file_renamed(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
595
        self.assertPathDoesNotExist('branch/file')
596
        self.assertPathExists('branch/new-file')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
597
598
    def do_rename_file2(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
599
        return [('rename', ('file', 'new-file2'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
600
601
    def check_file_renamed2(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
602
        self.assertPathDoesNotExist('branch/file')
603
        self.assertPathExists('branch/new-file2')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
604
605
    def do_rename_dir(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
606
        return [('rename', ('dir', 'new-dir'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
607
608
    def check_dir_renamed(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
609
        self.assertPathDoesNotExist('branch/dir')
610
        self.assertPathExists('branch/new-dir')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
611
612
    def do_rename_dir2(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
613
        return [('rename', ('dir', 'new-dir2'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
614
615
    def check_dir_renamed2(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
616
        self.assertPathDoesNotExist('branch/dir')
617
        self.assertPathExists('branch/new-dir2')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
618
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
619
    def do_delete_file(self):
6883.22.5 by Jelmer Vernooij
Fix more tests.
620
        return [('unversion', 'file')]
621
622
    def do_delete_file_in_dir(self):
623
        return [('unversion', 'dir/file')]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
624
625
    def check_file_doesnt_exist(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
626
        self.assertPathDoesNotExist('branch/file')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
627
628
    def do_delete_dir(self):
6883.22.5 by Jelmer Vernooij
Fix more tests.
629
        return [('unversion', 'dir')]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
630
631
    def check_dir_doesnt_exist(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
632
        self.assertPathDoesNotExist('branch/dir')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
633
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
634
    def do_create_file_in_dir(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
635
        return [('add', ('dir', b'dir-id', 'directory', '')),
636
                ('add', ('dir/file', b'file-id', 'file', b'trunk content\n'))]
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
637
638
    def do_rename_file_in_dir(self):
639
        return [('rename', ('dir/file', 'dir/new-file'))]
640
641
    def check_file_in_dir_renamed(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
642
        self.assertPathDoesNotExist('branch/dir/file')
643
        self.assertPathExists('branch/dir/new-file')
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
644
645
    def check_file_in_dir_doesnt_exist(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
646
        self.assertPathDoesNotExist('branch/dir/file')
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
647
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
648
    def _get_resolve_path_arg(self, wt, action):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
649
        tpath = self._this['path']
650
        opath = self._other['path']
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
651
        if tpath == '<deleted>':
652
            path = opath
653
        else:
654
            path = tpath
655
        return path
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
656
657
    def assertPathConflict(self, wt, c):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
658
        tpath = self._this['path']
659
        tfile_id = self._this['file_id']
660
        opath = self._other['path']
661
        ofile_id = self._other['file_id']
7143.15.2 by Jelmer Vernooij
Run autopep8.
662
        self.assertEqual(tfile_id, ofile_id)  # Sanity check
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
663
        self.assertEqual(tfile_id, c.file_id)
664
        self.assertEqual(tpath, c.path)
665
        self.assertEqual(opath, c.conflict_path)
4597.7.16 by Vincent Ladeuil
Some cleanup.
666
    _assert_conflict = assertPathConflict
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
667
668
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
669
class TestResolvePathConflictBefore531967(TestResolvePathConflict):
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
670
    """Same as TestResolvePathConflict but a specific conflict object.
671
    """
672
4597.7.16 by Vincent Ladeuil
Some cleanup.
673
    def assertPathConflict(self, c):
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
674
        # We create a conflict object as it was created before the fix and
675
        # inject it into the working tree, the test will exercise the
676
        # compatibility code.
677
        old_c = conflicts.PathConflict('<deleted>', self._item_path,
678
                                       file_id=None)
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
679
        wt.set_conflicts(conflicts.ConflictList([old_c]))
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
680
681
4597.8.5 by Vincent Ladeuil
Replace DuplicateEntry blackbox tests by whitebox ones.
682
class TestResolveDuplicateEntry(TestParametrizedResolveConflicts):
683
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
684
    _conflict_type = conflicts.DuplicateEntry
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
685
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
686
    scenarios = mirror_scenarios(
687
        [
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
688
            # File created with different file-ids
689
            (dict(_base_actions='nothing'),
690
             ('filea_created',
691
              dict(actions='create_file_a', check='file_content_a',
6973.11.7 by Jelmer Vernooij
Fix more tests.
692
                   path='file', file_id=b'file-a-id')),
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
693
             ('fileb_created',
694
              dict(actions='create_file_b', check='file_content_b',
6973.11.7 by Jelmer Vernooij
Fix more tests.
695
                   path='file', file_id=b'file-b-id')),),
6015.47.3 by Vincent Ladeuil
Failing tests reproducing bug #880701.
696
            # File created with different file-ids but deleted on one side
697
            (dict(_base_actions='create_file_a'),
698
             ('filea_replaced',
699
              dict(actions='replace_file_a_by_b', check='file_content_b',
6973.11.7 by Jelmer Vernooij
Fix more tests.
700
                   path='file', file_id=b'file-b-id')),
6015.47.3 by Vincent Ladeuil
Failing tests reproducing bug #880701.
701
             ('filea_modified',
702
              dict(actions='modify_file_a', check='file_new_content',
6973.11.7 by Jelmer Vernooij
Fix more tests.
703
                   path='file', file_id=b'file-a-id')),),
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
704
            ])
4597.8.5 by Vincent Ladeuil
Replace DuplicateEntry blackbox tests by whitebox ones.
705
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
706
    def do_nothing(self):
707
        return []
708
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
709
    def do_create_file_a(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
710
        return [('add', ('file', b'file-a-id', 'file', b'file a content\n'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
711
712
    def check_file_content_a(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
713
        self.assertFileEqual(b'file a content\n', 'branch/file')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
714
715
    def do_create_file_b(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
716
        return [('add', ('file', b'file-b-id', 'file', b'file b content\n'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
717
718
    def check_file_content_b(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
719
        self.assertFileEqual(b'file b content\n', 'branch/file')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
720
6015.47.3 by Vincent Ladeuil
Failing tests reproducing bug #880701.
721
    def do_replace_file_a_by_b(self):
6883.22.6 by Jelmer Vernooij
Fix some more tests.
722
        return [('unversion', 'file'),
6973.11.7 by Jelmer Vernooij
Fix more tests.
723
                ('add', ('file', b'file-b-id', 'file', b'file b content\n'))]
6015.47.3 by Vincent Ladeuil
Failing tests reproducing bug #880701.
724
725
    def do_modify_file_a(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
726
        return [('modify', ('file', b'new content\n'))]
6015.47.3 by Vincent Ladeuil
Failing tests reproducing bug #880701.
727
728
    def check_file_new_content(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
729
        self.assertFileEqual(b'new content\n', 'branch/file')
6015.47.3 by Vincent Ladeuil
Failing tests reproducing bug #880701.
730
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
731
    def _get_resolve_path_arg(self, wt, action):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
732
        return self._this['path']
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
733
4597.8.5 by Vincent Ladeuil
Replace DuplicateEntry blackbox tests by whitebox ones.
734
    def assertDuplicateEntry(self, wt, c):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
735
        tpath = self._this['path']
736
        tfile_id = self._this['file_id']
737
        opath = self._other['path']
738
        ofile_id = self._other['file_id']
7143.15.2 by Jelmer Vernooij
Run autopep8.
739
        self.assertEqual(tpath, opath)  # Sanity check
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
740
        self.assertEqual(tfile_id, c.file_id)
741
        self.assertEqual(tpath + '.moved', c.path)
742
        self.assertEqual(tpath, c.conflict_path)
4597.8.5 by Vincent Ladeuil
Replace DuplicateEntry blackbox tests by whitebox ones.
743
    _assert_conflict = assertDuplicateEntry
4597.3.19 by Vincent Ladeuil
Some failing tests.
744
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
745
746
class TestResolveUnversionedParent(TestResolveConflicts):
747
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
748
    # FIXME: Add the reverse tests: dir deleted in trunk, file added in branch
749
4597.3.30 by Vincent Ladeuil
Light changes learned while starting to understand multiple conflicts on
750
    # FIXME: While this *creates* UnversionedParent conflicts, this really only
751
    # tests MissingParent resolution :-/
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
752
    preamble = """
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
753
$ brz init trunk
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
754
...
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
755
$ cd trunk
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
756
$ mkdir dir
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
757
$ brz add -q dir
758
$ brz commit -m 'Create trunk' -q
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
759
$ echo 'trunk content' >dir/file
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
760
$ brz add -q dir/file
761
$ brz commit -q -m 'Add dir/file in trunk'
762
$ brz branch -q . -r 1 ../branch
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
763
$ cd ../branch
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
764
$ brz rm dir -q
765
$ brz commit -q -m 'Remove dir in branch'
766
$ brz merge ../trunk
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
767
2>+N  dir/
768
2>+N  dir/file
769
2>Conflict adding files to dir.  Created directory.
770
2>Conflict because dir is not versioned, but has versioned children.  Versioned directory.
771
2>2 conflicts encountered.
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
772
"""
773
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
774
    def test_take_this(self):
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
775
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
776
$ brz rm -q dir --no-backup
777
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
778
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
779
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
780
""")
781
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
782
    def test_take_other(self):
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
783
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
784
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
785
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
786
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
787
""")
788
789
790
class TestResolveMissingParent(TestResolveConflicts):
791
792
    preamble = """
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
793
$ brz init trunk
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
794
...
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
795
$ cd trunk
796
$ mkdir dir
797
$ echo 'trunk content' >dir/file
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
798
$ brz add -q
799
$ brz commit -m 'Create trunk' -q
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
800
$ echo 'trunk content' >dir/file2
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
801
$ brz add -q dir/file2
802
$ brz commit -q -m 'Add dir/file2 in branch'
803
$ brz branch -q . -r 1 ../branch
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
804
$ cd ../branch
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
805
$ brz rm -q dir/file --no-backup
806
$ brz rm -q dir
807
$ brz commit -q -m 'Remove dir/file'
808
$ brz merge ../trunk
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
809
2>+N  dir/
810
2>+N  dir/file2
811
2>Conflict adding files to dir.  Created directory.
812
2>Conflict because dir is not versioned, but has versioned children.  Versioned directory.
813
2>2 conflicts encountered.
814
"""
815
816
    def test_keep_them_all(self):
817
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
818
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
819
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
820
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
821
""")
822
823
    def test_adopt_child(self):
824
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
825
$ brz mv -q dir/file2 file2
826
$ brz rm -q dir --no-backup
827
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
828
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
829
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
830
""")
831
832
    def test_kill_them_all(self):
833
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
834
$ brz rm -q dir --no-backup
835
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
836
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
837
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
838
""")
839
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
840
    def test_resolve_taking_this(self):
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
841
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
842
$ brz resolve --take-this dir
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
843
2>...
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
844
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
845
""")
846
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
847
    def test_resolve_taking_other(self):
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
848
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
849
$ brz resolve --take-other dir
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
850
2>...
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
851
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
852
""")
853
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
854
855
class TestResolveDeletingParent(TestResolveConflicts):
856
857
    preamble = """
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
858
$ brz init trunk
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
859
...
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
860
$ cd trunk
861
$ mkdir dir
862
$ echo 'trunk content' >dir/file
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
863
$ brz add -q
864
$ brz commit -m 'Create trunk' -q
865
$ brz rm -q dir/file --no-backup
866
$ brz rm -q dir --no-backup
867
$ brz commit -q -m 'Remove dir/file'
868
$ brz branch -q . -r 1 ../branch
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
869
$ cd ../branch
870
$ echo 'branch content' >dir/file2
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
871
$ brz add -q dir/file2
872
$ brz commit -q -m 'Add dir/file2 in branch'
873
$ brz merge ../trunk
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
874
2>-D  dir/file
875
2>Conflict: can't delete dir because it is not empty.  Not deleting.
876
2>Conflict because dir is not versioned, but has versioned children.  Versioned directory.
877
2>2 conflicts encountered.
878
"""
879
880
    def test_keep_them_all(self):
881
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
882
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
883
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
884
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
885
""")
886
887
    def test_adopt_child(self):
888
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
889
$ brz mv -q dir/file2 file2
890
$ brz rm -q dir --no-backup
891
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
892
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
893
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
894
""")
895
896
    def test_kill_them_all(self):
897
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
898
$ brz rm -q dir --no-backup
899
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
900
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
901
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
902
""")
903
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
904
    def test_resolve_taking_this(self):
4597.3.32 by Vincent Ladeuil
Implement --interactive for DeletingParent noting the inconsistency.
905
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
906
$ brz resolve --take-this dir
6138.3.5 by Jonathan Riddell
make the test suite pass
907
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
908
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.32 by Vincent Ladeuil
Implement --interactive for DeletingParent noting the inconsistency.
909
""")
910
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
911
    def test_resolve_taking_other(self):
4597.3.32 by Vincent Ladeuil
Implement --interactive for DeletingParent noting the inconsistency.
912
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
913
$ brz resolve --take-other dir
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
914
2>deleted dir/file2
915
2>deleted dir
6138.3.5 by Jonathan Riddell
make the test suite pass
916
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
917
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.32 by Vincent Ladeuil
Implement --interactive for DeletingParent noting the inconsistency.
918
""")
919
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
920
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
921
class TestResolveParentLoop(TestParametrizedResolveConflicts):
922
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
923
    _conflict_type = conflicts.ParentLoop
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
924
925
    _this_args = None
926
    _other_args = None
927
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
928
    # Each side dict additionally defines:
929
    # - dir_id: the directory being moved
930
    # - target_id: The target directory
931
    # - xfail: whether the test is expected to fail if the action is
932
    #   involved as 'other'
933
    scenarios = mirror_scenarios(
934
        [
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
935
            # Dirs moved into each other
936
            (dict(_base_actions='create_dir1_dir2'),
937
             ('dir1_into_dir2',
938
              dict(actions='move_dir1_into_dir2', check='dir1_moved',
7058.4.6 by Jelmer Vernooij
Fix some conflict tests.
939
                   dir_id=b'dir1-id', target_id=b'dir2-id', xfail=False)),
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
940
             ('dir2_into_dir1',
941
              dict(actions='move_dir2_into_dir1', check='dir2_moved',
7058.4.6 by Jelmer Vernooij
Fix some conflict tests.
942
                   dir_id=b'dir2-id', target_id=b'dir1-id', xfail=False))),
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
943
            # Subdirs moved into each other
944
            (dict(_base_actions='create_dir1_4'),
945
             ('dir1_into_dir4',
946
              dict(actions='move_dir1_into_dir4', check='dir1_2_moved',
7058.4.6 by Jelmer Vernooij
Fix some conflict tests.
947
                   dir_id=b'dir1-id', target_id=b'dir4-id', xfail=True)),
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
948
             ('dir3_into_dir2',
949
              dict(actions='move_dir3_into_dir2', check='dir3_4_moved',
7058.4.6 by Jelmer Vernooij
Fix some conflict tests.
950
                   dir_id=b'dir3-id', target_id=b'dir2-id', xfail=True))),
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
951
            ])
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
952
953
    def do_create_dir1_dir2(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
954
        return [('add', ('dir1', b'dir1-id', 'directory', '')),
7143.15.2 by Jelmer Vernooij
Run autopep8.
955
                ('add', ('dir2', b'dir2-id', 'directory', '')), ]
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
956
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
957
    def do_move_dir1_into_dir2(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
958
        return [('rename', ('dir1', 'dir2/dir1'))]
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
959
960
    def check_dir1_moved(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
961
        self.assertPathDoesNotExist('branch/dir1')
962
        self.assertPathExists('branch/dir2/dir1')
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
963
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
964
    def do_move_dir2_into_dir1(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
965
        return [('rename', ('dir2', 'dir1/dir2'))]
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
966
967
    def check_dir2_moved(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
968
        self.assertPathDoesNotExist('branch/dir2')
969
        self.assertPathExists('branch/dir1/dir2')
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
970
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
971
    def do_create_dir1_4(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
972
        return [('add', ('dir1', b'dir1-id', 'directory', '')),
973
                ('add', ('dir1/dir2', b'dir2-id', 'directory', '')),
974
                ('add', ('dir3', b'dir3-id', 'directory', '')),
7143.15.2 by Jelmer Vernooij
Run autopep8.
975
                ('add', ('dir3/dir4', b'dir4-id', 'directory', '')), ]
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
976
977
    def do_move_dir1_into_dir4(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
978
        return [('rename', ('dir1', 'dir3/dir4/dir1'))]
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
979
980
    def check_dir1_2_moved(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
981
        self.assertPathDoesNotExist('branch/dir1')
982
        self.assertPathExists('branch/dir3/dir4/dir1')
983
        self.assertPathExists('branch/dir3/dir4/dir1/dir2')
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
984
985
    def do_move_dir3_into_dir2(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
986
        return [('rename', ('dir3', 'dir1/dir2/dir3'))]
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
987
988
    def check_dir3_4_moved(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
989
        self.assertPathDoesNotExist('branch/dir3')
990
        self.assertPathExists('branch/dir1/dir2/dir3')
991
        self.assertPathExists('branch/dir1/dir2/dir3/dir4')
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
992
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
993
    def _get_resolve_path_arg(self, wt, action):
4597.10.9 by Vincent Ladeuil
More doc.
994
        # ParentLoop says: moving <conflict_path> into <path>. Cancelled move.
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
995
        # But since <path> doesn't exist in the working tree, we need to use
4597.10.9 by Vincent Ladeuil
More doc.
996
        # <conflict_path> instead, and that, in turn, is given by dir_id. Pfew.
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
997
        return wt.id2path(self._other['dir_id'])
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
998
999
    def assertParentLoop(self, wt, c):
7045.5.4 by Jelmer Vernooij
Fix a few more tests.
1000
        self.assertEqual(self._other['dir_id'], c.file_id)
1001
        self.assertEqual(self._other['target_id'], c.conflict_file_id)
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
1002
        # The conflict paths are irrelevant (they are deterministic but not
1003
        # worth checking since they don't provide the needed information
1004
        # anyway)
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
1005
        if self._other['xfail']:
1006
            # It's a bit hackish to raise from here relying on being called for
1007
            # both tests but this avoid overriding test_resolve_taking_other
6050.1.2 by Martin
Make tests raising KnownFailure use the knownFailure method instead
1008
            self.knownFailure(
4597.10.4 by Vincent Ladeuil
Handle TestResolveParentLoop expected failures more precisely.
1009
                "ParentLoop doesn't carry enough info to resolve --take-other")
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
1010
    _assert_conflict = assertParentLoop
1011
1012
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
1013
class TestResolveNonDirectoryParent(TestResolveConflicts):
1014
1015
    preamble = """
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1016
$ brz init trunk
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1017
...
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1018
$ cd trunk
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1019
$ brz mkdir foo
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1020
...
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1021
$ brz commit -m 'Create trunk' -q
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1022
$ echo "Boing" >foo/bar
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1023
$ brz add -q foo/bar
1024
$ brz commit -q -m 'Add foo/bar'
1025
$ brz branch -q . -r 1 ../branch
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1026
$ cd ../branch
1027
$ rm -r foo
1028
$ echo "Boo!" >foo
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1029
$ brz commit -q -m 'foo is now a file'
1030
$ brz merge ../trunk
7058.3.2 by Jelmer Vernooij
More consistent output.
1031
2>RK  foo => foo.new/
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
1032
2>+N  foo.new/bar
1033
# FIXME: The message is misleading, foo.new *is* a directory when the message
1034
# is displayed -- vila 090916
1035
2>Conflict: foo.new is not a directory, but has files in it.  Created directory.
1036
2>1 conflicts encountered.
1037
"""
1038
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1039
    def test_take_this(self):
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
1040
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1041
$ brz rm -q foo.new --no-backup
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
1042
# FIXME: Isn't it weird that foo is now unkown even if foo.new has been put
1043
# aside ? -- vila 090916
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1044
$ brz add -q foo
1045
$ brz resolve foo.new
6138.3.5 by Jonathan Riddell
make the test suite pass
1046
2>1 conflict resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1047
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
1048
""")
1049
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1050
    def test_take_other(self):
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1051
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1052
$ brz rm -q foo --no-backup
1053
$ brz mv -q foo.new foo
1054
$ brz resolve foo
6138.3.5 by Jonathan Riddell
make the test suite pass
1055
2>1 conflict resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1056
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1057
""")
1058
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1059
    def test_resolve_taking_this(self):
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1060
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1061
$ brz resolve --take-this foo.new
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1062
2>...
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1063
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1064
""")
1065
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1066
    def test_resolve_taking_other(self):
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1067
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1068
$ brz resolve --take-other foo.new
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1069
2>...
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1070
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1071
""")
1072
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
1073
1074
class TestMalformedTransform(script.TestCaseWithTransportAndScript):
1075
1076
    def test_bug_430129(self):
1077
        # This is nearly like TestResolveNonDirectoryParent but with branch and
1078
        # trunk switched. As such it should certainly produce the same
1079
        # conflict.
6015.47.1 by Vincent Ladeuil
Turn MalformedTransform into an InternalBzrError so users get a traceback.
1080
        self.assertRaises(errors.MalformedTransform,
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
1081
                          self.run_script, """
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1082
$ brz init trunk
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1083
...
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1084
$ cd trunk
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1085
$ brz mkdir foo
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1086
...
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1087
$ brz commit -m 'Create trunk' -q
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1088
$ rm -r foo
1089
$ echo "Boo!" >foo
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1090
$ brz commit -m 'foo is now a file' -q
1091
$ brz branch -q . -r 1 ../branch -q
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1092
$ cd ../branch
1093
$ echo "Boing" >foo/bar
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1094
$ brz add -q foo/bar -q
1095
$ brz commit -m 'Add foo/bar' -q
1096
$ brz merge ../trunk
1097
2>brz: ERROR: Tree transform is malformed [('unversioned executability', 'new-1')]
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
1098
""")
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
1099
5050.63.2 by Vincent Ladeuil
The file should be in a subdir to reproduce the bug.
1100
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1101
class TestNoFinalPath(script.TestCaseWithTransportAndScript):
1102
1103
    def test_bug_805809(self):
1104
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1105
$ brz init trunk
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1106
Created a standalone tree (format: 2a)
1107
$ cd trunk
1108
$ echo trunk >file
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1109
$ brz add
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1110
adding file
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1111
$ brz commit -m 'create file on trunk'
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1112
2>Committing to: .../trunk/
1113
2>added file
1114
2>Committed revision 1.
5050.73.7 by Vincent Ladeuil
Slightly simpler test.
1115
# Create a debian branch based on trunk
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1116
$ cd ..
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1117
$ brz branch trunk -r 1 debian
6143.1.4 by Jonathan Riddell
update tests
1118
2>Branched 1 revision.
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1119
$ cd debian
1120
$ mkdir dir
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1121
$ brz add
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1122
adding dir
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1123
$ brz mv file dir
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1124
file => dir/file
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1125
$ brz commit -m 'rename file to dir/file for debian'
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1126
2>Committing to: .../debian/
1127
2>added dir
1128
2>renamed file => dir/file
1129
2>Committed revision 2.
5050.73.7 by Vincent Ladeuil
Slightly simpler test.
1130
# Create an experimental branch with a new root-id
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1131
$ cd ..
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1132
$ brz init experimental
5609.49.2 by Vincent Ladeuil
Fix pqm failure.
1133
Created a standalone tree (format: 2a)
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1134
$ cd experimental
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1135
# Work around merging into empty branch not being supported
1136
# (http://pad.lv/308562)
1137
$ echo something >not-empty
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1138
$ brz add
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1139
adding not-empty
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1140
$ brz commit -m 'Add some content in experimental'
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1141
2>Committing to: .../experimental/
1142
2>added not-empty
1143
2>Committed revision 1.
5050.73.7 by Vincent Ladeuil
Slightly simpler test.
1144
# merge debian even without a common ancestor
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1145
$ brz merge ../debian -r0..2
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1146
2>+N  dir/
1147
2>+N  dir/file
1148
2>All changes applied successfully.
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1149
$ brz commit -m 'merging debian into experimental'
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1150
2>Committing to: .../experimental/
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1151
2>added dir
1152
2>added dir/file
1153
2>Committed revision 2.
5050.73.7 by Vincent Ladeuil
Slightly simpler test.
1154
# Create an ubuntu branch with yet another root-id
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1155
$ cd ..
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1156
$ brz init ubuntu
5609.49.2 by Vincent Ladeuil
Fix pqm failure.
1157
Created a standalone tree (format: 2a)
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1158
$ cd ubuntu
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1159
# Work around merging into empty branch not being supported
1160
# (http://pad.lv/308562)
1161
$ echo something >not-empty-ubuntu
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1162
$ brz add
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1163
adding not-empty-ubuntu
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1164
$ brz commit -m 'Add some content in experimental'
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1165
2>Committing to: .../ubuntu/
1166
2>added not-empty-ubuntu
1167
2>Committed revision 1.
5050.73.7 by Vincent Ladeuil
Slightly simpler test.
1168
# Also merge debian
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1169
$ brz merge ../debian -r0..2
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1170
2>+N  dir/
1171
2>+N  dir/file
1172
2>All changes applied successfully.
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1173
$ brz commit -m 'merging debian'
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1174
2>Committing to: .../ubuntu/
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1175
2>added dir
1176
2>added dir/file
1177
2>Committed revision 2.
5050.73.7 by Vincent Ladeuil
Slightly simpler test.
1178
# Now try to merge experimental
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1179
$ brz merge ../experimental
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1180
2>+N  not-empty
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1181
2>Path conflict: dir / dir
1182
2>1 conflicts encountered.
1183
""")
1184
1185
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
1186
class TestResolveActionOption(tests.TestCase):
1187
1188
    def setUp(self):
1189
        super(TestResolveActionOption, self).setUp()
1190
        self.options = [conflicts.ResolveActionOption()]
7045.4.23 by Jelmer Vernooij
Fix some help tests.
1191
        self.parser = option.get_optparser(self.options)
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
1192
1193
    def parse(self, args):
1194
        return self.parser.parse_args(args)
1195
1196
    def test_unknown_action(self):
6731.1.4 by Jelmer Vernooij
Move BadOptionValue to breezy.option.
1197
        self.assertRaises(option.BadOptionValue,
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
1198
                          self.parse, ['--action', 'take-me-to-the-moon'])
1199
1200
    def test_done(self):
1201
        opts, args = self.parse(['--action', 'done'])
7143.15.2 by Jelmer Vernooij
Run autopep8.
1202
        self.assertEqual({'action': 'done'}, opts)
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
1203
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1204
    def test_take_this(self):
1205
        opts, args = self.parse(['--action', 'take-this'])
1206
        self.assertEqual({'action': 'take_this'}, opts)
1207
        opts, args = self.parse(['--take-this'])
1208
        self.assertEqual({'action': 'take_this'}, opts)
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
1209
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1210
    def test_take_other(self):
1211
        opts, args = self.parse(['--action', 'take-other'])
1212
        self.assertEqual({'action': 'take_other'}, opts)
1213
        opts, args = self.parse(['--take-other'])
1214
        self.assertEqual({'action': 'take_other'}, opts)