/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'),
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
53
    conflicts.DuplicateEntry('Moved existing file to',
54
                             u'p\xe5thdd.moved', u'p\xe5thd',
7058.4.6 by Jelmer Vernooij
Fix some conflict tests.
55
                             b'\xc3\xaedd', None),
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
56
    conflicts.ParentLoop('Cancelled move', u'p\xe5the', u'p\xe5th2e',
7058.4.6 by Jelmer Vernooij
Fix some conflict tests.
57
                         None, b'\xc3\xaed2e'),
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
58
    conflicts.UnversionedParent('Versioned directory',
7058.4.6 by Jelmer Vernooij
Fix some conflict tests.
59
                                u'p\xe5thf', b'\xc3\xaedf'),
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
60
    conflicts.NonDirectoryParent('Created directory',
7058.4.6 by Jelmer Vernooij
Fix some conflict tests.
61
                                 u'p\xe5thg', b'\xc3\xaedg'),
1534.10.22 by Aaron Bentley
Got ConflictList implemented
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
100
        foobaz  = conflicts.ContentsConflict('foo/baz')
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)
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
118
        dirhello = conflicts.ConflictList([conflicts.TextConflict('dir/hello')])
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):
6973.6.2 by Jelmer Vernooij
Fix more tests.
133
        text = text_type(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),
