~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_xml.py

  • Committer: John Arbash Meinel
  • Date: 2007-05-04 18:59:36 UTC
  • mto: This revision was merged to the branch mainline in revision 2643.
  • Revision ID: john@arbash-meinel.com-20070504185936-1mjdoqmtz74xe5mg
A C implementation of _fields_to_entry_0_parents drops the time from 400ms to 330ms for a 21k-entry tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
    errors, 
21
21
    inventory, 
22
22
    xml7,
23
 
    xml_serializer,
24
23
    )
25
24
from bzrlib.tests import TestCase
26
25
from bzrlib.inventory import Inventory, InventoryEntry
81
80
_committed_inv_v5 = """<inventory>
82
81
<file file_id="bar-20050901064931-73b4b1138abc9cd2" 
83
82
      name="bar" parent_id="TREE_ROOT" 
84
 
      revision="mbp@foo-123123"
85
 
      text_sha1="A" text_size="1"/>
 
83
      revision="mbp@foo-123123"/>
86
84
<directory name="subdir"
87
85
           file_id="foo-20050801201819-4139aa4a272f4250"
88
86
           parent_id="TREE_ROOT" 
89
87
           revision="mbp@foo-00"/>
90
88
<file executable="yes" file_id="bar-20050824000535-6bc48cfad47ed134" 
91
89
      name="bar" parent_id="foo-20050801201819-4139aa4a272f4250" 
92
 
      revision="mbp@foo-00"
93
 
      text_sha1="B" text_size="0"/>
 
90
      revision="mbp@foo-00"/>
94
91
</inventory>
95
92
"""
96
93
 
123
120
 
124
121
# DO NOT REFLOW THIS. Its the exact inventory we want.
125
122
_expected_inv_v5 = """<inventory format="5">
126
 
<file file_id="bar-20050901064931-73b4b1138abc9cd2" name="bar" revision="mbp@foo-123123" text_sha1="A" text_size="1" />
 
123
<file file_id="bar-20050901064931-73b4b1138abc9cd2" name="bar" revision="mbp@foo-123123" />
127
124
<directory file_id="foo-20050801201819-4139aa4a272f4250" name="subdir" revision="mbp@foo-00" />
128
 
<file executable="yes" file_id="bar-20050824000535-6bc48cfad47ed134" name="bar" parent_id="foo-20050801201819-4139aa4a272f4250" revision="mbp@foo-00" text_sha1="B" text_size="0" />
 
125
<file executable="yes" file_id="bar-20050824000535-6bc48cfad47ed134" name="bar" parent_id="foo-20050801201819-4139aa4a272f4250" revision="mbp@foo-00" />
129
126
</inventory>
130
127
"""
131
128
 
132
129
 
133
130
_expected_inv_v5_root = """<inventory file_id="f&lt;" format="5" revision_id="mother!">
134
 
<file file_id="bar-20050901064931-73b4b1138abc9cd2" name="bar" parent_id="f&lt;" revision="mbp@foo-123123" text_sha1="A" text_size="1" />
 
131
<file file_id="bar-20050901064931-73b4b1138abc9cd2" name="bar" parent_id="f&lt;" revision="mbp@foo-123123" />
135
132
<directory file_id="foo-20050801201819-4139aa4a272f4250" name="subdir" parent_id="f&lt;" revision="mbp@foo-00" />
136
 
<file executable="yes" file_id="bar-20050824000535-6bc48cfad47ed134" name="bar" parent_id="foo-20050801201819-4139aa4a272f4250" revision="mbp@foo-00" text_sha1="B" text_size="0" />
137
 
<symlink file_id="link-1" name="link" parent_id="foo-20050801201819-4139aa4a272f4250" revision="mbp@foo-00" symlink_target="a" />
 
133
<file executable="yes" file_id="bar-20050824000535-6bc48cfad47ed134" name="bar" parent_id="foo-20050801201819-4139aa4a272f4250" revision="mbp@foo-00" />
138
134
</inventory>
139
135
"""
140
136
 
141
137
_expected_inv_v7 = """<inventory format="7" revision_id="rev_outer">
142
138
<directory file_id="tree-root-321" name="" revision="rev_outer" />
143
139
<directory file_id="dir-id" name="dir" parent_id="tree-root-321" revision="rev_outer" />
144
 
<file file_id="file-id" name="file" parent_id="tree-root-321" revision="rev_outer" text_sha1="A" text_size="1" />
145
 
<symlink file_id="link-id" name="link" parent_id="tree-root-321" revision="rev_outer" symlink_target="a" />
 
140
<file file_id="file-id" name="file" parent_id="tree-root-321" revision="rev_outer" />
 
141
<symlink file_id="link-id" name="link" parent_id="tree-root-321" revision="rev_outer" />
146
142
<tree-reference file_id="nested-id" name="nested" parent_id="tree-root-321" revision="rev_outer" reference_revision="rev_inner" />
147
143
</inventory>
148
144
"""
175
171
</inventory>
176
172
"""
177
173
 
178
 
# Before revision_id was always stored as an attribute
179
 
_inventory_v5a = """<inventory format="5">
180
 
</inventory>
181
 
"""
182
 
 
183
 
# Before revision_id was always stored as an attribute
184
 
_inventory_v5b = """<inventory format="5" revision_id="a-rev-id">
185
 
</inventory>
186
 
