~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_rio.py

  • Committer: John Arbash Meinel
  • Date: 2006-09-23 06:39:46 UTC
  • mfrom: (2034 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2035.
  • Revision ID: john@arbash-meinel.com-20060923063946-e596c8a8eef928b4
[merge] bzr.dev 2034

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import sys
28
28
from tempfile import TemporaryFile
29
29
 
 
30
from bzrlib import (
 
31
    rio,
 
32
    )
30
33
from bzrlib.tests import TestCaseInTempDir, TestCase
31
34
from bzrlib.rio import (RioWriter, Stanza, read_stanza, read_stanzas, rio_file,
32
35
                        RioReader)
320
323
        self.assertRaises(TypeError, s.add, 10, {})
321
324
 
322
325
    def test_rio_unicode(self):
323
 
        # intentionally use cStringIO which doesn't accomodate unencoded unicode objects
324
 
        sio = cStringIO.StringIO()
325
326
        uni_data = u'\N{KATAKANA LETTER O}'
326
327
        s = Stanza(foo=uni_data)
327
328
        self.assertEquals(s.get('foo'), uni_data)
331
332
        new_s = read_stanza(raw_lines)
332
333
        self.assertEquals(new_s.get('foo'), uni_data)
333
334
 
 
335
    def test_rio_to_unicode(self):
 
336
        uni_data = u'\N{KATAKANA LETTER O}'
 
337
        s = Stanza(foo=uni_data)
 
338
        unicode_str = s.to_unicode()
 
339
        self.assertEqual(u'foo: %s\n' % (uni_data,), unicode_str)
 
340
        new_s = rio.read_stanza_unicode(unicode_str.splitlines(True))
 
341
        self.assertEqual(uni_data, new_s.get('foo'))
 
342
 
 
343
    def test_nested_rio_unicode(self):
 
344
        uni_data = u'\N{KATAKANA LETTER O}'
 
345
        s = Stanza(foo=uni_data)
 
346
        parent_stanza = Stanza(child=s.to_unicode())
 
347
        raw_lines = parent_stanza.to_lines()
 
348
        self.assertEqual(['child: foo: ' + uni_data.encode('utf-8') + '\n',
 
349
                          '\t\n',
 
350
                         ], raw_lines)
 
351
        new_parent = read_stanza(raw_lines)
 
352
        child_text = new_parent.get('child')
 
353
        self.assertEqual(u'foo: %s\n' % uni_data, child_text)
 
354
        new_child = rio.read_stanza_unicode(child_text.splitlines(True))
 
355
        self.assertEqual(uni_data, new_child.get('foo'))