/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: 2017-06-08 23:30:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170608233031-3qavls2o7a1pqllj
Update imports.

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
 
from io import BytesIO
18
17
 
19
18
from .. import (
20
19
    merge3,
21
20
    tests,
22
21
    )
23
 
from ..errors import BinaryFile
24
 
 
 
22
from ..errors import CantReprocessAndShowBase, BinaryFile
 
23
from ..sixish import (
 
24
    BytesIO,
 
25
    )
25
26
 
26
27
def split_lines(t):
27
28
    return BytesIO(t).readlines()
28
29
 
29
 
 
30
30
############################################################
31
31
# test case data from the gnu diffutils manual
32
32
# common base
33
 
TZU = split_lines(b"""     The Nameless is the origin of Heaven and Earth;
 
33
TZU = split_lines("""     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(b"""     The Way that can be told of is not the eternal Way;
 
48
LAO = split_lines("""     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(b"""     The Way that can be told of is not the eternal Way;
 
62
TAO = split_lines("""     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(b"""     The Way that can be told of is not the eternal Way;
 
79
MERGED_RESULT = split_lines("""     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.
95
95
>>>>>>> TAO
96
96
""")
97
97
 
98
 
 
99
98
class TestMerge3(tests.TestCase):
100
99
 
101
100
    def test_no_changes(self):
102
101
        """No conflicts because nothing changed"""
103
 
        m3 = merge3.Merge3([b'aaa', b'bbb'],
104
 
                           [b'aaa', b'bbb'],
105
 
                           [b'aaa', b'bbb'])
 
102
        m3 = merge3.Merge3(['aaa', 'bbb'],
 
103
                           ['aaa', 'bbb'],
 
104
                           ['aaa', 'bbb'])
106
105
 
107
106
        self.assertEqual(m3.find_unconflicted(),
108
 
                         [(0, 2)])
 
107
                          [(0, 2)])
109
108
 
110
109
        self.assertEqual(list(m3.find_sync_regions()),
111
 
                         [(0, 2,
112
 
                           0, 2,
113
 
                           0, 2),
114
 
                          (2, 2, 2, 2, 2, 2)])
 
110
                          [(0, 2,
 
111
                            0, 2,
 
112
                            0, 2),
 
113
                           (2,2, 2,2, 2,2)])
115
114
 
116
115
        self.assertEqual(list(m3.merge_regions()),
117
 
                         [('unchanged', 0, 2)])
 
116
                          [('unchanged', 0, 2)])
118
117
 
119
118
        self.assertEqual(list(m3.merge_groups()),
120
 
                         [('unchanged', [b'aaa', b'bbb'])])
 
119
                          [('unchanged', ['aaa', 'bbb'])])
121
120
 
122
121
    def test_front_insert(self):
123
 
        m3 = merge3.Merge3([b'zz'],
124
 
                           [b'aaa', b'bbb', b'zz'],
125
 
                           [b'zz'])
 
122
        m3 = merge3.Merge3(['zz'],
 
123
                           ['aaa', 'bbb', 'zz'],
 
124
                           ['zz'])
126
125
 
127
126
        # todo: should use a sentinal at end as from get_matching_blocks
128
127
        # to match without zz
129
128
        self.assertEqual(list(m3.find_sync_regions()),
130
 
                         [(0, 1, 2, 3, 0, 1),
131
 
                          (1, 1, 3, 3, 1, 1), ])
 
129
                          [(0,1, 2,3, 0,1),
 
130
                           (1,1, 3,3, 1,1),])
132
131
 
133
132
        self.assertEqual(list(m3.merge_regions()),
134
 
                         [('a', 0, 2),
135
 
                          ('unchanged', 0, 1)])
 
133
                          [('a', 0, 2),
 
134
                           ('unchanged', 0, 1)])
136
135
 
137
136
        self.assertEqual(list(m3.merge_groups()),
138
 
                         [('a', [b'aaa', b'bbb']),
139
 
                          ('unchanged', [b'zz'])])
 
137
                          [('a', ['aaa', 'bbb']),
 
138
                           ('unchanged', ['zz'])])
140
139
 
141
140
    def test_null_insert(self):
142
141
        m3 = merge3.Merge3([],
143
 
                           [b'aaa', b'bbb'],
 
142
                           ['aaa', 'bbb'],
144
143
                           [])
145
144
        # todo: should use a sentinal at end as from get_matching_blocks
146
145
        # to match without zz
147
146
        self.assertEqual(list(m3.find_sync_regions()),
148
 
                         [(0, 0, 2, 2, 0, 0)])
 
147
                          [(0,0, 2,2, 0,0)])
149
148
 
150
149
        self.assertEqual(list(m3.merge_regions()),
151
 
                         [('a', 0, 2)])
 
150
                          [('a', 0, 2)])
152
151
 
153
152
        self.assertEqual(list(m3.merge_lines()),
154
 
                         [b'aaa', b'bbb'])
 
153
                          ['aaa', 'bbb'])
155
154
 
156
155
    def test_no_conflicts(self):
157
156
        """No conflicts because only one side changed"""
158
 
        m3 = merge3.Merge3([b'aaa', b'bbb'],
159
 
                           [b'aaa', b'111', b'bbb'],
160
 
                           [b'aaa', b'bbb'])
 
157
        m3 = merge3.Merge3(['aaa', 'bbb'],
 
158
                           ['aaa', '111', 'bbb'],
 
159
                           ['aaa', 'bbb'])
161
160
 
162
161
        self.assertEqual(m3.find_unconflicted(),
163
 
                         [(0, 1), (1, 2)])
 
162
                          [(0, 1), (1, 2)])
164
163
 
165
164
        self.assertEqual(list(m3.find_sync_regions()),
166
 
                         [(0, 1, 0, 1, 0, 1),
167
 
                          (1, 2, 2, 3, 1, 2),
168
 
                          (2, 2, 3, 3, 2, 2), ])
 
165
                          [(0,1, 0,1, 0,1),
 
166
                           (1,2, 2,3, 1,2),
 
167
                           (2,2, 3,3, 2,2),])
169
168
 
170
169
        self.assertEqual(list(m3.merge_regions()),
171
 
                         [('unchanged', 0, 1),
172
 
                          ('a', 1, 2),
173
 
                          ('unchanged', 1, 2), ])
 
170
                          [('unchanged', 0, 1),
 
171
                           ('a', 1, 2),
 
172
                           ('unchanged', 1, 2),])
174
173
 
175
174
    def test_append_a(self):
176
 
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
177
 
                           [b'aaa\n', b'bbb\n', b'222\n'],
178
 
                           [b'aaa\n', b'bbb\n'])
 
175
        m3 = merge3.Merge3(['aaa\n', 'bbb\n'],
 
176
                           ['aaa\n', 'bbb\n', '222\n'],
 
177
                           ['aaa\n', 'bbb\n'])
179
178
 
180
 
        self.assertEqual(b''.join(m3.merge_lines()),
181
 
                         b'aaa\nbbb\n222\n')
 
179
        self.assertEqual(''.join(m3.merge_lines()),
 
180
                          'aaa\nbbb\n222\n')
182
181
 
183
182
    def test_append_b(self):
184
 
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
185
 
                           [b'aaa\n', b'bbb\n'],
186
 
                           [b'aaa\n', b'bbb\n', b'222\n'])
 
183
        m3 = merge3.Merge3(['aaa\n', 'bbb\n'],
 
184
                           ['aaa\n', 'bbb\n'],
 
185
                           ['aaa\n', 'bbb\n', '222\n'])
187
186
 
188
 
        self.assertEqual(b''.join(m3.merge_lines()),
189
 
                         b'aaa\nbbb\n222\n')
 
187
        self.assertEqual(''.join(m3.merge_lines()),
 
188
                          'aaa\nbbb\n222\n')
190
189
 
191
190
    def test_append_agreement(self):
192
 
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
193
 
                           [b'aaa\n', b'bbb\n', b'222\n'],
194
 
                           [b'aaa\n', b'bbb\n', b'222\n'])
 
191
        m3 = merge3.Merge3(['aaa\n', 'bbb\n'],
 
192
                           ['aaa\n', 'bbb\n', '222\n'],
 
193
                           ['aaa\n', 'bbb\n', '222\n'])
195
194
 
196
 
        self.assertEqual(b''.join(m3.merge_lines()),
197
 
                         b'aaa\nbbb\n222\n')
 
195
        self.assertEqual(''.join(m3.merge_lines()),
 
196
                          'aaa\nbbb\n222\n')
198
197
 
199
198
    def test_append_clash(self):
200
 
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
201
 
                           [b'aaa\n', b'bbb\n', b'222\n'],
202
 
                           [b'aaa\n', b'bbb\n', b'333\n'])
 
199
        m3 = merge3.Merge3(['aaa\n', 'bbb\n'],
 
200
                           ['aaa\n', 'bbb\n', '222\n'],
 
201
                           ['aaa\n', 'bbb\n', '333\n'])
203
202
 
204
 
        ml = m3.merge_lines(name_a=b'a',
205
 
                            name_b=b'b',
206
 
                            start_marker=b'<<',
207
 
                            mid_marker=b'--',
208
 
                            end_marker=b'>>')
209
 
        self.assertEqual(b''.join(ml),
210
 
                         b'''\
 
203
        ml = m3.merge_lines(name_a='a',
 
204
                            name_b='b',
 
205
                            start_marker='<<',
 
206
                            mid_marker='--',
 
207
                            end_marker='>>')
 
208
        self.assertEqual(''.join(ml),
 
209
'''\
211
210
aaa
212
211
bbb
213
212
<< a
218
217
''')
219
218
 
220
219
    def test_insert_agreement(self):
221
 
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
222
 
                           [b'aaa\n', b'222\n', b'bbb\n'],
223
 
                           [b'aaa\n', b'222\n', b'bbb\n'])
224
 
 
225
 
        ml = m3.merge_lines(name_a=b'a',
226
 
                            name_b=b'b',
227
 
                            start_marker=b'<<',
228
 
                            mid_marker=b'--',
229
 
                            end_marker=b'>>')
230
 
        self.assertEqual(b''.join(ml), b'aaa\n222\nbbb\n')
 
220
        m3 = merge3.Merge3(['aaa\n', 'bbb\n'],
 
221
                           ['aaa\n', '222\n', 'bbb\n'],
 
222
                           ['aaa\n', '222\n', 'bbb\n'])
 
223
 
 
224
        ml = m3.merge_lines(name_a='a',
 
225
                            name_b='b',
 
226
                            start_marker='<<',
 
227
                            mid_marker='--',
 
228
                            end_marker='>>')
 
229
        self.assertEqual(''.join(ml), 'aaa\n222\nbbb\n')
 
230
 
231
231
 
232
232
    def test_insert_clash(self):
233
233
        """Both try to insert lines in the same place."""
234
 
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
235
 
                           [b'aaa\n', b'111\n', b'bbb\n'],
236
 
                           [b'aaa\n', b'222\n', b'bbb\n'])
 
234
        m3 = merge3.Merge3(['aaa\n', 'bbb\n'],
 
235
                           ['aaa\n', '111\n', 'bbb\n'],
 
236
                           ['aaa\n', '222\n', 'bbb\n'])
237
237
 
238
238
        self.assertEqual(m3.find_unconflicted(),
239
 
                         [(0, 1), (1, 2)])
 
239
                          [(0, 1), (1, 2)])
240
240
 
241
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), ])
 
242
                          [(0,1, 0,1, 0,1),
 
243
                           (1,2, 2,3, 2,3),
 
244
                           (2,2, 3,3, 3,3),])
245
245
 
246
246
        self.assertEqual(list(m3.merge_regions()),
247
 
                         [('unchanged', 0, 1),
248
 
                          ('conflict', 1, 1, 1, 2, 1, 2),
249
 
                          ('unchanged', 1, 2)])
 
247
                          [('unchanged', 0,1),
 
248
                           ('conflict', 1,1, 1,2, 1,2),
 
249
                           ('unchanged', 1,2)])
250
250
 
251
251
        self.assertEqual(list(m3.merge_groups()),
252
 
                         [('unchanged', [b'aaa\n']),
253
 
                          ('conflict', [], [b'111\n'], [b'222\n']),
254
 
                          ('unchanged', [b'bbb\n']),
255
 
                          ])
 
252
                          [('unchanged', ['aaa\n']),
 
253
                           ('conflict', [], ['111\n'], ['222\n']),
 
254
                           ('unchanged', ['bbb\n']),
 
255
                           ])
256
256
 
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
 
257
        ml = m3.merge_lines(name_a='a',
 
258
                            name_b='b',
 
259
                            start_marker='<<',
 
260
                            mid_marker='--',
 
261
                            end_marker='>>')
 
262
        self.assertEqual(''.join(ml),
 
263
'''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([b'aaa', b'000', b'bbb'],
275
 
                           [b'aaa', b'111', b'bbb'],
276
 
                           [b'aaa', b'222', b'bbb'])
 
274
        m3 = merge3.Merge3(['aaa', '000', 'bbb'],
 
275
                           ['aaa', '111', 'bbb'],
 
276
                           ['aaa', '222', 'bbb'])
277
277
 
278
278
        self.assertEqual(m3.find_unconflicted(),
279
 
                         [(0, 1), (2, 3)])
 
279
                          [(0, 1), (2, 3)])
280
280
 
281
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), ])
 
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([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'])
 
288
        m3 = merge3.Merge3(['aaa', '000', '000', 'bbb'],
 
289
                           ['aaa', '111', '111', '111', 'bbb'],
 
290
                           ['aaa', '222', '222', '222', '222', 'bbb'])
291
291
 
292
292
        self.assertEqual(m3.find_unconflicted(),
293
 
                         [(0, 1), (3, 4)])
 
293
                          [(0, 1), (3, 4)])
 
294
 
294
295
 
295
296
        self.assertEqual(list(m3.find_sync_regions()),
296
 
                         [(0, 1, 0, 1, 0, 1),
297
 
                          (3, 4, 4, 5, 5, 6),
298
 
                          (4, 4, 5, 5, 6, 6), ])
 
297
                          [(0,1, 0,1, 0,1),
 
298
                           (3,4, 4,5, 5,6),
 
299
                           (4,4, 5,5, 6,6),])
299
300
 
300
301
    def test_merge_poem(self):
301
302
        """Test case from diff3 manual"""
302
303
        m3 = merge3.Merge3(TZU, LAO, TAO)
303
 
        ml = list(m3.merge_lines(b'LAO', b'TAO'))
 
304
        ml = list(m3.merge_lines('LAO', 'TAO'))
304
305
        self.log('merge result:')
305
 
        self.log(b''.join(ml))
 
306
        self.log(''.join(ml))
306
307
        self.assertEqual(ml, MERGED_RESULT)
307
308
 
308
309
    def test_minimal_conflicts_common(self):
309
310
        """Reprocessing"""
310
 
        base_text = (b"a\n" * 20).splitlines(True)
311
 
        this_text = (b"a\n" * 10 + b"b\n" * 10).splitlines(True)
312
 
        other_text = (b"a\n" * 10 + b"c\n" + b"b\n" *
313
 
                      8 + b"c\n").splitlines(True)
 
311
        base_text = ("a\n" * 20).splitlines(True)
 
312
        this_text = ("a\n"*10+"b\n" * 10).splitlines(True)
 
313
        other_text = ("a\n"*10+"c\n"+"b\n" * 8 + "c\n").splitlines(True)
314
314
        m3 = merge3.Merge3(base_text, other_text, this_text)
315
 
        m_lines = m3.merge_lines(b'OTHER', b'THIS', reprocess=True)
316
 
        merged_text = b"".join(list(m_lines))
317
 
        optimal_text = (b"a\n" * 10 + b"<<<<<<< OTHER\nc\n"
318
 
                        + 8 * b"b\n" + b"c\n=======\n"
319
 
                        + 10 * b"b\n" + b">>>>>>> THIS\n")
 
315
        m_lines = m3.merge_lines('OTHER', 'THIS', reprocess=True)
 
316
        merged_text = "".join(list(m_lines))
 
317
        optimal_text = ("a\n" * 10 + "<<<<<<< OTHER\nc\n"
 
318
            + 8* "b\n" + "c\n=======\n"
 
319
            + 10*"b\n" + ">>>>>>> THIS\n")
320
320
        self.assertEqualDiff(optimal_text, merged_text)
321
321
 
322
322
    def test_minimal_conflicts_unique(self):
323
323
        def add_newline(s):
324
324
            """Add a newline to each entry in the string"""
325
 
            return [(bytes([x]) + b'\n') for x in bytearray(s)]
 
325
            return [(x+'\n') for x in s]
326
326
 
327
 
        base_text = add_newline(b"abcdefghijklm")
328
 
        this_text = add_newline(b"abcdefghijklmNOPQRSTUVWXYZ")
329
 
        other_text = add_newline(b"abcdefghijklm1OPQRSTUVWXY2")
 
327
        base_text = add_newline("abcdefghijklm")
 
328
        this_text = add_newline("abcdefghijklmNOPQRSTUVWXYZ")
 
329
        other_text = add_newline("abcdefghijklm1OPQRSTUVWXY2")
330
330
        m3 = merge3.Merge3(base_text, other_text, this_text)
331
 
        m_lines = m3.merge_lines(b'OTHER', b'THIS', reprocess=True)
332
 
        merged_text = b"".join(list(m_lines))
333
 
        optimal_text = b''.join(add_newline(b"abcdefghijklm")
334
 
                                + [b"<<<<<<< OTHER\n1\n=======\nN\n>>>>>>> THIS\n"]
335
 
                                + add_newline(b'OPQRSTUVWXY')
336
 
                                + [b"<<<<<<< OTHER\n2\n=======\nZ\n>>>>>>> THIS\n"]
337
 
                                )
 
331
        m_lines = m3.merge_lines('OTHER', 'THIS', reprocess=True)
 
332
        merged_text = "".join(list(m_lines))
 
333
        optimal_text = ''.join(add_newline("abcdefghijklm")
 
334
            + ["<<<<<<< OTHER\n1\n=======\nN\n>>>>>>> THIS\n"]
 
335
            + add_newline('OPQRSTUVWXY')
 
336
            + ["<<<<<<< OTHER\n2\n=======\nZ\n>>>>>>> THIS\n"]
 
337
            )
338
338
        self.assertEqualDiff(optimal_text, merged_text)
339
339
 
340
340
    def test_minimal_conflicts_nonunique(self):
341
341
        def add_newline(s):
342
342
            """Add a newline to each entry in the string"""
343
 
            return [(bytes([x]) + b'\n') for x in bytearray(s)]
 
343
            return [(x+'\n') for x in s]
344
344
 
345
 
        base_text = add_newline(b"abacddefgghij")
346
 
        this_text = add_newline(b"abacddefgghijkalmontfprz")
347
 
        other_text = add_newline(b"abacddefgghijknlmontfprd")
 
345
        base_text = add_newline("abacddefgghij")
 
346
        this_text = add_newline("abacddefgghijkalmontfprz")
 
347
        other_text = add_newline("abacddefgghijknlmontfprd")
348
348
        m3 = merge3.Merge3(base_text, other_text, this_text)
349
 
        m_lines = m3.merge_lines(b'OTHER', b'THIS', reprocess=True)
350
 
        merged_text = b"".join(list(m_lines))
351
 
        optimal_text = b''.join(add_newline(b"abacddefgghijk")
352
 
                                + [b"<<<<<<< OTHER\nn\n=======\na\n>>>>>>> THIS\n"]
353
 
                                + add_newline(b'lmontfpr')
354
 
                                + [b"<<<<<<< OTHER\nd\n=======\nz\n>>>>>>> THIS\n"]
355
 
                                )
 
349
        m_lines = m3.merge_lines('OTHER', 'THIS', reprocess=True)
 
350
        merged_text = "".join(list(m_lines))
 
351
        optimal_text = ''.join(add_newline("abacddefgghijk")
 
352
            + ["<<<<<<< OTHER\nn\n=======\na\n>>>>>>> THIS\n"]
 
353
            + add_newline('lmontfpr')
 
354
            + ["<<<<<<< OTHER\nd\n=======\nz\n>>>>>>> THIS\n"]
 
355
            )
356
356
        self.assertEqualDiff(optimal_text, merged_text)
357
357
 
358
358
    def test_reprocess_and_base(self):
359
359
        """Reprocessing and showing base breaks correctly"""
360
 
        base_text = (b"a\n" * 20).splitlines(True)
361
 
        this_text = (b"a\n" * 10 + b"b\n" * 10).splitlines(True)
362
 
        other_text = (b"a\n" * 10 + b"c\n" + b"b\n" *
363
 
                      8 + b"c\n").splitlines(True)
 
360
        base_text = ("a\n" * 20).splitlines(True)
 
361
        this_text = ("a\n"*10+"b\n" * 10).splitlines(True)
 
362
        other_text = ("a\n"*10+"c\n"+"b\n" * 8 + "c\n").splitlines(True)
364
363
        m3 = merge3.Merge3(base_text, other_text, this_text)
365
 
        m_lines = m3.merge_lines(b'OTHER', b'THIS', reprocess=True,
366
 
                                 base_marker=b'|||||||')
367
 
        self.assertRaises(merge3.CantReprocessAndShowBase, list, m_lines)
 
364
        m_lines = m3.merge_lines('OTHER', 'THIS', reprocess=True,
 
365
                                 base_marker='|||||||')
 
366
        self.assertRaises(CantReprocessAndShowBase, list, m_lines)
368
367
 
369
368
    def test_binary(self):
370
 
        self.assertRaises(BinaryFile, merge3.Merge3, [b'\x00'], [b'a'], [b'b'])
 
369
        self.assertRaises(BinaryFile, merge3.Merge3, ['\x00'], ['a'], ['b'])
371
370
 
372
371
    def test_dos_text(self):
373
 
        base_text = b'a\r\n'
374
 
        this_text = b'b\r\n'
375
 
        other_text = b'c\r\n'
 
372
        base_text = 'a\r\n'
 
373
        this_text = 'b\r\n'
 
374
        other_text = 'c\r\n'
376
375
        m3 = merge3.Merge3(base_text.splitlines(True),
377
376
                           other_text.splitlines(True),
378
377
                           this_text.splitlines(True))
379
 
        m_lines = m3.merge_lines(b'OTHER', b'THIS')
380
 
        self.assertEqual(b'<<<<<<< OTHER\r\nc\r\n=======\r\nb\r\n'
381
 
                         b'>>>>>>> THIS\r\n'.splitlines(True), list(m_lines))
 
378
        m_lines = m3.merge_lines('OTHER', 'THIS')
 
379
        self.assertEqual('<<<<<<< OTHER\r\nc\r\n=======\r\nb\r\n'
 
380
            '>>>>>>> THIS\r\n'.splitlines(True), list(m_lines))
382
381
 
383
382
    def test_mac_text(self):
384
 
        base_text = b'a\r'
385
 
        this_text = b'b\r'
386
 
        other_text = b'c\r'
 
383
        base_text = 'a\r'
 
384
        this_text = 'b\r'
 
385
        other_text = 'c\r'
387
386
        m3 = merge3.Merge3(base_text.splitlines(True),
388
387
                           other_text.splitlines(True),
389
388
                           this_text.splitlines(True))
390
 
        m_lines = m3.merge_lines(b'OTHER', b'THIS')
391
 
        self.assertEqual(b'<<<<<<< OTHER\rc\r=======\rb\r'
392
 
                         b'>>>>>>> THIS\r'.splitlines(True), list(m_lines))
 
389
        m_lines = m3.merge_lines('OTHER', 'THIS')
 
390
        self.assertEqual('<<<<<<< OTHER\rc\r=======\rb\r'
 
391
            '>>>>>>> THIS\r'.splitlines(True), list(m_lines))
393
392
 
394
393
    def test_merge3_cherrypick(self):
395
 
        base_text = b"a\nb\n"
396
 
        this_text = b"a\n"
397
 
        other_text = b"a\nb\nc\n"
 
394
        base_text = "a\nb\n"
 
395
        this_text = "a\n"
 
396
        other_text = "a\nb\nc\n"
398
397
        # When cherrypicking, lines in base are not part of the conflict
399
398
        m3 = merge3.Merge3(base_text.splitlines(True),
400
399
                           this_text.splitlines(True),
401
400
                           other_text.splitlines(True), is_cherrypick=True)
402
401
        m_lines = m3.merge_lines()
403
 
        self.assertEqualDiff(b'a\n<<<<<<<\n=======\nc\n>>>>>>>\n',
404
 
                             b''.join(m_lines))
 
402
        self.assertEqualDiff('a\n<<<<<<<\n=======\nc\n>>>>>>>\n',
 
403
                             ''.join(m_lines))
405
404
 
406
405
        # This is not symmetric
407
406
        m3 = merge3.Merge3(base_text.splitlines(True),
408
407
                           other_text.splitlines(True),
409
408
                           this_text.splitlines(True), is_cherrypick=True)
410
409
        m_lines = m3.merge_lines()
411
 
        self.assertEqualDiff(b'a\n<<<<<<<\nb\nc\n=======\n>>>>>>>\n',
412
 
                             b''.join(m_lines))
 
410
        self.assertEqualDiff('a\n<<<<<<<\nb\nc\n=======\n>>>>>>>\n',
 
411
                             ''.join(m_lines))
413
412
 
414
413
    def test_merge3_cherrypick_w_mixed(self):
415
 
        base_text = b'a\nb\nc\nd\ne\n'
416
 
        this_text = b'a\nb\nq\n'
417
 
        other_text = b'a\nb\nc\nd\nf\ne\ng\n'
 
414
        base_text = 'a\nb\nc\nd\ne\n'
 
415
        this_text = 'a\nb\nq\n'
 
416
        other_text = 'a\nb\nc\nd\nf\ne\ng\n'
418
417
        # When cherrypicking, lines in base are not part of the conflict
419
418
        m3 = merge3.Merge3(base_text.splitlines(True),
420
419
                           this_text.splitlines(True),
421
420
                           other_text.splitlines(True), is_cherrypick=True)
422
421
        m_lines = m3.merge_lines()
423
 
        self.assertEqualDiff(b'a\n'
424
 
                             b'b\n'
425
 
                             b'<<<<<<<\n'
426
 
                             b'q\n'
427
 
                             b'=======\n'
428
 
                             b'f\n'
429
 
                             b'>>>>>>>\n'
430
 
                             b'<<<<<<<\n'
431
 
                             b'=======\n'
432
 
                             b'g\n'
433
 
                             b'>>>>>>>\n',
434
 
                             b''.join(m_lines))
 
422
        self.assertEqualDiff('a\n'
 
423
                             'b\n'
 
424
                             '<<<<<<<\n'
 
425
                             'q\n'
 
426
                             '=======\n'
 
427
                             'f\n'
 
428
                             '>>>>>>>\n'
 
429
                             '<<<<<<<\n'
 
430
                             '=======\n'
 
431
                             'g\n'
 
432
                             '>>>>>>>\n',
 
433
                             ''.join(m_lines))
435
434
 
436
435
    def test_allow_objects(self):
437
436
        """Objects other than strs may be used with Merge3 when
438
437
        allow_objects=True.
439
 
 
 
438
        
440
439
        merge_groups and merge_regions work with non-str input.  Methods that
441
440
        return lines like merge_lines fail.
442
441
        """
443
 
        base = [(x, x) for x in 'abcde']
444
 
        a = [(x, x) for x in 'abcdef']
445
 
        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']
446
445
        m3 = merge3.Merge3(base, a, b, allow_objects=True)
447
446
        self.assertEqual(
448
447
            [('b', 0, 1),
451
450
            list(m3.merge_regions()))
452
451
        self.assertEqual(
453
452
            [('b', [('Z', 'Z')]),
454
 
             ('unchanged', [(x, x) for x in 'abcde']),
 
453
             ('unchanged', [(x,x) for x in 'abcde']),
455
454
             ('a', [('f', 'f')])],
456
455
            list(m3.merge_groups()))
 
456