/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:
17
17
"""Whitebox tests for annotate functionality."""
18
18
 
19
19
import codecs
20
 
from cStringIO import StringIO
21
20
 
22
 
from breezy import (
 
21
from .. import (
23
22
    annotate,
24
23
    symbol_versioning,
25
24
    tests,
26
25
    )
 
26
from ..sixish import (
 
27
    BytesIO,
 
28
    )
 
29
from .ui_testing import StringIOWithEncoding
27
30
 
28
31
 
29
32
def annotation(text):
271
274
    def assertBranchAnnotate(self, expected, branch, file_id, revision_id,
272
275
            verbose=False, full=False, show_ids=False):
273
276
        tree = branch.repository.revision_tree(revision_id)
274
 
        to_file = StringIO()
 
277
        to_file = BytesIO()
275
278
        annotate.annotate_file_tree(tree, file_id, to_file,
276
279
            verbose=verbose, full=full, show_ids=show_ids, branch=branch)
277
280
        self.assertAnnotateEqualDiff(to_file.getvalue(), expected)
403
406
        revtree_2 = tree1.branch.repository.revision_tree('rev-2')
404
407
 
405
408
        # this passes if no exception is raised
406
 
        to_file = StringIO()
 
409
        to_file = BytesIO()
407
410
        annotate.annotate_file_tree(revtree_1, 'a-id',
408
411
            to_file=to_file, branch=tree1.branch)
409
412
 
410
 
        sio = StringIO()
411
 
        to_file = codecs.getwriter('ascii')(sio)
412
 
        to_file.encoding = 'ascii' # codecs does not set it
 
413
        sio = BytesIO()
 
414
        to_file = codecs.getwriter('ascii')(sio, 'replace')
413
415
        annotate.annotate_file_tree(revtree_2, 'b-id',
414
416
            to_file=to_file, branch=tree1.branch)
415
417
        self.assertEqualDiff('2   p?rez   | bye\n', sio.getvalue())
416
418
 
417
 
        # test now with to_file.encoding = None
418
 
        to_file = tests.StringIOWrapper()
419
 
        to_file.encoding = None
420
 
        annotate.annotate_file_tree(revtree_2, 'b-id',
421
 
            to_file=to_file, branch=tree1.branch)
422
 
        self.assertContainsRe('2   p.rez   | bye\n', to_file.getvalue())
423
 
 
424
 
        # and when it does not exist
425
 
        to_file = StringIO()
426
 
        annotate.annotate_file_tree(revtree_2, 'b-id',
427
 
            to_file=to_file, branch=tree1.branch)
428
 
        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())
429
424
 
430
425
    def test_annotate_author_or_committer(self):
431
426
        tree1 = self.make_branch_and_tree('tree1')
449
444
        self.assertBranchAnnotate('1   committ | hello\n', tree1.branch,
450
445
            'a-id', 'rev-1')
451
446
 
452
 
        to_file = StringIO()
 
447
        to_file = BytesIO()
453
448
        self.assertBranchAnnotate('2   author@ | bye\n', tree1.branch,
454
449
            'b-id', 'rev-2')
455
450