/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: Jelmer Vernooij
  • Date: 2017-05-22 00:56:52 UTC
  • mfrom: (6621.2.26 py3_pokes)
  • Revision ID: jelmer@jelmer.uk-20170522005652-yjahcr9hwmjkno7n
Merge Python3 porting work ('py3 pokes')

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
17
17
"""Whitebox tests for annotate functionality."""
18
18
 
19
19
import codecs
20
 
from cStringIO import StringIO
21
20
 
22
 
from bzrlib import (
 
21
from .. import (
23
22
    annotate,
24
 
    conflicts,
25
 
    errors,
 
23
    symbol_versioning,
26
24
    tests,
27
 
    trace,
28
 
    )
 
25
    )
 
26
from ..sixish import (
 
27
    BytesIO,
 
28
    )
 
29
from .ui_testing import StringIOWithEncoding
29
30
 
30
31
 
31
32
def annotation(text):
263
264
            ('modify', ('file-id', e_text))])
264
265
        return builder
265
266
 
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))
 
267
    def assertAnnotateEqualDiff(self, actual, expected):
269
268
        if actual != expected:
270
269
            # Create an easier to understand diff when the lines don't actually
271
270
            # match
272
271
            self.assertEqualDiff(''.join('\t'.join(l) for l in expected),
273
272
                                 ''.join('\t'.join(l) for l in actual))
274
273
 
 
274
    def assertBranchAnnotate(self, expected, branch, file_id, revision_id,
 
275
            verbose=False, full=False, show_ids=False):
 
276
        tree = branch.repository.revision_tree(revision_id)
 
277
        to_file = BytesIO()
 
278
        annotate.annotate_file_tree(tree, file_id, to_file,
 
279
            verbose=verbose, full=full, show_ids=show_ids, branch=branch)
 
280
        self.assertAnnotateEqualDiff(to_file.getvalue(), expected)
 
281
 
 
282
    def assertRepoAnnotate(self, expected, repo, file_id, revision_id):
 
283
        """Assert that the revision is properly annotated."""
 
284
        actual = list(repo.revision_tree(revision_id).annotate_iter(file_id))
 
285
        self.assertAnnotateEqualDiff(actual, expected)
 
286
 
275
287
    def test_annotate_duplicate_lines(self):
276
288
        # XXX: Should this be a per_repository test?
277
289
        builder = self.create_duplicate_lines_tree()
288
300
    def test_annotate_shows_dotted_revnos(self):
289
301
        builder = self.create_merged_trees()
290
302
 
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())
 
303
        self.assertBranchAnnotate('1     joe@foo | first\n'
 
304
                                  '2     joe@foo | second\n'
 
305
                                  '1.1.1 barry@f | third\n',
 
306
                                  builder.get_branch(), 'a-id', 'rev-3')
298
307
 
299
308
    def test_annotate_limits_dotted_revnos(self):
300
309
        """Annotate should limit dotted revnos to a depth of 12"""
301
310
        builder = self.create_deeply_merged_trees()
302
311
 
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())
 
312
        self.assertBranchAnnotate('1     joe@foo | first\n'
 
313
                                  '2     joe@foo | second\n'
 
314
                                  '1.1.1 barry@f | third\n'
 
315
                                  '1.2.1 jerry@f | fourth\n'
 
316
                                  '1.3.1 george@ | fifth\n'
 
317
                                  '              | sixth\n',
 
318
                                  builder.get_branch(), 'a-id', 'rev-6',
 
319
                                  verbose=False, full=False)
313
320
 
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())
 
321
        self.assertBranchAnnotate('1     joe@foo | first\n'
 
322
                                  '2     joe@foo | second\n'
 
323
                                  '1.1.1 barry@f | third\n'
 
324
                                  '1.2.1 jerry@f | fourth\n'
 
325
                                  '1.3.1 george@ | fifth\n'
 
326
                                  '1.3.1 george@ | sixth\n',
 
327
                                  builder.get_branch(), 'a-id', 'rev-6',
 
328
                                  verbose=False, full=True)
324
329
 
325
330
        # 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())
 
331
        self.assertBranchAnnotate('1     joe@foo.com    20061213 | first\n'
 
332
                                  '2     joe@foo.com    20061213 | second\n'
 
333
                                  '1.1.1 barry@foo.com  20061213 | third\n'
 
334
                                  '1.2.1 jerry@foo.com  20061213 | fourth\n'
 
335
                                  '1.3.1 george@foo.com 20061213 | fifth\n'
 
336
                                  '                              | sixth\n',
 
337
                                  builder.get_branch(), 'a-id', 'rev-6',
 
338
                                  verbose=True, full=False)
336
339
 
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())
 
