~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_rio.py

  • Committer: Michael Ellerman
  • Date: 2005-12-10 22:11:13 UTC
  • mto: This revision was merged to the branch mainline in revision 1528.
  • Revision ID: michael@ellerman.id.au-20051210221113-99ca561aaab4661e
Simplify handling of DivergedBranches in cmd_pull()

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 by Canonical Ltd
 
1
# Copyright (C) 2005 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
26
25
import os
27
26
import sys
28
27
from tempfile import TemporaryFile
29
28
 
30
29
from bzrlib.tests import TestCaseInTempDir, TestCase
31
 
from bzrlib.rio import (RioWriter, Stanza, read_stanza, read_stanzas, rio_file,
32
 
                        RioReader)
 
30
from bzrlib.rio import RioWriter, Stanza, read_stanza, read_stanzas
33
31
 
34
32
 
35
33
class TestRio(TestCase):
66
64
                ['name: fred\n',
67
65
                 'number: 42\n'])
68
66
 
69
 
    def test_as_dict(self):
70
 
        """Convert rio Stanza to dictionary"""
71
 
        s = Stanza(number='42', name='fred')
72
 
        sd = s.as_dict()
73
 
        self.assertEquals(sd, dict(number='42', name='fred'))
74
 
 
75
67
    def test_to_file(self):
76
68
        """Write rio to file"""
77
69
        tmpf = TemporaryFile()
158
150
""")
159
151
        s2 = read_stanza(s.to_lines())
160
152
        self.assertEquals(s, s2)
161
 
        self.rio_file_stanzas([s])
162
153
 
163
154
    def test_quoted(self):
164
155
        """rio quoted string cases"""
174
165
                   )
175
166
        s2 = read_stanza(s.to_lines())
176
167
        self.assertEquals(s, s2)
177
 
        # apparent bug in read_stanza
178
 
        # s3 = read_stanza(self.stanzas_to_str([s]))
179
 
        # self.assertEquals(s, s3)
180
168
 
181
169
    def test_read_empty(self):
182
170
        """Detect end of rio file"""
234
222
        self.assertEquals(s, Stanza(name="bar", val='129319'))
235
223
        s = read_stanza(tmpf)
236
224
        self.assertEquals(s, None)
237
 
        self.check_rio_file(tmpf)
238
 
 
239
 
    def check_rio_file(self, real_file):
240
 
        real_file.seek(0)
241
 
        read_write = rio_file(RioReader(real_file)).read()
242
 
        real_file.seek(0)
243
 
        self.assertEquals(read_write, real_file.read())
244
 
 
245
 
    @staticmethod
246
 
    def stanzas_to_str(stanzas):
247
 
        return rio_file(stanzas).read()
248
 
 
249
 
    def rio_file_stanzas(self, stanzas):
250
 
        new_stanzas = list(RioReader(rio_file(stanzas)))
251
 
        self.assertEqual(new_stanzas, stanzas)
252
225
 
253
226
    def test_tricky_quoted(self):
254
227
        tmpf = TemporaryFile()
300
273
            ]
301
274
        for expected in expected_vals:
302
275
            stanza = read_stanza(tmpf)
303
 
            self.rio_file_stanzas([stanza])
304
276
            self.assertEquals(len(stanza), 1)
305
277
            self.assertEqualDiff(stanza.get('s'), expected)
306
278
 
308
280
        """Write empty stanza"""
309
281
        l = list(Stanza().to_lines())
310
282
        self.assertEquals(l, [])
311
 
 
312
 
    def test_rio_raises_type_error(self):
313
 
        """TypeError on adding invalid type to Stanza"""
314
 
        s = Stanza()
315
 
        self.assertRaises(TypeError, s.add, 'foo', {})
316
 
 
317
 
    def test_rio_raises_type_error_key(self):
318
 
        """TypeError on adding invalid type to Stanza"""
319
 
        s = Stanza()
320
 
        self.assertRaises(TypeError, s.add, 10, {})
321
 
 
322
 
    def test_rio_unicode(self):
323
 
        # intentionally use cStringIO which doesn't accomodate unencoded unicode objects
324
 
        sio = cStringIO.StringIO()
325
 
        uni_data = u'\N{KATAKANA LETTER O}'
326
 
        s = Stanza(foo=uni_data)
327
 
        self.assertEquals(s.get('foo'), uni_data)
328
 
        raw_lines = s.to_lines()
329
 
        self.assertEquals(raw_lines,
330
 
                ['foo: ' + uni_data.encode('utf-8') + '\n'])
331
 
        new_s = read_stanza(raw_lines)
332
 
        self.assertEquals(new_s.get('foo'), uni_data)
333