~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_annotate.py

  • Committer: Patch Queue Manager
  • Date: 2013-10-07 17:04:34 UTC
  • mfrom: (6588.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20131007170434-mb0ahksmrzsnhi1i
(vila) Stricter checks on configuration option names (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from bzrlib import (
23
23
    annotate,
 
24
    symbol_versioning,
24
25
    tests,
25
26
    )
26
27
 
260
261
            ('modify', ('file-id', e_text))])
261
262
        return builder
262
263
 
263
 
    def assertRepoAnnotate(self, expected, repo, file_id, revision_id):
264
 
        """Assert that the revision is properly annotated."""
265
 
        actual = list(repo.revision_tree(revision_id).annotate_iter(file_id))
 
264
    def assertAnnotateEqualDiff(self, actual, expected):
266
265
        if actual != expected:
267
266
            # Create an easier to understand diff when the lines don't actually
268
267
            # match
269
268
            self.assertEqualDiff(''.join('\t'.join(l) for l in expected),
270
269
                                 ''.join('\t'.join(l) for l in actual))
271
270
 
 
271
    def assertBranchAnnotate(self, expected, branch, file_id, revision_id,
 
272
            verbose=False, full=False, show_ids=False):
 
273
        tree = branch.repository.revision_tree(revision_id)
 
274
        to_file = StringIO()
 
275
        annotate.annotate_file_tree(tree, file_id, to_file,
 
276
            verbose=verbose, full=full, show_ids=show_ids, branch=branch)
 
277
        self.assertAnnotateEqualDiff(to_file.getvalue(), expected)
 
278
 
 
279
    def assertRepoAnnotate(self, expected, repo, file_id, revision_id):
 
280
        """Assert that the revision is properly annotated."""
 
281
        actual = list(repo.revision_tree(revision_id).annotate_iter(file_id))
 
282
        self.assertAnnotateEqualDiff(actual, expected)
 
283
 
272
284
    def test_annotate_duplicate_lines(self):
273
285
        # XXX: Should this be a per_repository test?
274
286
        builder = self.create_duplicate_lines_tree()
285
297
    def test_annotate_shows_dotted_revnos(self):
286
298
        builder = self.create_merged_trees()
287
299
 
288
 
        sio = StringIO()
289
 
        annotate.annotate_file(builder.get_branch(), 'rev-3', 'a-id',
290
 
                               to_file=sio)
291
 
        self.assertEqualDiff('1     joe@foo | first\n'
292
 
                             '2     joe@foo | second\n'
293
 
                             '1.1.1 barry@f | third\n',
294
 
                             sio.getvalue())
 
300
        self.assertBranchAnnotate('1     joe@foo | first\n'
 
301
                                  '2     joe@foo | second\n'
 
302
                                  '1.1.1 barry@f | third\n',
 
303
                                  builder.get_branch(), 'a-id', 'rev-3')
295
304
 
296
305
    def test_annotate_limits_dotted_revnos(self):
297
306
        """Annotate should limit dotted revnos to a depth of 12"""
298
307
        builder = self.create_deeply_merged_trees()
299
308
 
300
 
        sio = StringIO()
301
 
        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
302
 
                               to_file=sio, verbose=False, full=False)
303
 
        self.assertEqualDiff('1     joe@foo | first\n'
304
 
                             '2     joe@foo | second\n'
305
 
                             '1.1.1 barry@f | third\n'
306
 
                             '1.2.1 jerry@f | fourth\n'
307
 
                             '1.3.1 george@ | fifth\n'
308
 
                             '              | sixth\n',
309
 
                             sio.getvalue())
 
309
        self.assertBranchAnnotate('1     joe@foo | first\n'
 
310
                                  '2     joe@foo | second\n'
 
311
                                  '1.1.1 barry@f | third\n'
 
312
                                  '1.2.1 jerry@f | fourth\n'
 
313
                                  '1.3.1 george@ | fifth\n'
 
314
                                  '              | sixth\n',
 
315
                                  builder.get_branch(), 'a-id', 'rev-6',
 
316
                                  verbose=False, full=False)
310
317
 
311
 
        sio = StringIO()
312
 
        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
313
 
                               to_file=sio, verbose=False, full=True)
314
 
        self.assertEqualDiff('1     joe@foo | first\n'
315
 
                             '2     joe@foo | second\n'
316
 
                             '1.1.1 barry@f | third\n'
317
 
                             '1.2.1 jerry@f | fourth\n'
318
 
                             '1.3.1 george@ | fifth\n'
319
 
                             '1.3.1 george@ | sixth\n',
320
 
                             sio.getvalue())
 
