/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-06-10 01:35:53 UTC
  • mto: (6670.4.8 move-bzr)
  • mto: This revision was merged to the branch mainline in revision 6681.
  • Revision ID: jelmer@jelmer.uk-20170610013553-560y7mn3su4pp763
Fix remaining tests.

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