~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_rio.py

  • Committer: Martin Pool
  • Date: 2006-02-22 04:29:54 UTC
  • mfrom: (1566 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1569.
  • Revision ID: mbp@sourcefrog.net-20060222042954-60333f08dd56a646
[merge] from bzr.dev before integration
Fix undefined ordering in sign_my_revisions breaking tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
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):
158
156
""")
159
157
        s2 = read_stanza(s.to_lines())
160
158
        self.assertEquals(s, s2)
161
 
        self.rio_file_stanzas([s])
162
159
 
163
160
    def test_quoted(self):
164
161
        """rio quoted string cases"""
174
171
                   )
175
172
        s2 = read_stanza(s.to_lines())
176
173
        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
174
 
181
175
    def test_read_empty(self):
182
176
        """Detect end of rio file"""
234
228
        self.assertEquals(s, Stanza(name="bar", val='129319'))
235
229
        s = read_stanza(tmpf)
236
230
        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
231
 
253
232
    def test_tricky_quoted(self):
254
233
        tmpf = TemporaryFile()
300
279
            ]
301
280
        for expected in expected_vals:
302
281
            stanza = read_stanza(tmpf)
303
 
            self.rio_file_stanzas([stanza])
304
282
            self.assertEquals(len(stanza), 1)
305
283
            self.assertEqualDiff(stanza.get('s'), expected)
306
284
 
318
296
        """TypeError on adding invalid type to Stanza"""
319
297
        s = Stanza()
320
298
        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