~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-02-09 23:15:53 UTC
  • mto: This revision was merged to the branch mainline in revision 2294.
  • Revision ID: john@arbash-meinel.com-20070209231553-9ywoxs2t3dsx667s
Make sure xml5 can handle unicode or utf8 strings

Show diffs side-by-side

added added

removed removed

Lines of Context:
274
274
            if ie.revision is None:
275
275
                continue
276
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))