~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_rio.py

  • Committer: Aaron Bentley
  • Date: 2006-03-09 18:47:40 UTC
  • mto: (2027.1.2 revert-subpath-56549)
  • mto: This revision was merged to the branch mainline in revision 1647.
  • Revision ID: abentley@panoramicfeedback.com-20060309184740-1bbba4a768e7628c
Implemented rio_file to produce a light file object from stanzas

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from tempfile import TemporaryFile
29
29
 
30
30
from bzrlib.tests import TestCaseInTempDir, TestCase
31
 
from bzrlib.rio import RioWriter, Stanza, read_stanza, read_stanzas
 
31
from bzrlib.rio import (RioWriter, Stanza, read_stanza, read_stanzas, rio_file,
 
32
                        RioReader)
32
33
 
33
34
 
34
35
class TestRio(TestCase):
157
158
""")
158
159
        s2 = read_stanza(s.to_lines())
159
160
        self.assertEquals(s, s2)
 
161
        self.rio_file_stanzas([s])
160
162
 
161
163
    def test_quoted(self):
162
164
        """rio quoted string cases"""
172
174
                   )
173
175
        s2 = read_stanza(s.to_lines())
174
176
        self.assertEquals(s, s2)
 
177
        # apparent bug in read_stanza
 
178
        # s3 = read_stanza(self.stanzas_to_str([s]))
 
179
        # self.assertEquals(s, s3)
175
180
 
176
181
    def test_read_empty(self):
177
182
        """Detect end of rio file"""
229
234
        self.assertEquals(s, Stanza(name="bar", val='129319'))
230
235
        s = read_stanza(tmpf)
231
236
        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)
232
252
 
233
253
    def test_tricky_quoted(self):
234
254
        tmpf = TemporaryFile()
280
300
            ]
281
301
        for expected in expected_vals:
282
302
            stanza = read_stanza(tmpf)
 
303
            self.rio_file_stanzas([stanza])
283
304
            self.assertEquals(len(stanza), 1)
284
305
            self.assertEqualDiff(stanza.get('s'), expected)
285
306