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

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Whitebox tests for annotate functionality."""
18
18
 
19
19
import codecs
20
 
from cStringIO import StringIO
 
20
from io import BytesIO, StringIO
21
21
 
22
 
from bzrlib import (
 
22
from .. import (
23
23
    annotate,
24
 
    symbol_versioning,
25
24
    tests,
26
25
    )
 
26
from .ui_testing import StringIOWithEncoding
27
27
 
28
28
 
29
29
def annotation(text):
30
 
    return [tuple(l.split(' ', 1)) for l in text.splitlines(True)]
31
 
 
32
 
 
33
 
parent_1 = annotation("""\
 
30
    return [tuple(l.split(b' ', 1)) for l in text.splitlines(True)]
 
31
 
 
32
 
 
33
parent_1 = annotation(b"""\
34
34
rev1 a
35
35
rev2 b
36
36
rev3 c
39
39
""")
40
40
 
41
41
 
42
 
parent_2 = annotation("""\
 
42
parent_2 = annotation(b"""\
43
43
rev1 a
44
44
rev3 c
45
45
rev4 d
49
49
""")
50
50
 
51
51
 
52
 
expected_2_1 = annotation("""\
 
52
expected_2_1 = annotation(b"""\
53
53
rev1 a
54
54
blahblah b
55
55
rev3 c
66
66
# f: in 2, but not in new, so ignored
67
67
# g: not in 1 or 2, so it goes to blahblah
68
68
# h: only in parent 2, so 2 gets it
69
 
expected_1_2_2 = annotation("""\
 
69
expected_1_2_2 = annotation(b"""\
70
70
rev1 a
71
71
rev2 b
72
72
rev3 c
77
77
""")
78
78
 
79
79
 
80
 
new_1 = """\
 
80
new_1 = b"""\
81
81
a
82
82
b
83
83
c
85
85
e
86
86
""".splitlines(True)
87
87
 
88
 
expected_1 = annotation("""\
 
88
expected_1 = annotation(b"""\
89
89
blahblah a
90
90
blahblah b
91
91
blahblah c
94
94
""")
95
95
 
96
96
 
97
 
new_2 = """\
 
97
new_2 = b"""\
98
98
a
99
99
b
100
100
c
118
118
#  |/
119
119
#  E    # D should supersede A and stay as D (not become E because C references
120
120
#         A)
121
 
duplicate_base = annotation("""\
 
121
duplicate_base = annotation(b"""\
122
122
rev-base first
123
123
rev-base second
124
124
rev-base third
125
125
rev-base fourth-base
126
126
""")
127
127
 
128
 
duplicate_A = annotation("""\
 
128
duplicate_A = annotation(b"""\
129
129
rev-base first
130
130
rev-A alt-second
131
131
rev-base third
132
132
rev-A fourth-A
133
133
""")
134
134
 
135
 
duplicate_B = annotation("""\
 
135
duplicate_B = annotation(b"""\
136
136
rev-base first
137
137
rev-B alt-second
138
138
rev-base third
139
139
rev-B fourth-B
140
140
""")
141
141
 
142
 
duplicate_C = annotation("""\
 
142
duplicate_C = annotation(b"""\
143
143
rev-base first
144
144
rev-A alt-second
145
145
rev-base third
146
146
rev-C fourth-C
147
147
""")
148
148
 
149
 
duplicate_D = annotation("""\
 
149
duplicate_D = annotation(b"""\
150
150
rev-base first
151
151
rev-A alt-second
152
152
rev-base third
153
153
rev-D fourth-D
154
154
""")
155
155
 
156
 
duplicate_E = annotation("""\
 
156
duplicate_E = annotation(b"""\
157
157
rev-base first
158
158
rev-A alt-second
159
159
rev-base third
177
177
        builder = self.make_branch_builder('branch')
178
178
        builder.start_series()
179
179
        self.addCleanup(builder.finish_series)
180
 
        builder.build_snapshot('rev-1', None, [
181
 
            ('add', ('', 'root-id', 'directory', None)),
182
 
            ('add', ('a', 'a-id', 'file', 'first\n')),
183
 
            ], timestamp=1166046000.00, timezone=0, committer="joe@foo.com")
184
 
        builder.build_snapshot('rev-2', ['rev-1'], [
185
 
            ('modify', ('a-id', 'first\nsecond\n')),
186
 
            ], timestamp=1166046001.00, timezone=0, committer="joe@foo.com")
187
 
        builder.build_snapshot('rev-1_1_1', ['rev-1'], [
188
 
            ('modify', ('a-id', 'first\nthird\n')),
189
 
            ], timestamp=1166046002.00, timezone=0, committer="barry@foo.com")
190
 
        builder.build_snapshot('rev-3', ['rev-2', 'rev-1_1_1'], [
191
 
            ('modify', ('a-id', 'first\nsecond\nthird\n')),
192
 
            ], timestamp=1166046003.00, timezone=0, committer="sal@foo.com")
 
180
        builder.build_snapshot(None, [
 
181
            ('add', ('', b'root-id', 'directory', None)),
 
182
            ('add', ('a', b'a-id', 'file', b'first\n')),
 
183
            ], timestamp=1166046000.00, timezone=0, committer="joe@foo.com",
 
184
            revision_id=b'rev-1')
 
185
        builder.build_snapshot([b'rev-1'], [
 
186
            ('modify', ('a', b'first\nsecond\n')),
 
187
            ], timestamp=1166046001.00, timezone=0, committer="joe@foo.com",
 
188
            revision_id=b'rev-2')
 
189
        builder.build_snapshot([b'rev-1'], [
 
190
            ('modify', ('a', b'first\nthird\n')),
 
191
            ], timestamp=1166046002.00, timezone=0, committer="barry@foo.com",
 
192
            revision_id=b'rev-1_1_1')
 
193
        builder.build_snapshot([b'rev-2', b'rev-1_1_1'], [
 
194
            ('modify', ('a', b'first\nsecond\nthird\n')),
 
195
            ], timestamp=1166046003.00, timezone=0, committer="sal@foo.com",
 
196
            revision_id=b'rev-3')
193
197
        return builder
194
198
 
195
199
    def create_deeply_merged_trees(self):
216
220
        rev-6
217
221
        """
218
222
        builder = self.create_merged_trees()
219
 
        builder.build_snapshot('rev-1_1_2', ['rev-1_1_1'], [])
220
 
        builder.build_snapshot('rev-4', ['rev-3', 'rev-1_1_2'], [])
221
 
        builder.build_snapshot('rev-1_2_1', ['rev-1_1_1'], [
222
 
            ('modify', ('a-id', 'first\nthird\nfourth\n')),
223
 
            ], timestamp=1166046003.00, timezone=0, committer="jerry@foo.com")
224
 
        builder.build_snapshot('rev-1_2_2', ['rev-1_2_1'], [],
225
 
            timestamp=1166046004.00, timezone=0, committer="jerry@foo.com")
226
 
        builder.build_snapshot('rev-5', ['rev-4', 'rev-1_2_2'], [
227
 
            ('modify', ('a-id', 'first\nsecond\nthird\nfourth\n')),
228
 
            ], timestamp=1166046004.00, timezone=0, committer="jerry@foo.com")
229
 
        builder.build_snapshot('rev-1_3_1', ['rev-1_2_1'], [
230
 
            ('modify', ('a-id', 'first\nthird\nfourth\nfifth\nsixth\n')),
231
 
            ], timestamp=1166046005.00, timezone=0, committer="george@foo.com")
232
 
        builder.build_snapshot('rev-6', ['rev-5', 'rev-1_3_1'], [
233
 
            ('modify', ('a-id',
234
 
                        'first\nsecond\nthird\nfourth\nfifth\nsixth\n')),
235
 
            ])
 
223
        builder.build_snapshot([b'rev-1_1_1'], [], revision_id=b'rev-1_1_2')
 
224
        builder.build_snapshot([b'rev-3', b'rev-1_1_2'],
 
225
                               [], revision_id=b'rev-4')
 
226
        builder.build_snapshot([b'rev-1_1_1'], [
 
227
            ('modify', ('a', b'first\nthird\nfourth\n')),
 
228
            ], timestamp=1166046003.00, timezone=0, committer="jerry@foo.com",
 
229
            revision_id=b'rev-1_2_1')
 
230
        builder.build_snapshot([b'rev-1_2_1'], [],
 
231
                               timestamp=1166046004.00, timezone=0, committer="jerry@foo.com",
 
232
                               revision_id=b'rev-1_2_2')
 
233
        builder.build_snapshot([b'rev-4', b'rev-1_2_2'], [
 
234
            ('modify', ('a', b'first\nsecond\nthird\nfourth\n')),
 
235
            ], timestamp=1166046004.00, timezone=0, committer="jerry@foo.com",
 
236
            revision_id=b'rev-5')
 
237
        builder.build_snapshot([b'rev-1_2_1'], [
 
238
            ('modify', ('a', b'first\nthird\nfourth\nfifth\nsixth\n')),
 
239
            ], timestamp=1166046005.00, timezone=0, committer="george@foo.com",
 
240
            revision_id=b'rev-1_3_1')
 
241
        builder.build_snapshot([b'rev-5', b'rev-1_3_1'], [
 
242
            ('modify', ('a',
 
243
                        b'first\nsecond\nthird\nfourth\nfifth\nsixth\n')),
 
244
            ], revision_id=b'rev-6')
236
245
        return builder
237
246
 
238
247
    def create_duplicate_lines_tree(self):
239
248
        builder = self.make_branch_builder('branch')
240
249
        builder.start_series()
241
250
        self.addCleanup(builder.finish_series)
242
 
        base_text = ''.join(l for r, l in duplicate_base)
243
 
        a_text = ''.join(l for r, l in duplicate_A)
244
 
        b_text = ''.join(l for r, l in duplicate_B)
245
 
        c_text = ''.join(l for r, l in duplicate_C)
246
 
        d_text = ''.join(l for r, l in duplicate_D)
247
 
        e_text = ''.join(l for r, l in duplicate_E)
248
 
        builder.build_snapshot('rev-base', None, [
249
 
            ('add', ('', 'root-id', 'directory', None)),
250
 
            ('add', ('file', 'file-id', 'file', base_text)),
251
 
            ])
252
 
        builder.build_snapshot('rev-A', ['rev-base'], [
253
 
            ('modify', ('file-id', a_text))])
254
 
        builder.build_snapshot('rev-B', ['rev-base'], [
255
 
            ('modify', ('file-id', b_text))])
256
 
        builder.build_snapshot('rev-C', ['rev-A'], [
257
 
            ('modify', ('file-id', c_text))])
258
 
        builder.build_snapshot('rev-D', ['rev-B', 'rev-A'], [
259
 
            ('modify', ('file-id', d_text))])
260
 
        builder.build_snapshot('rev-E', ['rev-C', 'rev-D'], [
261
 
            ('modify', ('file-id', e_text))])
 
251
        base_text = b''.join(l for r, l in duplicate_base)
 
252
        a_text = b''.join(l for r, l in duplicate_A)
 
253
        b_text = b''.join(l for r, l in duplicate_B)
 
254
        c_text = b''.join(l for r, l in duplicate_C)
 
255
        d_text = b''.join(l for r, l in duplicate_D)
 
256
        e_text = b''.join(l for r, l in duplicate_E)
 
257
        builder.build_snapshot(None, [
 
258
            ('add', ('', b'root-id', 'directory', None)),
 
259
            ('add', ('file', b'file-id', 'file', base_text)),
 
260
            ], revision_id=b'rev-base')
 
261
        builder.build_snapshot([b'rev-base'], [
 
262
            ('modify', ('file', a_text))],
 
263
            revision_id=b'rev-A')
 
264
        builder.build_snapshot([b'rev-base'], [
 
265
            ('modify', ('file', b_text))],
 
266
            revision_id=b'rev-B')
 
267
        builder.build_snapshot([b'rev-A'], [
 
268
            ('modify', ('file', c_text))],
 
269
            revision_id=b'rev-C')
 
270
        builder.build_snapshot([b'rev-B', b'rev-A'], [
 
271
            ('modify', ('file', d_text))],
 
272
            revision_id=b'rev-D')
 
273
        builder.build_snapshot([b'rev-C', b'rev-D'], [
 
274
            ('modify', ('file', e_text))],
 
275
            revision_id=b'rev-E')
262
276
        return builder
263
277
 
264
278
    def assertAnnotateEqualDiff(self, actual, expected):
268
282
            self.assertEqualDiff(''.join('\t'.join(l) for l in expected),
269
283
                                 ''.join('\t'.join(l) for l in actual))
270
284
 
271
 
    def assertBranchAnnotate(self, expected, branch, file_id, revision_id,
272
 
            verbose=False, full=False, show_ids=False):
 
285
    def assertBranchAnnotate(self, expected, branch, path, revision_id,
 
286
                             verbose=False, full=False, show_ids=False):
273
287
        tree = branch.repository.revision_tree(revision_id)
274
288
        to_file = StringIO()
275
 
        annotate.annotate_file_tree(tree, file_id, to_file,
276
 
            verbose=verbose, full=full, show_ids=show_ids, branch=branch)
 
289
        annotate.annotate_file_tree(tree, path, to_file,
 
290
                                    verbose=verbose, full=full, show_ids=show_ids, branch=branch)
277
291
        self.assertAnnotateEqualDiff(to_file.getvalue(), expected)
278
292
 
279
 
    def assertRepoAnnotate(self, expected, repo, file_id, revision_id):
 
293
    def assertRepoAnnotate(self, expected, repo, path, revision_id):
280
294
        """Assert that the revision is properly annotated."""
281
 
        actual = list(repo.revision_tree(revision_id).annotate_iter(file_id))
 
295
        actual = list(repo.revision_tree(revision_id).annotate_iter(path))
282
296
        self.assertAnnotateEqualDiff(actual, expected)
283
297
 
284
298
    def test_annotate_duplicate_lines(self):
287
301
        repo = builder.get_branch().repository
288
302
        repo.lock_read()
289
303
        self.addCleanup(repo.unlock)
290
 
        self.assertRepoAnnotate(duplicate_base, repo, 'file-id', 'rev-base')
291
 
        self.assertRepoAnnotate(duplicate_A, repo, 'file-id', 'rev-A')
292
 
        self.assertRepoAnnotate(duplicate_B, repo, 'file-id', 'rev-B')
293
 
        self.assertRepoAnnotate(duplicate_C, repo, 'file-id', 'rev-C')
294
 
        self.assertRepoAnnotate(duplicate_D, repo, 'file-id', 'rev-D')
295
 
        self.assertRepoAnnotate(duplicate_E, repo, 'file-id', 'rev-E')
 
304
        self.assertRepoAnnotate(duplicate_base, repo, 'file', b'rev-base')
 
305
        self.assertRepoAnnotate(duplicate_A, repo, 'file', b'rev-A')
 
306
        self.assertRepoAnnotate(duplicate_B, repo, 'file', b'rev-B')
 
307
        self.assertRepoAnnotate(duplicate_C, repo, 'file', b'rev-C')
 
308
        self.assertRepoAnnotate(duplicate_D, repo, 'file', b'rev-D')
 
309
        self.assertRepoAnnotate(duplicate_E, repo, 'file', b'rev-E')
296
310
 
297
311
    def test_annotate_shows_dotted_revnos(self):
298
312
        builder = self.create_merged_trees()
300
314
        self.assertBranchAnnotate('1     joe@foo | first\n'
301
315
                                  '2     joe@foo | second\n'
302
316
                                  '1.1.1 barry@f | third\n',
303
 
                                  builder.get_branch(), 'a-id', 'rev-3')
 
317
                                  builder.get_branch(), 'a', b'rev-3')
304
318
 
305
319
    def test_annotate_limits_dotted_revnos(self):
306
320
        """Annotate should limit dotted revnos to a depth of 12"""
312
326
                                  '1.2.1 jerry@f | fourth\n'
313
327
                                  '1.3.1 george@ | fifth\n'
314
328
                                  '              | sixth\n',
315
 
                                  builder.get_branch(), 'a-id', 'rev-6',
 
329
                                  builder.get_branch(), 'a', b'rev-6',
316
330
                                  verbose=False, full=False)
317
331
 
318
332
        self.assertBranchAnnotate('1     joe@foo | first\n'
321
335
                                  '1.2.1 jerry@f | fourth\n'
322
336
                                  '1.3.1 george@ | fifth\n'
323
337
                                  '1.3.1 george@ | sixth\n',
324
 
                                  builder.get_branch(), 'a-id', 'rev-6',
 
338
                                  builder.get_branch(), 'a', b'rev-6',
325
339
                                  verbose=False, full=True)
326
340
 
327
341
        # verbose=True shows everything, the full revno, user id, and date
331
345
                                  '1.2.1 jerry@foo.com  20061213 | fourth\n'
332
346
                                  '1.3.1 george@foo.com 20061213 | fifth\n'
333
347
                                  '                              | sixth\n',
334
 
                                  builder.get_branch(), 'a-id', 'rev-6',
 
348
                                  builder.get_branch(), 'a', b'rev-6',
335
349
                                  verbose=True, full=False)
336
350
 
337
351
        self.assertBranchAnnotate('1     joe@foo.com    20061213 | first\n'
340
354
                                  '1.2.1 jerry@foo.com  20061213 | fourth\n'
341
355
                                  '1.3.1 george@foo.com 20061213 | fifth\n'
342
356
                                  '1.3.1 george@foo.com 20061213 | sixth\n',
343
 
                                  builder.get_branch(), 'a-id', 'rev-6',
 
357
                                  builder.get_branch(), 'a', b'rev-6',
344
358
                                  verbose=True, full=True)
345
359
 
346
360
    def test_annotate_uses_branch_context(self):
356
370
                                  '1.2.1 jerry@f | fourth\n'
357
371
                                  '1.3.1 george@ | fifth\n'
358
372
                                  '              | sixth\n',
359
 
                                  builder.get_branch(), 'a-id', 'rev-1_3_1',
 
373
                                  builder.get_branch(), 'a', b'rev-1_3_1',
360
374
                                  verbose=False, full=False)
361
375
 
362
376
    def test_annotate_show_ids(self):
369
383
                                  'rev-1_2_1 | fourth\n'
370
384
                                  'rev-1_3_1 | fifth\n'
371
385
                                  '          | sixth\n',
372
 
                                  builder.get_branch(), 'a-id', 'rev-6',
 
386
                                  builder.get_branch(), 'a', b'rev-6',
373
387
                                  show_ids=True, full=False)
374
388
 
375
389
        self.assertBranchAnnotate('    rev-1 | first\n'
378
392
                                  'rev-1_2_1 | fourth\n'
379
393
                                  'rev-1_3_1 | fifth\n'
380
394
                                  'rev-1_3_1 | sixth\n',
381
 
                                  builder.get_branch(), 'a-id', 'rev-6',
 
395
                                  builder.get_branch(), 'a', b'rev-6',
382
396
                                  show_ids=True, full=True)
383
397
 
384
398
    def test_annotate_unicode_author(self):
385
399
        tree1 = self.make_branch_and_tree('tree1')
386
400
 
387
 
        self.build_tree_contents([('tree1/a', 'adi\xc3\xb3s')])
388
 
        tree1.add(['a'], ['a-id'])
389
 
        tree1.commit('a', rev_id='rev-1',
 
401
        self.build_tree_contents([('tree1/a', b'adi\xc3\xb3s')])
 
402
        tree1.add(['a'], [b'a-id'])
 
403
        tree1.commit('a', rev_id=b'rev-1',
390
404
                     committer=u'Pepe P\xe9rez <pperez@ejemplo.com>',
391
405
                     timestamp=1166046000.00, timezone=0)
392
406
 
393
 
        self.build_tree_contents([('tree1/b', 'bye')])
394
 
        tree1.add(['b'], ['b-id'])
395
 
        tree1.commit('b', rev_id='rev-2',
 
407
        self.build_tree_contents([('tree1/b', b'bye')])
 
408
        tree1.add(['b'], [b'b-id'])
 
409
        tree1.commit('b', rev_id=b'rev-2',
396
410
                     committer=u'p\xe9rez',
397
411
                     timestamp=1166046000.00, timezone=0)
398
412
 
399
413
        tree1.lock_read()
400
414
        self.addCleanup(tree1.unlock)
401
415
 
402
 
        revtree_1 = tree1.branch.repository.revision_tree('rev-1')
403
 
        revtree_2 = tree1.branch.repository.revision_tree('rev-2')
 
416
        revtree_1 = tree1.branch.repository.revision_tree(b'rev-1')
 
417
        revtree_2 = tree1.branch.repository.revision_tree(b'rev-2')
404
418
 
405
419
        # this passes if no exception is raised
406
420
        to_file = StringIO()
407
 
        annotate.annotate_file_tree(revtree_1, 'a-id',
408
 
            to_file=to_file, branch=tree1.branch)
409
 
 
410
 
        sio = StringIO()
411
 
        to_file = codecs.getwriter('ascii')(sio)
412
 
        to_file.encoding = 'ascii' # codecs does not set it
413
 
        annotate.annotate_file_tree(revtree_2, 'b-id',
414
 
            to_file=to_file, branch=tree1.branch)
415
 
        self.assertEqualDiff('2   p?rez   | bye\n', sio.getvalue())
416
 
 
417
 
        # test now with to_file.encoding = None
418
 
        to_file = tests.StringIOWrapper()
419
 
        to_file.encoding = None
420
 
        annotate.annotate_file_tree(revtree_2, 'b-id',
421
 
            to_file=to_file, branch=tree1.branch)
422
 
        self.assertContainsRe('2   p.rez   | bye\n', to_file.getvalue())
423
 
 
424
 
        # and when it does not exist
425
 
        to_file = StringIO()
426
 
        annotate.annotate_file_tree(revtree_2, 'b-id',
427
 
            to_file=to_file, branch=tree1.branch)
428
 
        self.assertContainsRe('2   p.rez   | bye\n', to_file.getvalue())
 
421
        annotate.annotate_file_tree(revtree_1, 'a',
 
422
                                    to_file=to_file, branch=tree1.branch)
 
423
 
 
424
        sio = BytesIO()
 
425
        to_file = codecs.getwriter('ascii')(sio, 'replace')
 
426
        annotate.annotate_file_tree(revtree_2, 'b',
 
427
                                    to_file=to_file, branch=tree1.branch)
 
428
        self.assertEqualDiff(b'2   p?rez   | bye\n', sio.getvalue())
 
429
 
 
430
        # test now with unicode file-like
 
431
        to_file = StringIOWithEncoding()
 
432
        annotate.annotate_file_tree(revtree_2, 'b',
 
433
                                    to_file=to_file, branch=tree1.branch)
 
434
        self.assertContainsRe(u'2   p\xe9rez   | bye\n', to_file.getvalue())
429
435
 
430
436
    def test_annotate_author_or_committer(self):
431
437
        tree1 = self.make_branch_and_tree('tree1')
432
438
 
433
 
        self.build_tree_contents([('tree1/a', 'hello')])
434
 
        tree1.add(['a'], ['a-id'])
435
 
        tree1.commit('a', rev_id='rev-1',
 
439
        self.build_tree_contents([('tree1/a', b'hello')])
 
440
        tree1.add(['a'], [b'a-id'])
 
441
        tree1.commit('a', rev_id=b'rev-1',
436
442
                     committer='Committer <committer@example.com>',
437
443
                     timestamp=1166046000.00, timezone=0)
438
444
 
439
 
        self.build_tree_contents([('tree1/b', 'bye')])
440
 
        tree1.add(['b'], ['b-id'])
441
 
        tree1.commit('b', rev_id='rev-2',
 
445
        self.build_tree_contents([('tree1/b', b'bye')])
 
446
        tree1.add(['b'], [b'b-id'])
 
447
        tree1.commit('b', rev_id=b'rev-2',
442
448
                     committer='Committer <committer@example.com>',
443
449
                     authors=['Author <author@example.com>'],
444
450
                     timestamp=1166046000.00, timezone=0)
447
453
        self.addCleanup(tree1.unlock)
448
454
 
449
455
        self.assertBranchAnnotate('1   committ | hello\n', tree1.branch,
450
 
            'a-id', 'rev-1')
 
456
                                  'a', b'rev-1')
451
457
 
452
 
        to_file = StringIO()
453
458
        self.assertBranchAnnotate('2   author@ | bye\n', tree1.branch,
454
 
            'b-id', 'rev-2')
 
459
                                  'b', b'rev-2')
455
460
 
456
461
 
457
462
class TestReannotate(tests.TestCase):
459
464
    def annotateEqual(self, expected, parents, newlines, revision_id,
460
465
                      blocks=None):
461
466
        annotate_list = list(annotate.reannotate(parents, newlines,
462
 
                             revision_id, blocks))
 
467
                                                 revision_id, blocks))
463
468
        self.assertEqual(len(expected), len(annotate_list))
464
469
        for e, a in zip(expected, annotate_list):
465
470
            self.assertEqual(e, a)
466
471
 
467
472
    def test_reannotate(self):
468
 
        self.annotateEqual(parent_1, [parent_1], new_1, 'blahblah')
469
 
        self.annotateEqual(expected_2_1, [parent_2], new_1, 'blahblah')
 
473
        self.annotateEqual(parent_1, [parent_1], new_1, b'blahblah')
 
474
        self.annotateEqual(expected_2_1, [parent_2], new_1, b'blahblah')
470
475
        self.annotateEqual(expected_1_2_2, [parent_1, parent_2], new_2,
471
 
                           'blahblah')
 
476
                           b'blahblah')
