~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_rio.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-02-22 07:59:56 UTC
  • mfrom: (1553.5.33 bzr.mbp.locks)
  • Revision ID: pqm@pqm.ubuntu.com-20060222075956-fb281c427e571da6
add LockDir and related fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 by Canonical Ltd
 
1
# Copyright (C) 2005, 2006 by 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
22
22
but this depends on the transport.
23
23
"""
24
24
 
 
25
import cStringIO
25
26
import os
26
27
import sys
27
28
from tempfile import TemporaryFile
64
65
                ['name: fred\n',
65
66
                 'number: 42\n'])
66
67
 
 
68
    def test_as_dict(self):
 
69
        """Convert rio Stanza to dictionary"""
 
70
        s = Stanza(number='42', name='fred')
 
71
        sd = s.as_dict()
 
72
        self.assertEquals(sd, dict(number='42', name='fred'))
 
73
 
67
74
    def test_to_file(self):
68
75
        """Write rio to file"""
69
76
        tmpf = TemporaryFile()
280
287
        """Write empty stanza"""
281
288
        l = list(Stanza().to_lines())
282
289
        self.assertEquals(l, [])
 
290
 
 
291
    def test_rio_raises_type_error(self):
 
292
        """TypeError on adding invalid type to Stanza"""
 
293
        s = Stanza()
 
294
        self.assertRaises(TypeError, s.add, 'foo', {})
 
295
 
 
296
    def test_rio_raises_type_error_key(self):
 
297
        """TypeError on adding invalid type to Stanza"""
 
298
        s = Stanza()
 
299
        self.assertRaises(TypeError, s.add, 10, {})
 
300
 
 
301
    def test_rio_unicode(self):
 
302
        # intentionally use cStringIO which doesn't accomodate unencoded unicode objects
 
303
        sio = cStringIO.StringIO()
 
304
        uni_data = u'\N{KATAKANA LETTER O}'
 
305
        s = Stanza(foo=uni_data)
 
306
        self.assertEquals(s.get('foo'), uni_data)
 
307
        raw_lines = s.to_lines()
 
308
        self.assertEquals(raw_lines,
 
309
                ['foo: ' + uni_data.encode('utf-8') + '\n'])
 
310
        new_s = read_stanza(raw_lines)
 
311
        self.assertEquals(new_s.get('foo'), uni_data)
 
312