~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: 2008-09-09 15:09:12 UTC
  • mto: This revision was merged to the branch mainline in revision 3699.
  • Revision ID: john@arbash-meinel.com-20080909150912-wyttm8he1zsls2ck
Use the right timing function on win32

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
from cStringIO import StringIO
18
18
 
19
19
from bzrlib import (
20
 
    errors,
21
 
    inventory,
22
 
    xml6,
 
20
    errors, 
 
21
    inventory, 
23
22
    xml7,
24
23
    xml8,
25
 
    serializer,
 
24
    xml_serializer,
26
25
    )
27
26
from bzrlib.tests import TestCase
28
27
from bzrlib.inventory import Inventory, InventoryEntry
81
80
"""
82
81
 
83
82
_committed_inv_v5 = """<inventory>
84
 
<file file_id="bar-20050901064931-73b4b1138abc9cd2"
85
 
      name="bar" parent_id="TREE_ROOT"
 
83
<file file_id="bar-20050901064931-73b4b1138abc9cd2" 
 
84
      name="bar" parent_id="TREE_ROOT" 
86
85
      revision="mbp@foo-123123"
87
86
      text_sha1="A" text_size="1"/>
88
87
<directory name="subdir"
89
88
           file_id="foo-20050801201819-4139aa4a272f4250"
90
 
           parent_id="TREE_ROOT"
 
89
           parent_id="TREE_ROOT" 
91
90
           revision="mbp@foo-00"/>
92
 
<file executable="yes" file_id="bar-20050824000535-6bc48cfad47ed134"
93
 
      name="bar" parent_id="foo-20050801201819-4139aa4a272f4250"
 
91
<file executable="yes" file_id="bar-20050824000535-6bc48cfad47ed134" 
 
92
      name="bar" parent_id="foo-20050801201819-4139aa4a272f4250" 
94
93
      revision="mbp@foo-00"
95
94
      text_sha1="B" text_size="0"/>
96
95
</inventory>
97
96
"""
98
97
 
99
98
_basis_inv_v5 = """<inventory revision_id="mbp@sourcefrog.net-20050905063503-43948f59fa127d92">
100
 
<file file_id="bar-20050901064931-73b4b1138abc9cd2"
101
 
      name="bar" parent_id="TREE_ROOT"
 
99
<file file_id="bar-20050901064931-73b4b1138abc9cd2" 
 
100
      name="bar" parent_id="TREE_ROOT" 
102
101
      revision="mbp@foo-123123"/>
103
102
<directory name="subdir"
104
103
           file_id="foo-20050801201819-4139aa4a272f4250"
105
 
           parent_id="TREE_ROOT"
 
104
           parent_id="TREE_ROOT" 
106
105
           revision="mbp@foo-00"/>
107
 
<file file_id="bar-20050824000535-6bc48cfad47ed134"
108
 
      name="bar" parent_id="foo-20050801201819-4139aa4a272f4250"
 
106
<file file_id="bar-20050824000535-6bc48cfad47ed134" 
 
107
      name="bar" parent_id="foo-20050801201819-4139aa4a272f4250" 
109
108
      revision="mbp@foo-00"/>
110
109
</inventory>
111
110
"""
140
139
</inventory>
141
140
"""
142
141
 
143
 
