301
314
'rev-1_1_1_1_1_1_1 | sixth\n',
317
def test_annotate_unicode_author(self):
318
tree1 = self.make_branch_and_tree('tree1')
320
self.build_tree_contents([('tree1/a', 'adi\xc3\xb3s')])
321
tree1.add(['a'], ['a-id'])
322
tree1.commit('a', rev_id='rev-1',
323
committer=u'Pepe P\xe9rez <pperez@ejemplo.com>',
324
timestamp=1166046000.00, timezone=0)
326
self.build_tree_contents([('tree1/b', 'bye')])
327
tree1.add(['b'], ['b-id'])
328
tree1.commit('b', rev_id='rev-2',
329
committer=u'p\xe9rez',
330
timestamp=1166046000.00, timezone=0)
333
self.addCleanup(tree1.unlock)
334
# this passes if no exception is raised
336
annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
339
to_file = codecs.getwriter('ascii')(sio)
340
to_file.encoding = 'ascii' # codecs does not set it
341
annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
342
self.assertEqualDiff('2 p?rez | bye\n', sio.getvalue())
344
# test now with to_file.encoding = None
345
to_file = tests.StringIOWrapper()
346
to_file.encoding = None
347
annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
348
self.assertContainsRe('2 p.rez | bye\n', to_file.getvalue())
350
# and when it does not exist
352
annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
353
self.assertContainsRe('2 p.rez | bye\n', to_file.getvalue())
355
def test_annotate_author_or_committer(self):
356
tree1 = self.make_branch_and_tree('tree1')
358
self.build_tree_contents([('tree1/a', 'hello')])
359
tree1.add(['a'], ['a-id'])
360
tree1.commit('a', rev_id='rev-1',
361
committer='Committer <committer@example.com>',
362
timestamp=1166046000.00, timezone=0)
364
self.build_tree_contents([('tree1/b', 'bye')])
365
tree1.add(['b'], ['b-id'])
366
tree1.commit('b', rev_id='rev-2',
367
committer='Committer <committer@example.com>',
368
author='Author <author@example.com>',
369
timestamp=1166046000.00, timezone=0)
372
self.addCleanup(tree1.unlock)
374
annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
375
self.assertEqual('1 committ | hello\n', to_file.getvalue())
378
annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
379
self.assertEqual('2 author@ | bye\n', to_file.getvalue())
305
382
class TestReannotate(tests.TestCase):
307
def annotateEqual(self, expected, parents, newlines, revision_id):
384
def annotateEqual(self, expected, parents, newlines, revision_id,
308
386
annotate_list = list(annotate.reannotate(parents, newlines,
387
revision_id, blocks))
310
388
self.assertEqual(len(expected), len(annotate_list))
311
389
for e, a in zip(expected, annotate_list):
312
390
self.assertEqual(e, a)
316
394
self.annotateEqual(expected_2_1, [parent_2], new_1, 'blahblah')
317
395
self.annotateEqual(expected_1_2_2, [parent_1, parent_2], new_2,
398
def test_reannotate_no_parents(self):
399
self.annotateEqual(expected_1, [], new_1, 'blahblah')
401
def test_reannotate_left_matching_blocks(self):
402
"""Ensure that left_matching_blocks has an impact.
404
In this case, the annotation is ambiguous, so the hint isn't actually
407
parent = [('rev1', 'a\n')]
408
new_text = ['a\n', 'a\n']
409
blocks = [(0, 0, 1), (1, 2, 0)]
410
self.annotateEqual([('rev1', 'a\n'), ('rev2', 'a\n')], [parent],
411
new_text, 'rev2', blocks)
412
blocks = [(0, 1, 1), (1, 2, 0)]
413
self.annotateEqual([('rev2', 'a\n'), ('rev1', 'a\n')], [parent],
414
new_text, 'rev2', blocks)