~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_annotate.py

(vila) Forbid more operations on ReadonlyTransportDecorator (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006-2009, 2011 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
 
    conflicts,
25
 
    errors,
 
24
    symbol_versioning,
26
25
    tests,
27
 
    trace,
28
26
    )
29
27
 
30
28
 
263
261
            ('modify', ('file-id', e_text))])
264
262
        return builder
265
263
 
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))
 
264
    def assertAnnotateEqualDiff(self, actual, expected):
269
265
        if actual != expected:
270
266
            # Create an easier to understand diff when the lines don't actually
271
267
            # match
272
268
            self.assertEqualDiff(''.join('\t'.join(l) for l in expected),
273
269
                                 ''.join('\t'.join(l) for l in actual))
274
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
 
275
284
    def test_annotate_duplicate_lines(self):
276
285
        # XXX: Should this be a per_repository test?
277
286
        builder = self.create_duplicate_lines_tree()
288
297
    def test_annotate_shows_dotted_revnos(self):
289
298
        builder = self.create_merged_trees()
290
299
 
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())
 
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')
298
304
 
299
305
    def test_annotate_limits_dotted_revnos(self):
300
306
        """Annotate should limit dotted revnos to a depth of 12"""
301
307
        builder = self.create_deeply_merged_trees()
302
308
 
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())
 
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)
313
317
 
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())
 
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)
324
326
 
325
327
        # verbose=True shows everything, the full revno, user id, and date
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())
 
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)
336
336
 
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())
 
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)
347
345
 
348
346
    def test_annotate_uses_branch_context(self):
349
347
        """Dotted revnos should use the Branch context.
353
351
        """
354
352
        builder = self.create_deeply_merged_trees()
355
353
 
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())
 
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)
365
361
 
366
362
    def test_annotate_show_ids(self):
367
363
        builder = self.create_deeply_merged_trees()
368
364
 
369
 
        sio = StringIO()
370
 
        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
371
 
                               to_file=sio, show_ids=True, full=False)
372
 
 
373
365
        # It looks better with real revision ids :)
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())
 
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)
393
383
 
394
384
    def test_annotate_unicode_author(self):
395
385
        tree1 = self.make_branch_and_tree('tree1')
408
398
 
409
399
        tree1.lock_read()
410
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
 
411
405
        # this passes if no exception is raised
412
406
        to_file = StringIO()
413
 
        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)
414
409
 
415
410
        sio = StringIO()
416
411
        to_file = codecs.getwriter('ascii')(sio)
417
412
        to_file.encoding = 'ascii' # codecs does not set it
418
 
        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)
419
415
        self.assertEqualDiff('2   p?rez   | bye\n', sio.getvalue())
420
416
 
421
417
        # test now with to_file.encoding = None
422
418
        to_file = tests.StringIOWrapper()
423
419
        to_file.encoding = None
424
 
        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)
425
422
        self.assertContainsRe('2   p.rez   | bye\n', to_file.getvalue())
426
423
 
427
424
        # and when it does not exist
428
425
        to_file = StringIO()
429
 
        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)
430
428
        self.assertContainsRe('2   p.rez   | bye\n', to_file.getvalue())
431
429
 
432
430
    def test_annotate_author_or_committer(self):
447
445
 
448
446
        tree1.lock_read()
449
447
        self.addCleanup(tree1.unlock)
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())
 
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')
457
455
 
458
456
 
459
457
class TestReannotate(tests.TestCase):