_expected_inv_v6 = """<inventory format="6" revision_id="rev_outer">
144
 
<directory file_id="tree-root-321" name="" revision="rev_outer" />
145
 
<directory file_id="dir-id" name="dir" parent_id="tree-root-321" revision="rev_outer" />
146
 
<file file_id="file-id" name="file" parent_id="tree-root-321" revision="rev_outer" text_sha1="A" text_size="1" />
147
 
<symlink file_id="link-id" name="link" parent_id="tree-root-321" revision="rev_outer" symlink_target="a" />
148
 
</inventory>
149
 
"""
150
 
 
151
142
_expected_inv_v7 = """<inventory format="7" revision_id="rev_outer">
152
143
<directory file_id="tree-root-321" name="" revision="rev_outer" />
153
144
<directory file_id="dir-id" name="dir" parent_id="tree-root-321" revision="rev_outer" />
303
294
        self.assertEqualDiff(_expected_inv_v5, outp.getvalue())
304
295
        inv2 = bzrlib.xml5.serializer_v5.read_inventory(StringIO(outp.getvalue()))
305
296
        self.assertEqual(inv, inv2)
306
 
 
 
297
    
307
298
    def assertRoundTrips(self, xml_string):
308
299
        inp = StringIO(xml_string)
309
300
        inv = bzrlib.xml5.serializer_v5.read_inventory(inp)
361
352
    def get_sample_inventory(self):
362
353
        inv = Inventory('tree-root-321', revision_id='rev_outer')
363
354
        inv.add(inventory.InventoryFile('file-id', 'file', 'tree-root-321'))
364
 
        inv.add(inventory.InventoryDirectory('dir-id', 'dir',
 
355
        inv.add(inventory.InventoryDirectory('dir-id', 'dir', 
365
356
                                             'tree-root-321'))
366
357
        inv.add(inventory.InventoryLink('link-id', 'link', 'tree-root-321'))
367
358
        inv['tree-root-321'].revision = 'rev_outer'
386
377
        for path, ie in inv.iter_entries():
387
378
            self.assertEqual(ie, inv2[ie.file_id])
388
379
 
389
 
    def test_roundtrip_inventory_v6(self):
390
 
        inv = self.get_sample_inventory()
391
 
        txt = xml6.serializer_v6.write_inventory_to_string(inv)
392
 
        lines = xml6.serializer_v6.write_inventory_to_lines(inv)
393
 
        self.assertEqual(bzrlib.osutils.split_lines(txt), lines)
394
 
        self.assertEqualDiff(_expected_inv_v6, txt)
395
 
        inv2 = xml6.serializer_v6.read_inventory_from_string(txt)
396
 
        self.assertEqual(4, len(inv2))
397
 
        for path, ie in inv.iter_entries():
398
 
            self.assertEqual(ie, inv2[ie.file_id])
399
 
 
400
380
    def test_wrong_format_v7(self):
401
381
        """Can't accidentally open a file with wrong serializer"""
402
382
        s_v6 = bzrlib.xml6.serializer_v6
403
383
        s_v7 = xml7.serializer_v7
404
 
        self.assertRaises(errors.UnexpectedInventoryFormat,
 
384
        self.assertRaises(errors.UnexpectedInventoryFormat, 
405
385
                          s_v7.read_inventory_from_string, _expected_inv_v5)
406
 
        self.assertRaises(errors.UnexpectedInventoryFormat,
 
386
        self.assertRaises(errors.UnexpectedInventoryFormat, 
407
387
                          s_v6.read_inventory_from_string, _expected_inv_v7)
408
388
 
409
389
    def test_tree_reference(self):
425
405
        self.assertEqual('tree-root-321', inv2['nested-id'].parent_id)
426
406
        self.assertEqual('rev-outer', inv2['nested-id'].revision)
427
407
        self.assertEqual('rev-inner', inv2['nested-id'].reference_revision)
428
 
        self.assertRaises(errors.UnsupportedInventoryKind,
 
408
        self.assertRaises(errors.UnsupportedInventoryKind, 
429
409
                          s_v6.read_inventory_from_string,
430
410
                          txt.replace('format="7"', 'format="6"'))
431
 
        self.assertRaises(errors.UnsupportedInventoryKind,
 
411
        self.assertRaises(errors.UnsupportedInventoryKind, 
432
412
                          s_v5.read_inventory_from_string,
433
413
                          txt.replace('format="7"', 'format="5"'))
434
414
 
512
492
 
513
493
        self.assertEqual(len(expected), len(actual))
514
494
 
 
495
    def test_registry(self):
 
496
        self.assertIs(serializer_v4,
 
497
                      xml_serializer.format_registry.get('4'))
 
498
        self.assertIs(bzrlib.xml5.serializer_v5,
 
499
                      xml_serializer.format_registry.get('5'))
 
500
        self.assertIs(bzrlib.xml6.serializer_v6,
 
501
                      xml_serializer.format_registry.get('6'))
 
502
        self.assertIs(bzrlib.xml7.serializer_v7,
 
503
                      xml_serializer.format_registry.get('7'))
 
504
        self.assertIs(bzrlib.xml8.serializer_v8,
 
505
                      xml_serializer.format_registry.get('8'))
 
506
 
515
507
 
516
508
class TestEncodeAndEscape(TestCase):
517
509
    """Whitebox testing of the _encode_and_escape function."""
518
510
 
519
511
    def setUp(self):
520
 
        TestCase.setUp(self)
521
512
        # Keep the cache clear before and after the test
522
513
        bzrlib.xml8._ensure_utf8_re()
523
514
        bzrlib.xml8._clear_cache()