318
        self.assertBranchAnnotate('1     joe@foo | first\n'
 
319
                                  '2     joe@foo | second\n'
 
320
                                  '1.1.1 barry@f | third\n'
 
321
                                  '1.2.1 jerry@f | fourth\n'
 
322
                                  '1.3.1 george@ | fifth\n'
 
323
                                  '1.3.1 george@ | sixth\n',
 
324
                                  builder.get_branch(), 'a-id', 'rev-6',
 
325
                                  verbose=False, full=True)
321
326
 
322
327
        # verbose=True shows everything, the full revno, user id, and date
323
 
        sio = StringIO()
324
 
        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
325
 
                               to_file=sio, verbose=True, full=False)
326
 
        self.assertEqualDiff('1     joe@foo.com    20061213 | first\n'
327
 
                             '2     joe@foo.com    20061213 | second\n'
328
 
                             '1.1.1 barry@foo.com  20061213 | third\n'
329
 
                             '1.2.1 jerry@foo.com  20061213 | fourth\n'
330
 
                             '1.3.1 george@foo.com 20061213 | fifth\n'
331
 
                             '                              | sixth\n',
332
 
                             sio.getvalue())
 
328
        self.assertBranchAnnotate('1     joe@foo.com    20061213 | first\n'
 
329
                                  '2     joe@foo.com    20061213 | second\n'
 
330
                                  '1.1.1 barry@foo.com  20061213 | third\n'
 
331
                                  '1.2.1 jerry@foo.com  20061213 | fourth\n'
 
332
                                  '1.3.1 george@foo.com 20061213 | fifth\n'
 
333
                                  '                              | sixth\n',
 
334
                                  builder.get_branch(), 'a-id', 'rev-6',
 
335
                                  verbose=True, full=False)
333
336
 
334
 
        sio = StringIO()
335
 
        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
336
 
                               to_file=sio, verbose=True, full=True)
337
 
        self.assertEqualDiff('1     joe@foo.com    20061213 | first\n'
338
 
                             '2     joe@foo.com    20061213 | second\n'
339
 
                             '1.1.1 barry@foo.com  20061213 | third\n'
340
 
                             '1.2.1 jerry@foo.com  20061213 | fourth\n'
341
 
                             '1.3.1 george@foo.com 20061213 | fifth\n'
342
 
                             '1.3.1 george@foo.com 20061213 | sixth\n',
343
 
                             sio.getvalue())
 
337
        self.assertBranchAnnotate('1     joe@foo.com    20061213 | first\n'
 
338
                                  '2     joe@foo.com    20061213 | second\n'
 
339
                                  '1.1.1 barry@foo.com  20061213 | third\n'
 
340
                                  '1.2.1 jerry@foo.com  20061213 | fourth\n'
 
341
                                  '1.3.1 george@foo.com 20061213 | fifth\n'
 
342
                                  '1.3.1 george@foo.com 20061213 | sixth\n',
 
343
                                  builder.get_branch(), 'a-id', 'rev-6',
 
344
                                  verbose=True, full=True)
344
345
 
345
346
    def test_annotate_uses_branch_context(self):
346
347
        """Dotted revnos should use the Branch context.
350
351
        """
351
352
        builder = self.create_deeply_merged_trees()
352
353
 
353
 
        sio = StringIO()
354
 
        annotate.annotate_file(builder.get_branch(), 'rev-1_3_1', 'a-id',
355
 
                               to_file=sio, verbose=False, full=False)
356
 
        self.assertEqualDiff('1     joe@foo | first\n'
357
 
                             '1.1.1 barry@f | third\n'
358
 
                             '1.2.1 jerry@f | fourth\n'
359
 
                             '1.3.1 george@ | fifth\n'
360
 
                             '              | sixth\n',
361
 
                             sio.getvalue())
 
354
        self.assertBranchAnnotate('1     joe@foo | first\n'
 
355
                                  '1.1.1 barry@f | third\n'
 
356
                                  '1.2.1 jerry@f | fourth\n'
 
357
                                  '1.3.1 george@ | fifth\n'
 
358
                                  '              | sixth\n',
 
359
                                  builder.get_branch(), 'a-id', 'rev-1_3_1',
 
360
                                  verbose=False, full=False)
362
361
 
363
362
    def test_annotate_show_ids(self):
364
363
        builder = self.create_deeply_merged_trees()
365
364
 
366
 
        sio = StringIO()
367
 
        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
368
 
                               to_file=sio, show_ids=True, full=False)
369
 
 
370
365
        # It looks better with real revision ids :)