340
        self.assertBranchAnnotate('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
                                  builder.get_branch(), 'a-id', 'rev-6',
 
347
                                  verbose=True, full=True)
347
348
 
348
349
    def test_annotate_uses_branch_context(self):
349
350
        """Dotted revnos should use the Branch context.
353
354
        """
354
355
        builder = self.create_deeply_merged_trees()
355
356
 
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())
 
357
        self.assertBranchAnnotate('1     joe@foo | first\n'
 
358
                                  '1.1.1 barry@f | third\n'
 
359
                                  '1.2.1 jerry@f | fourth\n'
 
360
                                  '1.3.1 george@ | fifth\n'
 
361
                                  '              | sixth\n',
 
362
                                  builder.get_branch(), 'a-id', 'rev-1_3_1',
 
363
                                  verbose=False, full=False)
365
364
 
366
365
    def test_annotate_show_ids(self):
367
366
        builder = self.create_deeply_merged_trees()
368
367
 
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
368
        # 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())
 
369
        self.assertBranchAnnotate('    rev-1 | first\n'
 
370
                                  '    rev-2 | second\n'
 
371
                                  'rev-1_1_1 | third\n'
 
372
                                  'rev-1_2_1 | fourth\n'
 
373
                                  'rev-1_3_1 | fifth\n'
 
374
                                  '          | sixth\n',
 
375
                                  builder.get_branch(), 'a-id', 'rev-6',
 
376
                                  show_ids=True, full=False)
 
377
 
 
378
        self.assertBranchAnnotate('    rev-1 | first\n'
 
379
                                  '    rev-2 | second\n'
 
380
                                  'rev-1_1_1 | third\n'
 
381
                                  'rev-1_2_1 | fourth\n'
 
382
                                  'rev-1_3_1 | fifth\n'
 
383
                                  'rev-1_3_1 | sixth\n',
 
384
                                  builder.get_branch(), 'a-id', 'rev-6',
 
385
                                  show_ids=True, full=True)
393
386
 
394
387
    def test_annotate_unicode_author(self):
395
388
        tree1 = self.make_branch_and_tree('tree1')
408
401
 
409
402
        tree1.lock_read()
410
403
        self.addCleanup(tree1.unlock)
 
404
 
 
405
        revtree_1 = tree1.branch.repository.revision_tree('rev-1')
 
406
        revtree_2 = tree1.branch.repository.revision_tree('rev-2')
 
407
 
411
408
        # this passes if no exception is raised
412
 
        to_file = StringIO()
413
 
        annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
 
409
        to_file = BytesIO()
 
410
        annotate.annotate_file_tree(revtree_1, 'a-id',
 
411
            to_file=to_file, branch=tree1.branch)
414
412
 
415
 
        sio = StringIO()
416
 
        to_file = codecs.getwriter('ascii')(sio)
417
 
        to_file.encoding = 'ascii' # codecs does not set it
418
 
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
 
413
        sio = BytesIO()
 
414
        to_file = codecs.getwriter('ascii')(sio, 'replace')
 
415
        annotate.annotate_file_tree(revtree_2, 'b-id',
 
416
            to_file=to_file, branch=tree1.branch)
419
417
        self.assertEqualDiff('2   p?rez   | bye\n', sio.getvalue())
420
418
 
421
 
        # test now with to_file.encoding = None
422
 
        to_file = tests.StringIOWrapper()
423
 
        to_file.encoding = None
424
 
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
425
 
        self.assertContainsRe('2   p.rez   | bye\n', to_file.getvalue())
426
 
 
427
 
        # and when it does not exist
428
 
        to_file = StringIO()
429
 
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
430
 
        self.assertContainsRe('2   p.rez   | bye\n', to_file.getvalue())
 
419
        # test now with unicode file-like
 
420
        to_file = StringIOWithEncoding()
 
421
        annotate.annotate_file_tree(revtree_2, 'b-id',
 
422
            to_file=to_file, branch=tree1.branch)
 
423
        self.assertContainsRe(u'2   p\xe9rez   | bye\n', to_file.getvalue())
431
424
 
432
425
    def test_annotate_author_or_committer(self):
433
426
        tree1 = self.make_branch_and_tree('tree1')
447
440
 
448
441
        tree1.lock_read()
449
442
        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())
 
443
 
 
444
        self.assertBranchAnnotate('1   committ | hello\n', tree1.branch,
 
445
            'a-id', 'rev-1')
 
446
 
 
447
        to_file = BytesIO()
 
448
        self.assertBranchAnnotate('2   author@ | bye\n', tree1.branch,
 
449
            'b-id', 'rev-2')
457
450
 
458
451
 
459
452
class TestReannotate(tests.TestCase):