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