"""
187
 
 
188
174
 
189
175
class TestSerializer(TestCase):
190
176
    """Test XML serialization"""
191
 
 
192
177
    def test_canned_inventory(self):
193
178
        """Test unpacked a canned inventory v4 file."""
194
179
        inp = StringIO(_working_inventory_v4)
257
242
        eq(ie.name, 'bar')
258
243
        eq(inv[ie.parent_id].kind, 'directory')
259
244
 
260
 
    def test_unpack_inventory_5a(self):
261
 
        inv = bzrlib.xml5.serializer_v5.read_inventory_from_string(
262
 
                _inventory_v5a, revision_id='test-rev-id')
263
 
        self.assertEqual('test-rev-id', inv.root.revision)
264
 
 
265
 
    def test_unpack_inventory_5b(self):
266
 
        inv = bzrlib.xml5.serializer_v5.read_inventory_from_string(
267
 
                _inventory_v5b, revision_id='test-rev-id')
268
 
        self.assertEqual('a-rev-id', inv.root.revision)
269
 
 
270
245
    def test_repack_inventory_5(self):
271
246
        inp = StringIO(_committed_inv_v5)
272
247
        inv = bzrlib.xml5.serializer_v5.read_inventory(inp)
282
257
        outp = StringIO()
283
258
        bzrlib.xml5.serializer_v5.write_inventory(inv, outp)
284
259
        self.assertEqualDiff(xml_string, outp.getvalue())
285
 
        lines = bzrlib.xml5.serializer_v5.write_inventory_to_lines(inv)
286
 
        outp.seek(0)
287
 
        self.assertEqual(outp.readlines(), lines)
288
260
        inv2 = bzrlib.xml5.serializer_v5.read_inventory(StringIO(outp.getvalue()))
289
261
        self.assertEqual(inv, inv2)
290
262
 
341
313
        inv['tree-root-321'].revision = 'rev_outer'
342
314
        inv['dir-id'].revision = 'rev_outer'
343
315
        inv['file-id'].revision = 'rev_outer'
344
 
        inv['file-id'].text_sha1 = 'A'
345
 
        inv['file-id'].text_size = 1
346
316
        inv['link-id'].revision = 'rev_outer'
347
 
        inv['link-id'].symlink_target = 'a'
348
317
        txt = xml7.serializer_v7.write_inventory_to_string(inv)
349
 
        lines = xml7.serializer_v7.write_inventory_to_lines(inv)
350
 
        self.assertEqual(bzrlib.osutils.split_lines(txt), lines)
351
318
        self.assertEqualDiff(_expected_inv_v7, txt)
352
319
        inv2 = xml7.serializer_v7.read_inventory_from_string(txt)
353
320
        self.assertEqual(5, len(inv2))
367
334
        s_v5 = bzrlib.xml5.serializer_v5
368
335
        s_v6 = bzrlib.xml6.serializer_v6
369
336
        s_v7 = xml7.serializer_v7
370
 
        inv = Inventory('tree-root-321', revision_id='rev-outer')
371
 
        inv.root.revision = 'root-rev'
 
337
        inv = Inventory('tree-root-321')
372
338
        inv.add(inventory.TreeReference('nested-id', 'nested', 'tree-root-321',
373
339
                                        'rev-outer', 'rev-inner'))
374
 
        self.assertRaises(errors.UnsupportedInventoryKind,
 
340
        self.assertRaises(errors.UnsupportedInventoryKind, 
375
341
                          s_v5.write_inventory_to_string, inv)
376
 
        self.assertRaises(errors.UnsupportedInventoryKind,
 
342
        self.assertRaises(errors.UnsupportedInventoryKind, 
377
343
                          s_v6.write_inventory_to_string, inv)
378
344
        txt = s_v7.write_inventory_to_string(inv)
379
 
        lines = s_v7.write_inventory_to_lines(inv)
380
 
        self.assertEqual(bzrlib.osutils.split_lines(txt), lines)
381
345
        inv2 = s_v7.read_inventory_from_string(txt)
382
346
        self.assertEqual('tree-root-321', inv2['nested-id'].parent_id)
383
347
        self.assertEqual('rev-outer', inv2['nested-id'].revision)
409
373
        fid_bar1 = u'b\xe5r-01'.encode('utf8')
410
374
        fid_sub = u's\xb5bdir-01'.encode('utf8')
411
375
        fid_bar2 = u'b\xe5r-02'.encode('utf8')
412
 
        expected = [(u'', fid_root, None, rev_id_2),
 
376
        expected = [(u'', fid_root, None, None),
413
377
                    (u'b\xe5r', fid_bar1, fid_root, rev_id_1),
414
378
                    (u's\xb5bdir', fid_sub, fid_root, rev_id_1),
415
379
                    (u's\xb5bdir/b\xe5r', fid_bar2, fid_sub, rev_id_2),
433
397
 
434
398
        self.assertEqual(len(expected), len(actual))
435
399
 
436
 
    def test_registry(self):
437
 
        self.assertIs(serializer_v4,
438
 
                      xml_serializer.format_registry.get('4'))
439
 
        self.assertIs(bzrlib.xml5.serializer_v5,
440
 
                      xml_serializer.format_registry.get('5'))
441
 
        self.assertIs(bzrlib.xml6.serializer_v6,
442
 
                      xml_serializer.format_registry.get('6'))
443
 
        self.assertIs(bzrlib.xml7.serializer_v7,
444
 
                      xml_serializer.format_registry.get('7'))
445
 
 
446
400
 
447
401
class TestEncodeAndEscape(TestCase):
448
402
    """Whitebox testing of the _encode_and_escape function."""