/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_xml.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-22 00:56:52 UTC
  • mfrom: (6621.2.26 py3_pokes)
  • Revision ID: jelmer@jelmer.uk-20170522005652-yjahcr9hwmjkno7n
Merge Python3 porting work ('py3 pokes')

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from cStringIO import StringIO
18
17
 
19
 
from breezy import (
 
18
from .. import (
20
19
    errors,
21
20
    fifo_cache,
22
21
    inventory,
24
23
    xml7,
25
24
    xml8,
26
25
    )
27
 
from breezy.tests import TestCase
28
 
from breezy.inventory import Inventory
 
26
from ..sixish import (
 
27
    BytesIO,
 
28
    )
 
29
from ..inventory import Inventory
 
30
from . import TestCase
29
31
import breezy.xml5
30
32
 
31
33
_revision_v5 = """<revision committer="Martin Pool &lt;mbp@sourcefrog.net&gt;"
196
198
 
197
199
    def test_unpack_revision_5(self):
198
200
        """Test unpacking a canned revision v5"""
199
 
        inp = StringIO(_revision_v5)
 
201
        inp = BytesIO(_revision_v5)
200
202
        rev = breezy.xml5.serializer_v5.read_revision(inp)
201
203
        eq = self.assertEqual
202
204
        eq(rev.committer,
207
209
           "mbp@sourcefrog.net-20050905063503-43948f59fa127d92")
208
210
 
209
211
    def test_unpack_revision_5_utc(self):
210
 
        inp = StringIO(_revision_v5_utc)
 
212
        inp = BytesIO(_revision_v5_utc)
211
213
        rev = breezy.xml5.serializer_v5.read_revision(inp)
212
214
        eq = self.assertEqual
213
215
        eq(rev.committer,
219
221
 
220
222
    def test_unpack_inventory_5(self):
221
223
        """Unpack canned new-style inventory"""
222
 
        inp = StringIO(_committed_inv_v5)
 
224
        inp = BytesIO(_committed_inv_v5)
223
225
        inv = breezy.xml5.serializer_v5.read_inventory(inp)
224
226
        eq = self.assertEqual
225
227
        eq(len(inv), 4)
231
233
 
232
234
    def test_unpack_basis_inventory_5(self):
233
235
        """Unpack canned new-style inventory"""
234
 
        inp = StringIO(_basis_inv_v5)
 
236
        inp = BytesIO(_basis_inv_v5)
235
237
        inv = breezy.xml5.serializer_v5.read_inventory(inp)
236
238
        eq = self.assertEqual
237
239
        eq(len(inv), 4)
285
287
        self.assertEqual('a-rev-id', inv.root.revision)
286
288
 
287
289
    def test_repack_inventory_5(self):
288
 
        inp = StringIO(_committed_inv_v5)
 
290
        inp = BytesIO(_committed_inv_v5)
289
291
        inv = breezy.xml5.serializer_v5.read_inventory(inp)
290
 
        outp = StringIO()
 
292
        outp = BytesIO()
291
293
        breezy.xml5.serializer_v5.write_inventory(inv, outp)
292
294
        self.assertEqualDiff(_expected_inv_v5, outp.getvalue())
293
 
        inv2 = breezy.xml5.serializer_v5.read_inventory(StringIO(outp.getvalue()))
 
295
        inv2 = breezy.xml5.serializer_v5.read_inventory(BytesIO(outp.getvalue()))
294
296
        self.assertEqual(inv, inv2)
295
297
 
296
298
    def assertRoundTrips(self, xml_string):
297
 
        inp = StringIO(xml_string)
 
299
        inp = BytesIO(xml_string)
298
300
        inv = breezy.xml5.serializer_v5.read_inventory(inp)
299
 
        outp = StringIO()
 
301
        outp = BytesIO()
300
302
        breezy.xml5.serializer_v5.write_inventory(inv, outp)
301
303
        self.assertEqualDiff(xml_string, outp.getvalue())
302
304
        lines = breezy.xml5.serializer_v5.write_inventory_to_lines(inv)
303
305
        outp.seek(0)
304
306
        self.assertEqual(outp.readlines(), lines)
305
 
        inv2 = breezy.xml5.serializer_v5.read_inventory(StringIO(outp.getvalue()))
 
307
        inv2 = breezy.xml5.serializer_v5.read_inventory(BytesIO(outp.getvalue()))
306
308
        self.assertEqual(inv, inv2)
307
309
 
308
310
    def tests_serialize_inventory_v5_with_root(self):
310
312
 
311
313
    def check_repack_revision(self, txt):
312
314
        """Check that repacking a revision yields the same information"""
313
 
        inp = StringIO(txt)
 
315
        inp = BytesIO(txt)
314
316
        rev = breezy.xml5.serializer_v5.read_revision(inp)
315
 
        outp = StringIO()
 
317
        outp = BytesIO()
316
318
        breezy.xml5.serializer_v5.write_revision(rev, outp)
317
319
        outfile_contents = outp.getvalue()
318
 
        rev2 = breezy.xml5.serializer_v5.read_revision(StringIO(outfile_contents))
 
320
        rev2 = breezy.xml5.serializer_v5.read_revision(BytesIO(outfile_contents))
319
321
        self.assertEqual(rev, rev2)
320
322
 
321
323
    def test_repack_revision_5(self):
329
331
        """Pack revision to XML v5"""
330
332
        # fixed 20051025, revisions should have final newline
331
333
        rev = breezy.xml5.serializer_v5.read_revision_from_string(_revision_v5)
332
 
        outp = StringIO()
 
334
        outp = BytesIO()
333
335
        breezy.xml5.serializer_v5.write_revision(rev, outp)
334
336
        outfile_contents = outp.getvalue()
335
337
        self.assertEqual(outfile_contents[-1], '\n')
340
342
        """Create an empty property value check that it serializes correctly"""
341
343
        s_v5 = breezy.xml5.serializer_v5
342
344
        rev = s_v5.read_revision_from_string(_revision_v5)
343
 
        outp = StringIO()
 
345
        outp = BytesIO()
344
346
        props = {'empty':'', 'one':'one'}
345
347
        rev.properties = props
346
348
        txt = s_v5.write_revision_to_string(rev)