/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_merge3.py

  • Committer: Jelmer Vernooij
  • Date: 2018-07-08 10:56:06 UTC
  • mto: This revision was merged to the branch mainline in revision 7030.
  • Revision ID: jelmer@jelmer.uk-20180708105606-d53hkks89qq88twu
Use separate .as_bytes method rather than __bytes__.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
 
from bzrlib import (
19
 
    errors,
 
18
from .. import (
20
19
    merge3,
21
20
    tests,
22
21
    )
23
 
from bzrlib.merge3 import Merge3
24
 
from bzrlib.errors import CantReprocessAndShowBase, BinaryFile
 
22
from ..errors import CantReprocessAndShowBase, BinaryFile
 
23
from ..sixish import (
 
24
    BytesIO,
 
25
    )
25
26
 
26
27
def split_lines(t):
27
 
    from cStringIO import StringIO
28
 
    return StringIO(t).readlines()
 
28
    return BytesIO(t).readlines()
29
29
 
30
30
############################################################
31
31
# test case data from the gnu diffutils manual
32
32
# common base
33
 
TZU = split_lines("""     The Nameless is the origin of Heaven and Earth;
 
33
TZU = split_lines(b"""     The Nameless is the origin of Heaven and Earth;
34
34
     The named is the mother of all things.
35
35
 
36
36
     Therefore let there always be non-being,
45
45
     The door of all subtleties!
46
46
""")
47
47
 
48
 
LAO = split_lines("""     The Way that can be told of is not the eternal Way;
 
48
LAO = split_lines(b"""     The Way that can be told of is not the eternal Way;
49
49
     The name that can be named is not the eternal name.
50
50
     The Nameless is the origin of Heaven and Earth;
51
51
     The Named is the mother of all things.
59
59
""")
60
60
 
61
61
 
62
 
TAO = split_lines("""     The Way that can be told of is not the eternal Way;
 
62
TAO = split_lines(b"""     The Way that can be told of is not the eternal Way;
63
63
     The name that can be named is not the eternal name.
64
64
     The Nameless is the origin of Heaven and Earth;
65
65
     The named is the mother of all things.
76
76
 
77
77
""")
78
78
 
79
 
MERGED_RESULT = split_lines("""     The Way that can be told of is not the eternal Way;
 
79
MERGED_RESULT = split_lines(b"""     The Way that can be told of is not the eternal Way;
80
80
     The name that can be named is not the eternal name.
81
81
     The Nameless is the origin of Heaven and Earth;
82
82
     The Named is the mother of all things.
103
103
                           ['aaa', 'bbb'],
104
104
                           ['aaa', 'bbb'])
105
105
 
106
 
        self.assertEquals(m3.find_unconflicted(),
 
106
        self.assertEqual(m3.find_unconflicted(),
107
107
                          [(0, 2)])
108
108
 
109
 
        self.assertEquals(list(m3.find_sync_regions()),
 
109
        self.assertEqual(list(m3.find_sync_regions()),
110
110
                          [(0, 2,
111
111
                            0, 2,
112
112
                            0, 2),
113
 
                           (2,2, 2,2, 2,2)])
 
113
                           (2, 2, 2, 2, 2, 2)])
114
114
 
115
 
        self.assertEquals(list(m3.merge_regions()),
 
115
        self.assertEqual(list(m3.merge_regions()),
116
116
                          [('unchanged', 0, 2)])
117
117
 
118
 
        self.assertEquals(list(m3.merge_groups()),
 
118
        self.assertEqual(list(m3.merge_groups()),
119
119
                          [('unchanged', ['aaa', 'bbb'])])
120
120
 
121
121
    def test_front_insert(self):
125
125
 
126
126
        # todo: should use a sentinal at end as from get_matching_blocks
127
127
        # to match without zz
128
 
        self.assertEquals(list(m3.find_sync_regions()),
129
 
                          [(0,1, 2,3, 0,1),
130
 
                           (1,1, 3,3, 1,1),])
 
128
        self.assertEqual(list(m3.find_sync_regions()),
 
129
                          [(0, 1, 2, 3, 0, 1),
 
130
                           (1, 1, 3, 3, 1, 1),])
131
131
 
132
 
        self.assertEquals(list(m3.merge_regions()),
 
132
        self.assertEqual(list(m3.merge_regions()),
133
133
                          [('a', 0, 2),
134
134
                           ('unchanged', 0, 1)])
135
135
 
136
 
        self.assertEquals(list(m3.merge_groups()),
 
136
        self.assertEqual(list(m3.merge_groups()),
137
137
                          [('a', ['aaa', 'bbb']),
138
138
                           ('unchanged', ['zz'])])
139
139
 
143
143
                           [])
144
144
        # todo: should use a sentinal at end as from get_matching_blocks
145
145
        # to match without zz
146
 
        self.assertEquals(list(m3.find_sync_regions()),
147
 
                          [(0,0, 2,2, 0,0)])
 
146
        self.assertEqual(list(m3.find_sync_regions()),
 
147
                          [(0, 0, 2, 2, 0, 0)])
148
148
 
149
 
        self.assertEquals(list(m3.merge_regions()),
 
149
        self.assertEqual(list(m3.merge_regions()),
150
150
                          [('a', 0, 2)])
151
151
 
152
 
        self.assertEquals(list(m3.merge_lines()),
 
152
        self.assertEqual(list(m3.merge_lines()),
153
153
                          ['aaa', 'bbb'])
154
154
 
155
155
    def test_no_conflicts(self):
158
158
                           ['aaa', '111', 'bbb'],
159
159
                           ['aaa', 'bbb'])
160
160
 
161
 
        self.assertEquals(m3.find_unconflicted(),
 
161
        self.assertEqual(m3.find_unconflicted(),
162
162
                          [(0, 1), (1, 2)])
163
163
 
164
 
        self.assertEquals(list(m3.find_sync_regions()),
165
 
                          [(0,1, 0,1, 0,1),
166
 
                           (1,2, 2,3, 1,2),
167
 
                           (2,2, 3,3, 2,2),])
 
164
        self.assertEqual(list(m3.find_sync_regions()),
 
165
                          [(0, 1, 0, 1, 0, 1),
 
166
                           (1, 2, 2, 3, 1, 2),
 
167
                           (2, 2, 3, 3, 2, 2),])
168
168
 
169
 
        self.assertEquals(list(m3.merge_regions()),
 
169
        self.assertEqual(list(m3.merge_regions()),
170
170
                          [('unchanged', 0, 1),
171
171
                           ('a', 1, 2),
172
172
                           ('unchanged', 1, 2),])
176
176
                           ['aaa\n', 'bbb\n', '222\n'],
177
177
                           ['aaa\n', 'bbb\n'])
178
178
 
179
 
        self.assertEquals(''.join(m3.merge_lines()),
 
179
        self.assertEqual(''.join(m3.merge_lines()),
180
180
                          'aaa\nbbb\n222\n')
181
181
 
182
182
    def test_append_b(self):
184
184
                           ['aaa\n', 'bbb\n'],
185
185
                           ['aaa\n', 'bbb\n', '222\n'])
186
186
 
187
 
        self.assertEquals(''.join(m3.merge_lines()),
 
187
        self.assertEqual(''.join(m3.merge_lines()),
188
188
                          'aaa\nbbb\n222\n')
189
189
 
190
190
    def test_append_agreement(self):
192
192
                           ['aaa\n', 'bbb\n', '222\n'],
193
193
                           ['aaa\n', 'bbb\n', '222\n'])
194
194
 
195
 
        self.assertEquals(''.join(m3.merge_lines()),
 
195
        self.assertEqual(''.join(m3.merge_lines()),
196
196
                          'aaa\nbbb\n222\n')
197
197
 
198
198
    def test_append_clash(self):
205
205
                            start_marker='<<',
206
206
                            mid_marker='--',
207
207
                            end_marker='>>')
208
 
        self.assertEquals(''.join(ml),
 
208
        self.assertEqual(''.join(ml),
209
209
'''\
210
210
aaa
211
211
bbb
226
226
                            start_marker='<<',
227
227
                            mid_marker='--',
228
228
                            end_marker='>>')
229
 
        self.assertEquals(''.join(ml), 'aaa\n222\nbbb\n')
 
229
        self.assertEqual(''.join(ml), 'aaa\n222\nbbb\n')
230
230
 
231
231
 
232
232
    def test_insert_clash(self):
235
235
                           ['aaa\n', '111\n', 'bbb\n'],
236
236
                           ['aaa\n', '222\n', 'bbb\n'])
237
237
 
238
 
        self.assertEquals(m3.find_unconflicted(),
 
238
        self.assertEqual(m3.find_unconflicted(),
239
239
                          [(0, 1), (1, 2)])
240
240
 
241
 
        self.assertEquals(list(m3.find_sync_regions()),
242
 
                          [(0,1, 0,1, 0,1),
243
 
                           (1,2, 2,3, 2,3),
244
 
                           (2,2, 3,3, 3,3),])
245
 
 
246
 
        self.assertEquals(list(m3.merge_regions()),
247
 
                          [('unchanged', 0,1),
248
 
                           ('conflict', 1,1, 1,2, 1,2),
249
 
                           ('unchanged', 1,2)])
250
 
 
251
 
        self.assertEquals(list(m3.merge_groups()),
 
241
        self.assertEqual(list(m3.find_sync_regions()),
 
242
                          [(0, 1, 0, 1, 0, 1),
 
243
                           (1, 2, 2, 3, 2, 3),
 
244
                           (2, 2, 3, 3, 3, 3),])
 
245
 
 
246
        self.assertEqual(list(m3.merge_regions()),
 
247
                          [('unchanged', 0, 1),
 
248
                           ('conflict', 1, 1, 1, 2, 1, 2),
 
249
                           ('unchanged', 1, 2)])
 
250
 
 
251
        self.assertEqual(list(m3.merge_groups()),
252
252
                          [('unchanged', ['aaa\n']),
253
253
                           ('conflict', [], ['111\n'], ['222\n']),
254
254
                           ('unchanged', ['bbb\n']),
255
255
                           ])
256
256
 
257
 
        ml = m3.merge_lines(name_a='a',
258
 
                            name_b='b',
259
 
                            start_marker='<<',
260
 
                            mid_marker='--',
261
 
                            end_marker='>>')
262
 
        self.assertEquals(''.join(ml),
263
 
'''aaa
 
257
        ml = m3.merge_lines(name_a=b'a',
 
258
                            name_b=b'b',
 
259
                            start_marker=b'<<',
 
260
                            mid_marker=b'--',
 
261
                            end_marker=b'>>')
 
262
        self.assertEqual(b''.join(ml),
 
263
b'''aaa
264
264
<< a
265
265
111
266
266
--
271
271
 
272
272
    def test_replace_clash(self):
273
273
        """Both try to insert lines in the same place."""
274
 
        m3 = merge3.Merge3(['aaa', '000', 'bbb'],
275
 
                           ['aaa', '111', 'bbb'],
276
 
                           ['aaa', '222', 'bbb'])
 
274
        m3 = merge3.Merge3([b'aaa', b'000', b'bbb'],
 
275
                           [b'aaa', b'111', b'bbb'],
 
276
                           [b'aaa', b'222', b'bbb'])
277
277
 
278
 
        self.assertEquals(m3.find_unconflicted(),
 
278
        self.assertEqual(m3.find_unconflicted(),
279
279
                          [(0, 1), (2, 3)])
280
280
 
281
 
        self.assertEquals(list(m3.find_sync_regions()),
282
 
                          [(0,1, 0,1, 0,1),
283
 
                           (2,3, 2,3, 2,3),
284
 
                           (3,3, 3,3, 3,3),])
 
281
        self.assertEqual(list(m3.find_sync_regions()),
 
282
                          [(0, 1, 0, 1, 0, 1),
 
283
                           (2, 3, 2, 3, 2, 3),
 
284
                           (3, 3, 3, 3, 3, 3),])
285
285
 
286
286
    def test_replace_multi(self):
287
287
        """Replacement with regions of different size."""
288
 
        m3 = merge3.Merge3(['aaa', '000', '000', 'bbb'],
289
 
                           ['aaa', '111', '111', '111', 'bbb'],
290
 
                           ['aaa', '222', '222', '222', '222', 'bbb'])
 
288
        m3 = merge3.Merge3([b'aaa', b'000', b'000', b'bbb'],
 
289
                           [b'aaa', b'111', b'111', b'111', b'bbb'],
 
290
                           [b'aaa', b'222', b'222', b'222', b'222', b'bbb'])
291
291
 
292
 
        self.assertEquals(m3.find_unconflicted(),
 
292
        self.assertEqual(m3.find_unconflicted(),
293
293
                          [(0, 1), (3, 4)])
294
294
 
295
295
 
296
 
        self.assertEquals(list(m3.find_sync_regions()),
297
 
                          [(0,1, 0,1, 0,1),
298
 
                           (3,4, 4,5, 5,6),
299
 
                           (4,4, 5,5, 6,6),])
 
296
        self.assertEqual(list(m3.find_sync_regions()),
 
297
                          [(0, 1, 0, 1, 0, 1),
 
298
                           (3, 4, 4, 5, 5, 6),
 
299
                           (4, 4, 5, 5, 6, 6),])
300
300
 
301
301
    def test_merge_poem(self):
302
302
        """Test case from diff3 manual"""
304
304
        ml = list(m3.merge_lines('LAO', 'TAO'))
305
305
        self.log('merge result:')
306
306
        self.log(''.join(ml))
307
 
        self.assertEquals(ml, MERGED_RESULT)
 
307
        self.assertEqual(ml, MERGED_RESULT)
308
308
 
309
309
    def test_minimal_conflicts_common(self):
310
310
        """Reprocessing"""
439
439
        merge_groups and merge_regions work with non-str input.  Methods that
440
440
        return lines like merge_lines fail.
441
441
        """
442
 
        base = [(x,x) for x in 'abcde']
443
 
        a = [(x,x) for x in 'abcdef']
444
 
        b = [(x,x) for x in 'Zabcde']
 
442
        base = [(x, x) for x in 'abcde']
 
443
        a = [(x, x) for x in 'abcdef']
 
444
        b = [(x, x) for x in 'Zabcde']
445
445
        m3 = merge3.Merge3(base, a, b, allow_objects=True)
446
446
        self.assertEqual(
447
447
            [('b', 0, 1),
450
450
            list(m3.merge_regions()))
451
451
        self.assertEqual(
452
452
            [('b', [('Z', 'Z')]),
453
 
             ('unchanged', [(x,x) for x in 'abcde']),
 
453
             ('unchanged', [(x, x) for x in 'abcde']),
454
454
             ('a', [('f', 'f')])],
455
455
            list(m3.merge_groups()))
456
456