414
414
self.assertEqual('tree-root-321', inv2['nested-id'].parent_id)
415
415
self.assertEqual('rev-outer', inv2['nested-id'].revision)
416
416
self.assertEqual('rev-inner', inv2['nested-id'].reference_revision)
417
self.assertRaises(errors.UnsupportedInventoryKind,
418
s_v6.read_inventory_from_string,
419
txt.replace('format="7"', 'format="6"'))
420
self.assertRaises(errors.UnsupportedInventoryKind,
421
s_v5.read_inventory_from_string,
422
txt.replace('format="7"', 'format="5"'))
424
418
def test_roundtrip_inventory_v8(self):
425
419
inv = self.get_sample_inventory()
506
500
"""Whitebox testing of the _encode_and_escape function."""
503
super(TestEncodeAndEscape, self).setUp()
510
504
# Keep the cache clear before and after the test
511
bzrlib.xml8._ensure_utf8_re()
512
bzrlib.xml8._clear_cache()
513
self.addCleanup(bzrlib.xml8._clear_cache)
505
bzrlib.xml_serializer._clear_cache()
506
self.addCleanup(bzrlib.xml_serializer._clear_cache)
515
508
def test_simple_ascii(self):
516
509
# _encode_and_escape always appends a final ", because these parameters
517
510
# are being used in xml attributes, and by returning it now, we have to
518
511
# do fewer string operations later.
519
val = bzrlib.xml8._encode_and_escape('foo bar')
512
val = bzrlib.xml_serializer.encode_and_escape('foo bar')
520
513
self.assertEqual('foo bar"', val)
521
514
# The second time should be cached
522
val2 = bzrlib.xml8._encode_and_escape('foo bar')
515
val2 = bzrlib.xml_serializer.encode_and_escape('foo bar')
523
516
self.assertIs(val2, val)
525
518
def test_ascii_with_xml(self):
526
519
self.assertEqual('&'"<>"',
527
bzrlib.xml8._encode_and_escape('&\'"<>'))
520
bzrlib.xml_serializer.encode_and_escape('&\'"<>'))
529
522
def test_utf8_with_xml(self):
530
523
# u'\xb5\xe5&\u062c'
531
524
utf8_str = '\xc2\xb5\xc3\xa5&\xd8\xac'
532
525
self.assertEqual('µå&ج"',
533
bzrlib.xml8._encode_and_escape(utf8_str))
526
bzrlib.xml_serializer.encode_and_escape(utf8_str))
535
528
def test_unicode(self):
536
529
uni_str = u'\xb5\xe5&\u062c'
537
530
self.assertEqual('µå&ج"',
538
bzrlib.xml8._encode_and_escape(uni_str))
531
bzrlib.xml_serializer.encode_and_escape(uni_str))
541
534
class TestMisc(TestCase):