472
477
 
473
478
    def test_reannotate_no_parents(self):
474
 
        self.annotateEqual(expected_1, [], new_1, 'blahblah')
 
479
        self.annotateEqual(expected_1, [], new_1, b'blahblah')
475
480
 
476
481
    def test_reannotate_left_matching_blocks(self):
477
482
        """Ensure that left_matching_blocks has an impact.
479
484
        In this case, the annotation is ambiguous, so the hint isn't actually
480
485
        lying.
481
486
        """
482
 
        parent = [('rev1', 'a\n')]
483
 
        new_text = ['a\n', 'a\n']
 
487
        parent = [(b'rev1', b'a\n')]
 
488
        new_text = [b'a\n', b'a\n']
484
489
        blocks = [(0, 0, 1), (1, 2, 0)]
485
 
        self.annotateEqual([('rev1', 'a\n'), ('rev2', 'a\n')], [parent],
486
 
                           new_text, 'rev2', blocks)
 
490
        self.annotateEqual([(b'rev1', b'a\n'), (b'rev2', b'a\n')], [parent],
 
491
                           new_text, b'rev2', blocks)
487
492
        blocks = [(0, 1, 1), (1, 2, 0)]
488
 
        self.annotateEqual([('rev2', 'a\n'), ('rev1', 'a\n')], [parent],
489
 
                           new_text, 'rev2', blocks)
 
493
        self.annotateEqual([(b'rev2', b'a\n'), (b'rev1', b'a\n')], [parent],
 
494
                           new_text, b'rev2', blocks)