/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_conflicts.py

  • Committer: Jelmer Vernooij
  • Date: 2020-08-10 15:00:17 UTC
  • mfrom: (7490.40.99 work)
  • mto: This revision was merged to the branch mainline in revision 7521.
  • Revision ID: jelmer@jelmer.uk-20200810150017-vs7xnrd1vat4iktg
Merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
 
18
17
import os
19
18
 
20
19
from .. import (
25
24
    tests,
26
25
    transform,
27
26
    )
 
27
from ..bzr import conflicts as bzr_conflicts
28
28
from . import (
29
29
    script,
30
30
    scenarios,
42
42
# u'\xe5' == a with circle
43
43
# '\xc3\xae' == u'\xee' == i with hat
44
44
# So these are u'path' and 'id' only with a circle and a hat. (shappo?)
45
 
example_conflicts = conflicts.ConflictList(
46
 
    [conflicts.MissingParent('Not deleting', u'p\xe5thg', b'\xc3\xaedg'),
47
 
     conflicts.ContentsConflict(u'p\xe5tha', None, b'\xc3\xaeda'),
48
 
     conflicts.TextConflict(u'p\xe5tha'),
49
 
     conflicts.PathConflict(u'p\xe5thb', u'p\xe5thc', b'\xc3\xaedb'),
50
 
     conflicts.DuplicateID('Unversioned existing file',
51
 
                           u'p\xe5thc', u'p\xe5thc2',
52
 
                           b'\xc3\xaedc', b'\xc3\xaedc'),
53
 
     conflicts.DuplicateEntry('Moved existing file to',
54
 
                              u'p\xe5thdd.moved', u'p\xe5thd',
55
 
                              b'\xc3\xaedd', None),
56
 
     conflicts.ParentLoop('Cancelled move', u'p\xe5the', u'p\xe5th2e',
57
 
                          None, b'\xc3\xaed2e'),
58
 
     conflicts.UnversionedParent('Versioned directory',
59
 
                                 u'p\xe5thf', b'\xc3\xaedf'),
60
 
     conflicts.NonDirectoryParent('Created directory',
61
 
                                  u'p\xe5thg', b'\xc3\xaedg'),
62
 
     ])
 
45
example_conflicts = [
 
46
     bzr_conflicts.MissingParent('Not deleting', u'p\xe5thg', b'\xc3\xaedg'),
 
47
     bzr_conflicts.ContentsConflict(u'p\xe5tha', None, b'\xc3\xaeda'),
 
48
     bzr_conflicts.TextConflict(u'p\xe5tha'),
 
49
     bzr_conflicts.PathConflict(u'p\xe5thb', u'p\xe5thc', b'\xc3\xaedb'),
 
50
     bzr_conflicts.DuplicateID('Unversioned existing file',
 
51
                               u'p\xe5thc', u'p\xe5thc2',
 
52
                               b'\xc3\xaedc', b'\xc3\xaedc'),
 
53
     bzr_conflicts.DuplicateEntry('Moved existing file to',
 
54
                                  u'p\xe5thdd.moved', u'p\xe5thd',
 
55
                                  b'\xc3\xaedd', None),
 
56
     bzr_conflicts.ParentLoop('Cancelled move', u'p\xe5the', u'p\xe5th2e',
 
57
                              None, b'\xc3\xaed2e'),
 
58
     bzr_conflicts.UnversionedParent('Versioned directory',
 
59
                                     u'p\xe5thf', b'\xc3\xaedf'),
 
60
     bzr_conflicts.NonDirectoryParent('Created directory',
 
61
                                      u'p\xe5thg', b'\xc3\xaedg'),
 
62
     ]
63
63
 
64
64
 
65
65
def vary_by_conflicts():
77
77
                                  ])
78
78
        os.mkdir('hello.OTHER')
79
79
        tree.add('hello', b'q')
80
 
        l = conflicts.ConflictList([conflicts.TextConflict('hello')])
 
80
        l = conflicts.ConflictList([bzr_conflicts.TextConflict('hello')])
81
81
        l.remove_files(tree)
82
82
 
83
83
    def test_select_conflicts(self):
89
89
                (not_selected, selected),
90
90
                tree_conflicts.select_conflicts(tree, paths, **kwargs))
91
91
 
92
 
        foo = conflicts.ContentsConflict('foo')
93
 
        bar = conflicts.ContentsConflict('bar')
 
92
        foo = bzr_conflicts.ContentsConflict('foo')
 
93
        bar = bzr_conflicts.ContentsConflict('bar')
94
94
        tree_conflicts = clist([foo, bar])
95
95
 
96
96
        check_select(clist([bar]), clist([foo]), ['foo'])
97
97
        check_select(clist(), tree_conflicts,
98
98
                     [''], ignore_misses=True, recurse=True)
99
99
 
100
 
        foobaz = conflicts.ContentsConflict('foo/baz')
 
100
        foobaz = bzr_conflicts.ContentsConflict('foo/baz')
101
101
        tree_conflicts = clist([foobaz, bar])
102
102
 
103
103
        check_select(clist([bar]), clist([foobaz]),
104
104
                     ['foo'], ignore_misses=True, recurse=True)
105
105
 
106
 
        qux = conflicts.PathConflict('qux', 'foo/baz')
 
106
        qux = bzr_conflicts.PathConflict('qux', 'foo/baz')
107
107
        tree_conflicts = clist([qux])
108
108
 
