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