137
            self.conflict.__class__.__name__)
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
6973.6.2 by Jelmer Vernooij
Fix more tests.
144
        self.assertIsInstance(o.path, text_type)
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:
6973.6.2 by Jelmer Vernooij
Fix more tests.
151
            self.assertIsInstance(conflict_path, text_type)
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):
6973.6.2 by Jelmer Vernooij
Fix more tests.
178
            self.assertEqual(text, text_type(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
189
    preamble = None # The setup script set by daughter classes
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, [
6973.6.4 by Jelmer Vernooij
Avoid text_type()
307
                ('add', (u'', b'root-id', 'directory', ''))],
6973.5.2 by Jelmer Vernooij
Add more bees.
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', '')),
5609.17.1 by Vincent Ladeuil
Reproduce bug #715068.
421
            ] + self.do_create_file('dir/file')
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):
6973.11.7 by Jelmer Vernooij
Fix more tests.
489
        self.assertFileEqual(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
490
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
491
    def do_delete_file(self):
6883.22.5 by Jelmer Vernooij
Fix more tests.
492
        return [('unversion', 'file')]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
493
6883.22.6 by Jelmer Vernooij
Fix some more tests.
494
    def do_delete_file_in_dir(self):
495
        return [('unversion', 'dir/file')]
496
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
497
    def check_file_doesnt_exist(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
498
        self.assertPathDoesNotExist('branch/file')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
499
5050.63.3 by Vincent Ladeuil
Correctly resolve content conflicts for files in subdirs
500
    def do_create_file_in_dir(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
501
        return [('add', ('dir', b'dir-id', 'directory', '')),
502
                ('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
503
504
    def do_modify_file_in_dir(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
505
        return [('modify', ('dir/file', b'trunk content\nmore content\n'))]
5050.63.3 by Vincent Ladeuil
Correctly resolve content conflicts for files in subdirs
506
507
    def check_file_in_dir_has_more_content(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
508
        self.assertFileEqual(b'trunk content\nmore content\n', 'branch/dir/file')
5050.63.3 by Vincent Ladeuil
Correctly resolve content conflicts for files in subdirs
509
510
    def check_file_in_dir_doesnt_exist(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
511
        self.assertPathDoesNotExist('branch/dir/file')
5050.63.3 by Vincent Ladeuil
Correctly resolve content conflicts for files in subdirs
512
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
513
    def _get_resolve_path_arg(self, wt, action):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
514
        return self._path
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
515
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
516
    def assertContentsConflict(self, wt, c):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
517
        self.assertEqual(self._file_id, c.file_id)
518
        self.assertEqual(self._path, c.path)
4597.7.16 by Vincent Ladeuil
Some cleanup.
519
    _assert_conflict = assertContentsConflict
520
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
521
522
class TestResolvePathConflict(TestParametrizedResolveConflicts):
523
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
524
    _conflict_type = conflicts.PathConflict
4597.7.16 by Vincent Ladeuil
Some cleanup.
525
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
526
    def do_nothing(self):
527
        return []
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
528
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
529
    # Each side dict additionally defines:
530
    # - path path involved (can be '<deleted>')
531
    # - file-id involved
532
    scenarios = mirror_scenarios(
533
        [
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
534
            # File renamed/deleted
535
            (dict(_base_actions='create_file'),
536
             ('file_renamed',
537
              dict(actions='rename_file', check='file_renamed',
6973.11.7 by Jelmer Vernooij
Fix more tests.
538
                   path='new-file', file_id=b'file-id')),
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
539
             ('file_deleted',
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
540
              dict(actions='delete_file', check='file_doesnt_exist',
541
                   # PathConflicts deletion handling requires a special
542
                   # hard-coded value
6973.11.7 by Jelmer Vernooij
Fix more tests.
543
                   path='<deleted>', file_id=b'file-id')),),
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
544
            # File renamed/deleted in dir
545
            (dict(_base_actions='create_file_in_dir'),
546
             ('file_renamed_in_dir',
547
              dict(actions='rename_file_in_dir', check='file_in_dir_renamed',
6973.11.7 by Jelmer Vernooij
Fix more tests.
548
                   path='dir/new-file', file_id=b'file-id')),
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
549
             ('file_deleted',
6883.22.5 by Jelmer Vernooij
Fix more tests.
550
              dict(actions='delete_file_in_dir', check='file_in_dir_doesnt_exist',
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
551
                   # PathConflicts deletion handling requires a special
552
                   # hard-coded value
6973.11.7 by Jelmer Vernooij
Fix more tests.
553
                   path='<deleted>', file_id=b'file-id')),),
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
554
            # File renamed/renamed differently
555
            (dict(_base_actions='create_file'),
556
             ('file_renamed',
557
              dict(actions='rename_file', check='file_renamed',
6973.11.7 by Jelmer Vernooij
Fix more tests.
558
                   path='new-file', file_id=b'file-id')),
4597.8.4 by Vincent Ladeuil
Delete PathConflict bloackbox tests.
559
             ('file_renamed2',
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
560
              dict(actions='rename_file2', check='file_renamed2',
6973.11.7 by Jelmer Vernooij
Fix more tests.
561
                   path='new-file2', file_id=b'file-id')),),
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
562
            # Dir renamed/deleted
563
            (dict(_base_actions='create_dir'),
564
             ('dir_renamed',
565
              dict(actions='rename_dir', check='dir_renamed',
6973.11.7 by Jelmer Vernooij
Fix more tests.
566
                   path='new-dir', file_id=b'dir-id')),
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
567
             ('dir_deleted',
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
568
              dict(actions='delete_dir', check='dir_doesnt_exist',
569
                   # PathConflicts deletion handling requires a special
570
                   # hard-coded value
6973.11.7 by Jelmer Vernooij
Fix more tests.
571
                   path='<deleted>', file_id=b'dir-id')),),
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
572
            # Dir renamed/renamed differently
573
            (dict(_base_actions='create_dir'),
574
             ('dir_renamed',
575
              dict(actions='rename_dir', check='dir_renamed',
6973.11.7 by Jelmer Vernooij
Fix more tests.
576
                   path='new-dir', file_id=b'dir-id')),
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
577
             ('dir_renamed2',
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
578
              dict(actions='rename_dir2', check='dir_renamed2',
6973.11.7 by Jelmer Vernooij
Fix more tests.
579
                   path='new-dir2', file_id=b'dir-id')),),
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
580
            ])
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
581
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
582
    def do_create_file(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
583
        return [('add', ('file', b'file-id', 'file', b'trunk content\n'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
584
585
    def do_create_dir(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
586
        return [('add', ('dir', b'dir-id', 'directory', ''))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
587
588
    def do_rename_file(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
589
        return [('rename', ('file', 'new-file'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
590
591
    def check_file_renamed(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
592
        self.assertPathDoesNotExist('branch/file')
593
        self.assertPathExists('branch/new-file')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
594
595
    def do_rename_file2(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
596
        return [('rename', ('file', 'new-file2'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
597
598
    def check_file_renamed2(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
599
        self.assertPathDoesNotExist('branch/file')
600
        self.assertPathExists('branch/new-file2')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
601
602
    def do_rename_dir(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
603
        return [('rename', ('dir', 'new-dir'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
604
605
    def check_dir_renamed(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
606
        self.assertPathDoesNotExist('branch/dir')
607
        self.assertPathExists('branch/new-dir')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
608
609
    def do_rename_dir2(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
610
        return [('rename', ('dir', 'new-dir2'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
611
612
    def check_dir_renamed2(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
613
        self.assertPathDoesNotExist('branch/dir')
614
        self.assertPathExists('branch/new-dir2')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
615
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
616
    def do_delete_file(self):
6883.22.5 by Jelmer Vernooij
Fix more tests.
617
        return [('unversion', 'file')]
618
619
    def do_delete_file_in_dir(self):
620
        return [('unversion', 'dir/file')]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
621
622
    def check_file_doesnt_exist(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
623
        self.assertPathDoesNotExist('branch/file')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
624
625
    def do_delete_dir(self):
6883.22.5 by Jelmer Vernooij
Fix more tests.
626
        return [('unversion', 'dir')]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
627
628
    def check_dir_doesnt_exist(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
629
        self.assertPathDoesNotExist('branch/dir')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
630
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
631
    def do_create_file_in_dir(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
632
        return [('add', ('dir', b'dir-id', 'directory', '')),
633
                ('add', ('dir/file', b'file-id', 'file', b'trunk content\n'))]
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
634
635
    def do_rename_file_in_dir(self):
636
        return [('rename', ('dir/file', 'dir/new-file'))]
637
638
    def check_file_in_dir_renamed(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
639
        self.assertPathDoesNotExist('branch/dir/file')
640
        self.assertPathExists('branch/dir/new-file')
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
641
642
    def check_file_in_dir_doesnt_exist(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
643
        self.assertPathDoesNotExist('branch/dir/file')
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
644
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
645
    def _get_resolve_path_arg(self, wt, action):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
646
        tpath = self._this['path']
647
        opath = self._other['path']
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
648
        if tpath == '<deleted>':
649
            path = opath
650
        else:
651
            path = tpath
652
        return path
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
653
654
    def assertPathConflict(self, wt, c):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
655
        tpath = self._this['path']
656
        tfile_id = self._this['file_id']
657
        opath = self._other['path']
658
        ofile_id = self._other['file_id']
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
659
        self.assertEqual(tfile_id, ofile_id) # Sanity check
660
        self.assertEqual(tfile_id, c.file_id)
661
        self.assertEqual(tpath, c.path)
662
        self.assertEqual(opath, c.conflict_path)
4597.7.16 by Vincent Ladeuil
Some cleanup.
663
    _assert_conflict = assertPathConflict
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
664
665
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
666
class TestResolvePathConflictBefore531967(TestResolvePathConflict):
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
667
    """Same as TestResolvePathConflict but a specific conflict object.
668
    """
669
4597.7.16 by Vincent Ladeuil
Some cleanup.
670
    def assertPathConflict(self, c):
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
671
        # We create a conflict object as it was created before the fix and
672
        # inject it into the working tree, the test will exercise the
673
        # compatibility code.
674
        old_c = conflicts.PathConflict('<deleted>', self._item_path,
675
                                       file_id=None)
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
676
        wt.set_conflicts(conflicts.ConflictList([old_c]))
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
677
678
4597.8.5 by Vincent Ladeuil
Replace DuplicateEntry blackbox tests by whitebox ones.
679
class TestResolveDuplicateEntry(TestParametrizedResolveConflicts):
680
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
681
    _conflict_type = conflicts.DuplicateEntry
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
682
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
683
    scenarios = mirror_scenarios(
684
        [
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
685
            # File created with different file-ids
686
            (dict(_base_actions='nothing'),
687
             ('filea_created',
688
              dict(actions='create_file_a', check='file_content_a',
6973.11.7 by Jelmer Vernooij
Fix more tests.
689
                   path='file', file_id=b'file-a-id')),
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
690
             ('fileb_created',
691
              dict(actions='create_file_b', check='file_content_b',
6973.11.7 by Jelmer Vernooij
Fix more tests.
692
                   path='file', file_id=b'file-b-id')),),
6015.47.3 by Vincent Ladeuil
Failing tests reproducing bug #880701.
693
            # File created with different file-ids but deleted on one side
694
            (dict(_base_actions='create_file_a'),
695
             ('filea_replaced',
696
              dict(actions='replace_file_a_by_b', check='file_content_b',
6973.11.7 by Jelmer Vernooij
Fix more tests.
697
                   path='file', file_id=b'file-b-id')),
6015.47.3 by Vincent Ladeuil
Failing tests reproducing bug #880701.
698
             ('filea_modified',
699
              dict(actions='modify_file_a', check='file_new_content',
6973.11.7 by Jelmer Vernooij
Fix more tests.
700
                   path='file', file_id=b'file-a-id')),),
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
701
            ])
4597.8.5 by Vincent Ladeuil
Replace DuplicateEntry blackbox tests by whitebox ones.
702
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
703
    def do_nothing(self):
704
        return []
705
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
706
    def do_create_file_a(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
707
        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.
708
709
    def check_file_content_a(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
710
        self.assertFileEqual(b'file a content\n', 'branch/file')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
711
712
    def do_create_file_b(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
713
        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.
714
715
    def check_file_content_b(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
716
        self.assertFileEqual(b'file b content\n', 'branch/file')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
717
6015.47.3 by Vincent Ladeuil
Failing tests reproducing bug #880701.
718
    def do_replace_file_a_by_b(self):
6883.22.6 by Jelmer Vernooij
Fix some more tests.
719
        return [('unversion', 'file'),
6973.11.7 by Jelmer Vernooij
Fix more tests.
720
                ('add', ('file', b'file-b-id', 'file', b'file b content\n'))]
6015.47.3 by Vincent Ladeuil
Failing tests reproducing bug #880701.
721
722
    def do_modify_file_a(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
723
        return [('modify', ('file', b'new content\n'))]
6015.47.3 by Vincent Ladeuil
Failing tests reproducing bug #880701.
724
725
    def check_file_new_content(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
726
        self.assertFileEqual(b'new content\n', 'branch/file')
6015.47.3 by Vincent Ladeuil
Failing tests reproducing bug #880701.
727
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
728
    def _get_resolve_path_arg(self, wt, action):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
729
        return self._this['path']
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
730
4597.8.5 by Vincent Ladeuil
Replace DuplicateEntry blackbox tests by whitebox ones.
731
    def assertDuplicateEntry(self, wt, c):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
732
        tpath = self._this['path']
733
        tfile_id = self._this['file_id']
734
        opath = self._other['path']
735
        ofile_id = self._other['file_id']
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
736
        self.assertEqual(tpath, opath) # Sanity check
737
        self.assertEqual(tfile_id, c.file_id)
738
        self.assertEqual(tpath + '.moved', c.path)
739
        self.assertEqual(tpath, c.conflict_path)
4597.8.5 by Vincent Ladeuil
Replace DuplicateEntry blackbox tests by whitebox ones.
740
    _assert_conflict = assertDuplicateEntry
4597.3.19 by Vincent Ladeuil
Some failing tests.
741
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
742
743
class TestResolveUnversionedParent(TestResolveConflicts):
744
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
745
    # FIXME: Add the reverse tests: dir deleted in trunk, file added in branch
746
4597.3.30 by Vincent Ladeuil
Light changes learned while starting to understand multiple conflicts on
747
    # FIXME: While this *creates* UnversionedParent conflicts, this really only
748
    # tests MissingParent resolution :-/
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
749
    preamble = """
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
750
$ brz init trunk
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
751
...
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
752
$ cd trunk
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
753
$ mkdir dir
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
754
$ brz add -q dir
755
$ brz commit -m 'Create trunk' -q
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
756
$ echo 'trunk content' >dir/file
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
757
$ brz add -q dir/file
758
$ brz commit -q -m 'Add dir/file in trunk'
759
$ brz branch -q . -r 1 ../branch
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
760
$ cd ../branch
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
761
$ brz rm dir -q
762
$ brz commit -q -m 'Remove dir in branch'
763
$ brz merge ../trunk
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
764
2>+N  dir/
765
2>+N  dir/file
766
2>Conflict adding files to dir.  Created directory.
767
2>Conflict because dir is not versioned, but has versioned children.  Versioned directory.
768
2>2 conflicts encountered.
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
769
"""
770
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
771
    def test_take_this(self):
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
772
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
773
$ brz rm -q dir --no-backup
774
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
775
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
776
$ 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.
777
""")
778
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
779
    def test_take_other(self):
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
780
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
781
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
782
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
783
$ 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.
784
""")
785
786
787
class TestResolveMissingParent(TestResolveConflicts):
788
789
    preamble = """
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
790
$ brz init trunk
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
791
...
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
792
$ cd trunk
793
$ mkdir dir
794
$ echo 'trunk content' >dir/file
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
795
$ brz add -q
796
$ brz commit -m 'Create trunk' -q
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
797
$ echo 'trunk content' >dir/file2
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
798
$ brz add -q dir/file2
799
$ brz commit -q -m 'Add dir/file2 in branch'
800
$ brz branch -q . -r 1 ../branch
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
801
$ cd ../branch
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
802
$ brz rm -q dir/file --no-backup
803
$ brz rm -q dir
804
$ brz commit -q -m 'Remove dir/file'
805
$ brz merge ../trunk
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
806
2>+N  dir/
807
2>+N  dir/file2
808
2>Conflict adding files to dir.  Created directory.
809
2>Conflict because dir is not versioned, but has versioned children.  Versioned directory.
810
2>2 conflicts encountered.
811
"""
812
813
    def test_keep_them_all(self):
814
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
815
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
816
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
817
$ 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.
818
""")
819
820
    def test_adopt_child(self):
821
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
822
$ brz mv -q dir/file2 file2
823
$ brz rm -q dir --no-backup
824
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
825
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
826
$ 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.
827
""")
828
829
    def test_kill_them_all(self):
830
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
831
$ brz rm -q dir --no-backup
832
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
833
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
834
$ 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.
835
""")
836
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
837
    def test_resolve_taking_this(self):
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
838
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
839
$ 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
840
2>...
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
841
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
842
""")
843
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
844
    def test_resolve_taking_other(self):
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
845
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
846
$ 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
847
2>...
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
848
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
849
""")
850
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
851
852
class TestResolveDeletingParent(TestResolveConflicts):
853
854
    preamble = """
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
855
$ brz init trunk
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
856
...
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
857
$ cd trunk
858
$ mkdir dir
859
$ echo 'trunk content' >dir/file
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
860
$ brz add -q
861
$ brz commit -m 'Create trunk' -q
862
$ brz rm -q dir/file --no-backup
863
$ brz rm -q dir --no-backup
864
$ brz commit -q -m 'Remove dir/file'
865
$ brz branch -q . -r 1 ../branch
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
866
$ cd ../branch
867
$ echo 'branch content' >dir/file2
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
868
$ brz add -q dir/file2
869
$ brz commit -q -m 'Add dir/file2 in branch'
870
$ brz merge ../trunk
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
871
2>-D  dir/file
872
2>Conflict: can't delete dir because it is not empty.  Not deleting.
873
2>Conflict because dir is not versioned, but has versioned children.  Versioned directory.
874
2>2 conflicts encountered.
875
"""
876
877
    def test_keep_them_all(self):
878
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
879
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
880
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
881
$ 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.
882
""")
883
884
    def test_adopt_child(self):
885
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
886
$ brz mv -q dir/file2 file2
887
$ brz rm -q dir --no-backup
888
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
889
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
890
$ 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.
891
""")
892
893
    def test_kill_them_all(self):
894
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
895
$ brz rm -q dir --no-backup
896
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
897
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
898
$ 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.
899
""")
900
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
901
    def test_resolve_taking_this(self):
4597.3.32 by Vincent Ladeuil
Implement --interactive for DeletingParent noting the inconsistency.
902
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
903
$ brz resolve --take-this dir
6138.3.5 by Jonathan Riddell
make the test suite pass
904
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
905
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.32 by Vincent Ladeuil
Implement --interactive for DeletingParent noting the inconsistency.
906
""")
907
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
908
    def test_resolve_taking_other(self):
4597.3.32 by Vincent Ladeuil
Implement --interactive for DeletingParent noting the inconsistency.
909
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
910
$ 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
911
2>deleted dir/file2
912
2>deleted dir
6138.3.5 by Jonathan Riddell
make the test suite pass
913
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
914
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.32 by Vincent Ladeuil
Implement --interactive for DeletingParent noting the inconsistency.
915
""")
916
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
917
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
918
class TestResolveParentLoop(TestParametrizedResolveConflicts):
919
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
920
    _conflict_type = conflicts.ParentLoop
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
921
922
    _this_args = None
923
    _other_args = None
924
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
925
    # Each side dict additionally defines:
926
    # - dir_id: the directory being moved
927
    # - target_id: The target directory
928
    # - xfail: whether the test is expected to fail if the action is
929
    #   involved as 'other'
930
    scenarios = mirror_scenarios(
931
        [
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
932
            # Dirs moved into each other
933
            (dict(_base_actions='create_dir1_dir2'),
934
             ('dir1_into_dir2',
935
              dict(actions='move_dir1_into_dir2', check='dir1_moved',
7058.4.6 by Jelmer Vernooij
Fix some conflict tests.
936
                   dir_id=b'dir1-id', target_id=b'dir2-id', xfail=False)),
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
937
             ('dir2_into_dir1',
938
              dict(actions='move_dir2_into_dir1', check='dir2_moved',
7058.4.6 by Jelmer Vernooij
Fix some conflict tests.
939
                   dir_id=b'dir2-id', target_id=b'dir1-id', xfail=False))),
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
940
            # Subdirs moved into each other
941
            (dict(_base_actions='create_dir1_4'),
942
             ('dir1_into_dir4',
943
              dict(actions='move_dir1_into_dir4', check='dir1_2_moved',
7058.4.6 by Jelmer Vernooij
Fix some conflict tests.
944
                   dir_id=b'dir1-id', target_id=b'dir4-id', xfail=True)),
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
945
             ('dir3_into_dir2',
946
              dict(actions='move_dir3_into_dir2', check='dir3_4_moved',
7058.4.6 by Jelmer Vernooij
Fix some conflict tests.
947
                   dir_id=b'dir3-id', target_id=b'dir2-id', xfail=True))),
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
948
            ])
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
949
950
    def do_create_dir1_dir2(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
951
        return [('add', ('dir1', b'dir1-id', 'directory', '')),
952
                ('add', ('dir2', b'dir2-id', 'directory', '')),]
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
953
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
954
    def do_move_dir1_into_dir2(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
955
        return [('rename', ('dir1', 'dir2/dir1'))]
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
956
957
    def check_dir1_moved(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
958
        self.assertPathDoesNotExist('branch/dir1')
959
        self.assertPathExists('branch/dir2/dir1')
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
960
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
961
    def do_move_dir2_into_dir1(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
962
        return [('rename', ('dir2', 'dir1/dir2'))]
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
963
964
    def check_dir2_moved(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
965
        self.assertPathDoesNotExist('branch/dir2')
966
        self.assertPathExists('branch/dir1/dir2')
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
967
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
968
    def do_create_dir1_4(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
969
        return [('add', ('dir1', b'dir1-id', 'directory', '')),
970
                ('add', ('dir1/dir2', b'dir2-id', 'directory', '')),
971
                ('add', ('dir3', b'dir3-id', 'directory', '')),
972
                ('add', ('dir3/dir4', b'dir4-id', 'directory', '')),]
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
973
974
    def do_move_dir1_into_dir4(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
975
        return [('rename', ('dir1', 'dir3/dir4/dir1'))]
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
976
977
    def check_dir1_2_moved(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
978
        self.assertPathDoesNotExist('branch/dir1')
979
        self.assertPathExists('branch/dir3/dir4/dir1')
980
        self.assertPathExists('branch/dir3/dir4/dir1/dir2')
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
981
982
    def do_move_dir3_into_dir2(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
983
        return [('rename', ('dir3', 'dir1/dir2/dir3'))]
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
984
985
    def check_dir3_4_moved(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
986
        self.assertPathDoesNotExist('branch/dir3')
987
        self.assertPathExists('branch/dir1/dir2/dir3')
988
        self.assertPathExists('branch/dir1/dir2/dir3/dir4')
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
989
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
990
    def _get_resolve_path_arg(self, wt, action):
4597.10.9 by Vincent Ladeuil
More doc.
991
        # ParentLoop says: moving <conflict_path> into <path>. Cancelled move.
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
992
        # But since <path> doesn't exist in the working tree, we need to use
4597.10.9 by Vincent Ladeuil
More doc.
993
        # <conflict_path> instead, and that, in turn, is given by dir_id. Pfew.
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
994
        return wt.id2path(self._other['dir_id'])
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
995
996
    def assertParentLoop(self, wt, c):
7045.5.4 by Jelmer Vernooij
Fix a few more tests.
997
        self.assertEqual(self._other['dir_id'], c.file_id)
998
        self.assertEqual(self._other['target_id'], c.conflict_file_id)
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
999
        # The conflict paths are irrelevant (they are deterministic but not
1000
        # worth checking since they don't provide the needed information
1001
        # anyway)
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
1002
        if self._other['xfail']:
1003
            # It's a bit hackish to raise from here relying on being called for
1004
            # both tests but this avoid overriding test_resolve_taking_other
6050.1.2 by Martin
Make tests raising KnownFailure use the knownFailure method instead
1005
            self.knownFailure(
4597.10.4 by Vincent Ladeuil
Handle TestResolveParentLoop expected failures more precisely.
1006
                "ParentLoop doesn't carry enough info to resolve --take-other")
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
1007
    _assert_conflict = assertParentLoop
1008
1009
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
1010
class TestResolveNonDirectoryParent(TestResolveConflicts):
1011
1012
    preamble = """
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1013
$ brz init trunk
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1014
...
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1015
$ cd trunk
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1016
$ brz mkdir foo
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1017
...
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1018
$ brz commit -m 'Create trunk' -q
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1019
$ echo "Boing" >foo/bar
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1020
$ brz add -q foo/bar
1021
$ brz commit -q -m 'Add foo/bar'
1022
$ brz branch -q . -r 1 ../branch
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1023
$ cd ../branch
1024
$ rm -r foo
1025
$ echo "Boo!" >foo
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1026
$ brz commit -q -m 'foo is now a file'
1027
$ brz merge ../trunk
7058.3.2 by Jelmer Vernooij
More consistent output.
1028
2>RK  foo => foo.new/
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
1029
2>+N  foo.new/bar
1030
# FIXME: The message is misleading, foo.new *is* a directory when the message
1031
# is displayed -- vila 090916
1032
2>Conflict: foo.new is not a directory, but has files in it.  Created directory.
1033
2>1 conflicts encountered.
1034
"""
1035
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1036
    def test_take_this(self):
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
1037
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1038
$ brz rm -q foo.new --no-backup
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
1039
# FIXME: Isn't it weird that foo is now unkown even if foo.new has been put
1040
# aside ? -- vila 090916
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1041
$ brz add -q foo
1042
$ brz resolve foo.new
6138.3.5 by Jonathan Riddell
make the test suite pass
1043
2>1 conflict resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1044
$ 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.
1045
""")
1046
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1047
    def test_take_other(self):
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1048
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1049
$ brz rm -q foo --no-backup
1050
$ brz mv -q foo.new foo
1051
$ brz resolve foo
6138.3.5 by Jonathan Riddell
make the test suite pass
1052
2>1 conflict resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1053
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1054
""")
1055
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1056
    def test_resolve_taking_this(self):
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1057
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1058
$ 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
1059
2>...
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1060
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1061
""")
1062
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1063
    def test_resolve_taking_other(self):
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1064
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1065
$ 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
1066
2>...
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1067
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1068
""")
1069
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
1070
1071
class TestMalformedTransform(script.TestCaseWithTransportAndScript):
1072
1073
    def test_bug_430129(self):
1074
        # This is nearly like TestResolveNonDirectoryParent but with branch and
1075
        # trunk switched. As such it should certainly produce the same
1076
        # conflict.
6015.47.1 by Vincent Ladeuil
Turn MalformedTransform into an InternalBzrError so users get a traceback.
1077
        self.assertRaises(errors.MalformedTransform,
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
1078
                          self.run_script, """
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1079
$ brz init trunk
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1080
...
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1081
$ cd trunk
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1082
$ brz mkdir foo
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1083
...
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1084
$ brz commit -m 'Create trunk' -q
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1085
$ rm -r foo
1086
$ echo "Boo!" >foo
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1087
$ brz commit -m 'foo is now a file' -q
1088
$ brz branch -q . -r 1 ../branch -q
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1089
$ cd ../branch
1090
$ echo "Boing" >foo/bar
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1091
$ brz add -q foo/bar -q
1092
$ brz commit -m 'Add foo/bar' -q
1093
$ brz merge ../trunk
1094
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.
1095
""")
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
1096
5050.63.2 by Vincent Ladeuil
The file should be in a subdir to reproduce the bug.
1097
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1098
class TestNoFinalPath(script.TestCaseWithTransportAndScript):
1099
1100
    def test_bug_805809(self):
1101
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1102
$ brz init trunk
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1103
Created a standalone tree (format: 2a)
1104
$ cd trunk
1105
$ echo trunk >file
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1106
$ brz add
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1107
adding file
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1108
$ brz commit -m 'create file on trunk'
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1109
2>Committing to: .../trunk/
1110
2>added file
1111
2>Committed revision 1.
5050.73.7 by Vincent Ladeuil
Slightly simpler test.
1112
# Create a debian branch based on trunk
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1113
$ cd ..
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1114
$ brz branch trunk -r 1 debian
6143.1.4 by Jonathan Riddell
update tests
1115
2>Branched 1 revision.
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1116
$ cd debian
1117
$ mkdir dir
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1118
$ brz add
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1119
adding dir
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1120
$ brz mv file dir
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1121
file => dir/file
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1122
$ brz commit -m 'rename file to dir/file for debian'
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1123
2>Committing to: .../debian/
1124
2>added dir
1125
2>renamed file => dir/file
1126
2>Committed revision 2.
5050.73.7 by Vincent Ladeuil
Slightly simpler test.
1127
# Create an experimental branch with a new root-id
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1128
$ cd ..
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1129
$ brz init experimental
5609.49.2 by Vincent Ladeuil
Fix pqm failure.
1130
Created a standalone tree (format: 2a)
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1131
$ cd experimental
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1132
# Work around merging into empty branch not being supported
1133
# (http://pad.lv/308562)
1134
$ echo something >not-empty
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1135
$ brz add
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1136
adding not-empty
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1137
$ 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
1138
2>Committing to: .../experimental/
1139
2>added not-empty
1140
2>Committed revision 1.
5050.73.7 by Vincent Ladeuil
Slightly simpler test.
1141
# merge debian even without a common ancestor
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1142
$ brz merge ../debian -r0..2
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1143
2>+N  dir/
1144
2>+N  dir/file
1145
2>All changes applied successfully.
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1146
$ brz commit -m 'merging debian into experimental'
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1147
2>Committing to: .../experimental/
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1148
2>added dir
1149
2>added dir/file
1150
2>Committed revision 2.
5050.73.7 by Vincent Ladeuil
Slightly simpler test.
1151
# Create an ubuntu branch with yet another root-id
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1152
$ cd ..
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1153
$ brz init ubuntu
5609.49.2 by Vincent Ladeuil
Fix pqm failure.
1154
Created a standalone tree (format: 2a)
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1155
$ cd ubuntu
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1156
# Work around merging into empty branch not being supported
1157
# (http://pad.lv/308562)
1158
$ echo something >not-empty-ubuntu
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1159
$ brz add
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1160
adding not-empty-ubuntu
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1161
$ 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
1162
2>Committing to: .../ubuntu/
1163
2>added not-empty-ubuntu
1164
2>Committed revision 1.
5050.73.7 by Vincent Ladeuil
Slightly simpler test.
1165
# Also merge debian
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1166
$ brz merge ../debian -r0..2
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1167
2>+N  dir/
1168
2>+N  dir/file
1169
2>All changes applied successfully.
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1170
$ brz commit -m 'merging debian'
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1171
2>Committing to: .../ubuntu/
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1172
2>added dir
1173
2>added dir/file
1174
2>Committed revision 2.
5050.73.7 by Vincent Ladeuil
Slightly simpler test.
1175
# Now try to merge experimental
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1176
$ brz merge ../experimental
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1177
2>+N  not-empty
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1178
2>Path conflict: dir / dir
1179
2>1 conflicts encountered.
1180
""")
1181
1182
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
1183
class TestResolveActionOption(tests.TestCase):
1184
1185
    def setUp(self):
1186
        super(TestResolveActionOption, self).setUp()
1187
        self.options = [conflicts.ResolveActionOption()]
7045.4.23 by Jelmer Vernooij
Fix some help tests.
1188
        self.parser = option.get_optparser(self.options)
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
1189
1190
    def parse(self, args):
1191
        return self.parser.parse_args(args)
1192
1193
    def test_unknown_action(self):
6731.1.4 by Jelmer Vernooij
Move BadOptionValue to breezy.option.
1194
        self.assertRaises(option.BadOptionValue,
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
1195
                          self.parse, ['--action', 'take-me-to-the-moon'])
1196
1197
    def test_done(self):
1198
        opts, args = self.parse(['--action', 'done'])
1199
        self.assertEqual({'action':'done'}, opts)
1200
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1201
    def test_take_this(self):
1202
        opts, args = self.parse(['--action', 'take-this'])
1203
        self.assertEqual({'action': 'take_this'}, opts)
1204
        opts, args = self.parse(['--take-this'])
1205
        self.assertEqual({'action': 'take_this'}, opts)
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
1206
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1207
    def test_take_other(self):
1208
        opts, args = self.parse(['--action', 'take-other'])
1209
        self.assertEqual({'action': 'take_other'}, opts)
1210
        opts, args = self.parse(['--take-other'])
1211
        self.assertEqual({'action': 'take_other'}, opts)