109
 
        check_select(clist(), tree_conflicts,
 
109
        check_select(tree_conflicts, clist(),
110
110
                     ['foo'], ignore_misses=True, recurse=True)
111
111
        check_select(tree_conflicts, clist(), ['foo'], ignore_misses=True)
112
112
 
115
115
        self.build_tree(['dir/', 'dir/hello'])
116
116
        tree.add(['dir', 'dir/hello'])
117
117
 
118
 
        dirhello = conflicts.ConflictList(
119
 
            [conflicts.TextConflict('dir/hello')])
 
118
        dirhello = [bzr_conflicts.TextConflict('dir/hello')]
120
119
        tree.set_conflicts(dirhello)
121
120
 
122
121
        conflicts.resolve(tree, ['dir'], recursive=False, ignore_misses=True)
137
136
        self.assertContainsString(repr(self.conflict),
138
137
                                  self.conflict.__class__.__name__)
139
138
 
140
 
    def test_stanza_roundtrip(self):
141
 
        p = self.conflict
142
 
        o = conflicts.Conflict.factory(**p.as_stanza().as_dict())
143
 
        self.assertEqual(o, p)
144
 
 
145
 
        self.assertIsInstance(o.path, str)
146
 
 
147
 
        if o.file_id is not None:
148
 
            self.assertIsInstance(o.file_id, bytes)
149
 
 
150
 
        conflict_path = getattr(o, 'conflict_path', None)
151
 
        if conflict_path is not None:
152
 
            self.assertIsInstance(conflict_path, str)
153
 
 
154
 
        conflict_file_id = getattr(o, 'conflict_file_id', None)
155
 
        if conflict_file_id is not None:
156
 
            self.assertIsInstance(conflict_file_id, bytes)
157
 
 
158
 
    def test_stanzification(self):
159
 
        stanza = self.conflict.as_stanza()
160
 
        if 'file_id' in stanza:
161
 
            # In Stanza form, the file_id has to be unicode.
162
 
            self.assertStartsWith(stanza['file_id'], u'\xeed')
163
 
        self.assertStartsWith(stanza['path'], u'p\xe5th')
164
 
        if 'conflict_path' in stanza:
165
 
            self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
166
 
        if 'conflict_file_id' in stanza:
167
 
            self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
168
 
 
169
139
 
170
140
class TestConflictList(tests.TestCase):
171
141
 
172
142
    def test_stanzas_roundtrip(self):
173
 
        stanzas_iter = example_conflicts.to_stanzas()
174
 
        processed = conflicts.ConflictList.from_stanzas(stanzas_iter)
 
143
        stanzas_iter = bzr_conflicts.ConflictList(example_conflicts).to_stanzas()
 
144
        processed = bzr_conflicts.ConflictList.from_stanzas(stanzas_iter)
175
145
        self.assertEqual(example_conflicts, processed)
176
146
 
177
147
    def test_stringification(self):
178
 
        for text, o in zip(example_conflicts.to_strings(), example_conflicts):
179
 
            self.assertEqual(text, str(o))
 
148
        for text, o in zip(
 
149
                bzr_conflicts.ConflictList(example_conflicts).to_strings(),
 
150
                example_conflicts):
 
151
            self.assertEqual(text, text_type(o))
180
152
 
181
153
 
182
154
# FIXME: The shell-like tests should be converted to real whitebox tests... or
367
339
 
368
340
class TestResolveTextConflicts(TestParametrizedResolveConflicts):
369
341
 
370
 
    _conflict_type = conflicts.TextConflict
 
342
    _conflict_type = bzr_conflicts.TextConflict
371
343
 
372
344
    # Set by the scenarios
373
345
    # path and file-id for the file involved in the conflict
438
410
 
439
411
class TestResolveContentsConflict(TestParametrizedResolveConflicts):
440
412
 
441
 
    _conflict_type = conflicts.ContentsConflict
 
413
    _conflict_type = bzr_conflicts.ContentsConflict
442
414
 
443
415
    # Set by the scenarios
444
416
    # path and file-id for the file involved in the conflict
524
496
 
525
497
class TestResolvePathConflict(TestParametrizedResolveConflicts):
526
498
 
527
 
    _conflict_type = conflicts.PathConflict
 
499
    _conflict_type = bzr_conflicts.PathConflict
528
500
 
529
501
    def do_nothing(self):
530
502
        return []
674
646
        # We create a conflict object as it was created before the fix and
675
647
        # inject it into the working tree, the test will exercise the
676
648
        # compatibility code.
677
 
        old_c = conflicts.PathConflict('<deleted>', self._item_path,
 
649
        old_c = bzr_conflicts.PathConflict('<deleted>', self._item_path,
678
650
                                       file_id=None)
679
 
        wt.set_conflicts(conflicts.ConflictList([old_c]))
 
651
        wt.set_conflicts([old_c])
680
652
 
681
653
 
682
654
class TestResolveDuplicateEntry(TestParametrizedResolveConflicts):
683
655
 
684
 
    _conflict_type = conflicts.DuplicateEntry
 
656
    _conflict_type = bzr_conflicts.DuplicateEntry
685
657
 
686
658
    scenarios = mirror_scenarios(
687
659
        [
920
892
 
921
893
class TestResolveParentLoop(TestParametrizedResolveConflicts):
922
894
 
923
 
    _conflict_type = conflicts.ParentLoop
 
895
    _conflict_type = bzr_conflicts.ParentLoop
924
896
 
925
897
    _this_args = None
926
898
    _other_args = None