~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_xml.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-01-17 17:21:14 UTC
  • mfrom: (2229.2.5 reserved-ids)
  • Revision ID: pqm@pqm.ubuntu.com-20070117172114-dc75493dad46088c
Ensure reserved ids are never stored

Show diffs side-by-side

added added

removed removed

Lines of Context:
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)
262
 
 
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)
270
 
 
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:
275
 
                continue
276
 
            self.assertIsInstance(ie.revision, str)
277
 
 
278
 
 
279
 
class TestEncodeAndEscape(TestCase):
280
 
    """Whitebox testing of the _encode_and_escape function."""
281
 
 
282
 
    def setUp(self):
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)
287
 
 
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)
297
 
 
298
 
    def test_ascii_with_xml(self):
299
 
        self.assertEqual('&'"<>"',
300
 
                         bzrlib.xml5._encode_and_escape('&\'"<>'))
301
 
 
302
 
    def test_utf8_with_xml(self):
303
 
        # u'\xb5\xe5&\u062c'
304
 
        utf8_str = '\xc2\xb5\xc3\xa5&\xd8\xac'
305
 
        self.assertEqual('&#181;&#229;&amp;&#1580;"',
306
 
                         bzrlib.xml5._encode_and_escape(utf8_str))
307
 
 
308
 
    def test_unicode(self):
309
 
        uni_str = u'\xb5\xe5&\u062c'
310
 
        self.assertEqual('&#181;&#229;&amp;&#1580;"',
311
 
                         bzrlib.xml5._encode_and_escape(uni_str))