371
 
        self.assertEqualDiff('    rev-1 | first\n'
372
 
                             '    rev-2 | second\n'
373
 
                             'rev-1_1_1 | third\n'
374
 
                             'rev-1_2_1 | fourth\n'
375
 
                             'rev-1_3_1 | fifth\n'
376
 
                             '          | sixth\n',
377
 
                             sio.getvalue())
378
 
 
379
 
        sio = StringIO()
380
 
        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
381
 
                               to_file=sio, show_ids=True, full=True)
382
 
 
383
 
        self.assertEqualDiff('    rev-1 | first\n'
384
 
                             '    rev-2 | second\n'
385
 
                             'rev-1_1_1 | third\n'
386
 
                             'rev-1_2_1 | fourth\n'
387
 
                             'rev-1_3_1 | fifth\n'
388
 
                             'rev-1_3_1 | sixth\n',
389
 
                             sio.getvalue())
 
366
        self.assertBranchAnnotate('    rev-1 | first\n'
 
367
                                  '    rev-2 | second\n'
 
368
                                  'rev-1_1_1 | third\n'
 
369
                                  'rev-1_2_1 | fourth\n'
 
370
                                  'rev-1_3_1 | fifth\n'
 
371
                                  '          | sixth\n',
 
372
                                  builder.get_branch(), 'a-id', 'rev-6',
 
373
                                  show_ids=True, full=False)
 
374
 
 
375
        self.assertBranchAnnotate('    rev-1 | first\n'
 
376
                                  '    rev-2 | second\n'
 
377
                                  'rev-1_1_1 | third\n'
 
378
                                  'rev-1_2_1 | fourth\n'
 
379
                                  'rev-1_3_1 | fifth\n'
 
380
                                  'rev-1_3_1 | sixth\n',
 
381
                                  builder.get_branch(), 'a-id', 'rev-6',
 
382
                                  show_ids=True, full=True)
390
383
 
391
384
    def test_annotate_unicode_author(self):
392
385
        tree1 = self.make_branch_and_tree('tree1')
405
398
 
406
399
        tree1.lock_read()
407
400
        self.addCleanup(tree1.unlock)
 
401
 
 
402
        revtree_1 = tree1.branch.repository.revision_tree('rev-1')
 
403
        revtree_2 = tree1.branch.repository.revision_tree('rev-2')
 
404
 
408
405
        # this passes if no exception is raised
409
406
        to_file = StringIO()
410
 
        annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
 
407
        annotate.annotate_file_tree(revtree_1, 'a-id',
 
408
            to_file=to_file, branch=tree1.branch)
411
409
 
412
410
        sio = StringIO()
413
411
        to_file = codecs.getwriter('ascii')(sio)
414
412
        to_file.encoding = 'ascii' # codecs does not set it
415
 
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
 
413
        annotate.annotate_file_tree(revtree_2, 'b-id',
 
414
            to_file=to_file, branch=tree1.branch)
416
415
        self.assertEqualDiff('2   p?rez   | bye\n', sio.getvalue())
417
416
 
418
417
        # test now with to_file.encoding = None
419
418
        to_file = tests.StringIOWrapper()
420
419
        to_file.encoding = None
421
 
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
 
420
        annotate.annotate_file_tree(revtree_2, 'b-id',
 
421
            to_file=to_file, branch=tree1.branch)
422
422
        self.assertContainsRe('2   p.rez   | bye\n', to_file.getvalue())
423
423
 
424
424
        # and when it does not exist
425
425
        to_file = StringIO()
426
 
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
 
426
        annotate.annotate_file_tree(revtree_2, 'b-id',
 
427
            to_file=to_file, branch=tree1.branch)
427
428
        self.assertContainsRe('2   p.rez   | bye\n', to_file.getvalue())
428
429
 
429
430
    def test_annotate_author_or_committer(self):
444
445
 
445
446
        tree1.lock_read()
446
447
        self.addCleanup(tree1.unlock)
447
 
        to_file = StringIO()
448
 
        annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
449
 
        self.assertEqual('1   committ | hello\n', to_file.getvalue())
450
 
 
451
 
        to_file = StringIO()
452
 
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
453
 
        self.assertEqual('2   author@ | bye\n', to_file.getvalue())
 
448
 
 
449
        self.assertBranchAnnotate('1   committ | hello\n', tree1.branch,
 
450
            'a-id', 'rev-1')
 
451
 
 
452
        to_file = StringIO()
 
453
        self.assertBranchAnnotate('2   author@ | bye\n', tree1.branch,
 
454
            'b-id', 'rev-2')
454
455
 
455
456
 
456
457
class TestReannotate(tests.TestCase):