~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_xml.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-13 00:26:41 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101013002641-9tlh9k89mlj1666m
Keep docs-plain working.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005-2010 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
23
23
    xml6,
24
24
    xml7,
25
25
    xml8,
 
26
    serializer,
26
27
    )
27
28
from bzrlib.tests import TestCase
28
 
from bzrlib.inventory import Inventory
 
29
from bzrlib.inventory import Inventory, InventoryEntry
 
30
from bzrlib.xml4 import serializer_v4
29
31
import bzrlib.xml5
30
32
 
 
33
_working_inventory_v4 = """<inventory file_id="TREE_ROOT">
 
34
<entry file_id="bar-20050901064931-73b4b1138abc9cd2" kind="file" name="bar" parent_id="TREE_ROOT" />
 
35
<entry file_id="foo-20050801201819-4139aa4a272f4250" kind="directory" name="foo" parent_id="TREE_ROOT" />
 
36
<entry file_id="bar-20050824000535-6bc48cfad47ed134" kind="file" name="bar" parent_id="foo-20050801201819-4139aa4a272f4250" />
 
37
</inventory>"""
 
38
 
 
39
 
 
40
_revision_v4 = """<revision committer="Martin Pool &lt;mbp@sourcefrog.net&gt;"
 
41
    inventory_id="mbp@sourcefrog.net-20050905080035-e0439293f8b6b9f9"
 
42
    inventory_sha1="e79c31c1deb64c163cf660fdedd476dd579ffd41"
 
43
    revision_id="mbp@sourcefrog.net-20050905080035-e0439293f8b6b9f9"
 
44
    timestamp="1125907235.212"
 
45
    timezone="36000">
 
46
<message>- start splitting code for xml (de)serialization away from objects
 
47
  preparatory to supporting multiple formats by a single library
 
48
</message>
 
49
<parents>
 
50
<revision_ref revision_id="mbp@sourcefrog.net-20050905063503-43948f59fa127d92" revision_sha1="7bdf4cc8c5bdac739f8cf9b10b78cf4b68f915ff" />
 
51
</parents>
 
52
</revision>
 
53
"""
 
54
 
31
55
_revision_v5 = """<revision committer="Martin Pool &lt;mbp@sourcefrog.net&gt;"
32
56
    inventory_sha1="e79c31c1deb64c163cf660fdedd476dd579ffd41"
33
57
    revision_id="mbp@sourcefrog.net-20050905080035-e0439293f8b6b9f9"
194
218
class TestSerializer(TestCase):
195
219
    """Test XML serialization"""
196
220
 
 
221
    def test_canned_inventory(self):
 
222
        """Test unpacked a canned inventory v4 file."""
 
223
        inp = StringIO(_working_inventory_v4)
 
224
        inv = serializer_v4.read_inventory(inp)
 
225
        self.assertEqual(len(inv), 4)
 
226
        self.assert_('bar-20050901064931-73b4b1138abc9cd2' in inv)
 
227
 
 
228
    def test_unpack_revision(self):
 
229
        """Test unpacking a canned revision v4"""
 
230
        inp = StringIO(_revision_v4)
 
231
        rev = serializer_v4.read_revision(inp)
 
232
        eq = self.assertEqual
 
233
        eq(rev.committer,
 
234
           "Martin Pool <mbp@sourcefrog.net>")
 
235
        eq(rev.inventory_id,
 
236
           "mbp@sourcefrog.net-20050905080035-e0439293f8b6b9f9")
 
237
        eq(len(rev.parent_ids), 1)
 
238
        eq(rev.parent_ids[0],
 
239
           "mbp@sourcefrog.net-20050905063503-43948f59fa127d92")
 
240
 
197
241
    def test_unpack_revision_5(self):
198
242
        """Test unpacking a canned revision v5"""
199
243
        inp = StringIO(_revision_v5)
536
580
        uni_str = u'\xb5\xe5&\u062c'
537
581
        self.assertEqual('&#181;&#229;&amp;&#1580;"',
538
582
                         bzrlib.xml8._encode_and_escape(uni_str))
539
 
 
540
 
 
541
 
class TestMisc(TestCase):
542
 
 
543
 
    def test_unescape_xml(self):
544
 
        """We get some kind of error when malformed entities are passed"""
545
 
        self.assertRaises(KeyError, bzrlib.xml8._unescape_xml, 'foo&bar;')