259
259
txt = s_v5.write_revision_to_string(rev)
260
260
new_rev = s_v5.read_revision_from_string(txt)
261
261
self.assertEqual(props, new_rev.properties)
263
def test_revision_ids_are_utf8(self):
264
"""Parsed revision_ids should all be utf-8 strings, not unicode."""
265
s_v5 = bzrlib.xml5.serializer_v5
266
rev = s_v5.read_revision_from_string(_revision_v5)
267
self.assertIsInstance(rev.revision_id, str)
268
for parent_id in rev.parent_ids:
269
self.assertIsInstance(parent_id, str)
271
# ie.revision should either be None or a utf-8 revision id
272
inv = s_v5.read_inventory_from_string(_committed_inv_v5)
273
for path, ie in inv.iter_entries():
274
if ie.revision is None:
276
self.assertIsInstance(ie.revision, str)
279
class TestEncodeAndEscape(TestCase):
280
"""Whitebox testing of the _encode_and_escape function."""
283
# Keep the cache clear before and after the test
284
bzrlib.xml5._ensure_utf8_re()
285
bzrlib.xml5._clear_cache()
286
self.addCleanup(bzrlib.xml5._clear_cache)
288
def test_simple_ascii(self):
289
# _encode_and_escape always appends a final ", because these parameters
290
# are being used in xml attributes, and by returning it now, we have to
291
# do fewer string operations later.
292
val = bzrlib.xml5._encode_and_escape('foo bar')
293
self.assertEqual('foo bar"', val)
294
# The second time should be cached
295
val2 = bzrlib.xml5._encode_and_escape('foo bar')
296
self.assertIs(val2, val)
298
def test_ascii_with_xml(self):
299
self.assertEqual('&'"<>"',
300
bzrlib.xml5._encode_and_escape('&\'"<>'))
302
def test_utf8_with_xml(self):
304
utf8_str = '\xc2\xb5\xc3\xa5&\xd8\xac'
305
self.assertEqual('µå&ج"',
306
bzrlib.xml5._encode_and_escape(utf8_str))
308
def test_unicode(self):
309
uni_str = u'\xb5\xe5&\u062c'
310
self.assertEqual('µå&ج"',
311
bzrlib.xml5._encode_and_escape(uni_str))