/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 bzrlib/tests/test_annotate.py

  • Committer: Adeodato Simó
  • Date: 2007-07-06 17:21:57 UTC
  • mto: (2593.2.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 2594.
  • Revision ID: dato@net.com.org.es-20070706172157-11w04axiv4mtrabm
Improve annotate to prevent unicode exceptions in certain situations.

The fixed bugs are:

  * when an annotation has the author part as unicode(), and line
    contents are 8-bit data, an UnicodeDecodeError is raised when
    formatting them together with '%s %s'

  * when the author part of an annotation contains characters not
    representable in the encoding of the user that runs annotate,
    an UnicodeEncodeError is raised

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Whitebox tests for annotate functionality."""
18
18
 
 
19
import codecs
19
20
from cStringIO import StringIO
20
21
 
21
22
from bzrlib import (
301
302
                             'rev-1_1_1_1_1_1_1 | sixth\n',
302
303
                             sio.getvalue())
303
304
 
 
305
    def test_annotate_unicode_author(self):
 
306
        tree1 = self.make_branch_and_tree('tree1')
 
307
 
 
308
        self.build_tree_contents([('tree1/a', 'adi\xc3\xb3s')])
 
309
        tree1.add(['a'], ['a-id'])
 
310
        tree1.commit('a', rev_id='rev-1',
 
311
                     committer=u'Pepe P\xe9rez <pperez@ejemplo.com>',
 
312
                     timestamp=1166046000.00, timezone=0)
 
313
 
 
314
        self.build_tree_contents([('tree1/b', 'bye')])
 
315
        tree1.add(['b'], ['b-id'])
 
316
        tree1.commit('b', rev_id='rev-2',
 
317
                     committer=u'p\xe9rez',
 
318
                     timestamp=1166046000.00, timezone=0)
 
319
 
 
320
        # the test passes if the annotate_file() calls below do not raise an
 
321
        # exception
 
322
 
 
323
        to_file = codecs.EncodedFile(StringIO(), 'utf-8')
 
324
        annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
 
325
 
 
326
        to_file = codecs.getwriter('ascii')(StringIO())
 
327
        to_file.encoding = 'ascii' # codecs does not set it
 
328
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
 
329
 
304
330
 
305
331
class TestReannotate(tests.TestCase):
306
332