~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_annotate.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-05-11 11:47:36 UTC
  • mfrom: (5200.3.8 lock_return)
  • Revision ID: pqm@pqm.ubuntu.com-20100511114736-mc1sq9zyo3vufec7
(lifeless) Provide a consistent interface to Tree, Branch,
 Repository where lock methods return an object with an unlock method to
 unlock the lock. This breaks the API for Branch,
 Repository on their lock_write methods. (Robert Collins)

Show diffs side-by-side

added added

removed removed

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