/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_urlutils.py

  • Committer: Martin Pool
  • Date: 2006-06-05 15:09:51 UTC
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: mbp@sourcefrog.net-20060605150951-b2de88c27e46a8d2
urlutils.unescape_for_display should return Unicode

Show diffs side-by-side

added added

removed removed

Lines of Context:
325
325
        # Test that URLs are converted to nice unicode strings for display
326
326
        def test(expected, url, encoding='utf-8'):
327
327
            disp_url = urlutils.unescape_for_display(url, encoding=encoding)
 
328
            self.assertIsInstance(disp_url, unicode)
328
329
            self.assertEqual(expected, disp_url)
329
330
        test('http://foo', 'http://foo')
330
331
        if sys.platform == 'win32':
333
334
            test('/foo/path', 'file:///foo/path')
334
335
 
335
336
        test('http://foo/%2Fbaz', 'http://foo/%2Fbaz')
336
 
        test(u'http://host/r\xe4ksm\xf6rg\xe5s'.encode('utf-8'), 
337
 
                'http://host/r%C3%A4ksm%C3%B6rg%C3%A5s')
 
337
        test(u'http://host/r\xe4ksm\xf6rg\xe5s',
 
338
             'http://host/r%C3%A4ksm%C3%B6rg%C3%A5s')
338
339
 
339
340
        # Make sure special escaped characters stay escaped
340
341
        test(u'http://host/%3B%2F%3F%3A%40%26%3D%2B%24%2C%23',
341
 
            'http://host/%3B%2F%3F%3A%40%26%3D%2B%24%2C%23')
 
342
             'http://host/%3B%2F%3F%3A%40%26%3D%2B%24%2C%23')
342
343
 
343
344
        # Can we handle sections that don't have utf-8 encoding?
344
 
        test('http://host/%EE%EE%EE/r\xc3\xa4ksm\xc3\xb6rg\xc3\xa5s',
345
 
            'http://host/%EE%EE%EE/r%C3%A4ksm%C3%B6rg%C3%A5s')
 
345
        test(u'http://host/%EE%EE%EE/r\xe4ksm\xf6rg\xe5s',
 
346
             'http://host/%EE%EE%EE/r%C3%A4ksm%C3%B6rg%C3%A5s')
346
347
 
347
348
        # Test encoding into output that can handle some characters
348
 
        test('http://host/%EE%EE%EE/r\xe4ksm\xf6rg\xe5s',
349
 
            'http://host/%EE%EE%EE/r%C3%A4ksm%C3%B6rg%C3%A5s', 
350
 
            encoding='iso-8859-1')
351
 
        # Test utf-8 encoding, when some characters aren't handled
352
 
        test('http://host/\xd8\xac\xd9\x88\xd8\xac\xd9\x88', 
353
 
            'http://host/%d8%ac%d9%88%d8%ac%d9%88', 
354
 
            encoding='utf-8')
355
 
        test('http://host/%d8%ac%d9%88%d8%ac%d9%88', 
356
 
            'http://host/%d8%ac%d9%88%d8%ac%d9%88', 
357
 
            encoding='iso-8859-1')
 
349
        test(u'http://host/%EE%EE%EE/r\xe4ksm\xf6rg\xe5s',
 
350
             'http://host/%EE%EE%EE/r%C3%A4ksm%C3%B6rg%C3%A5s',
 
351
             encoding='iso-8859-1')
 
352
 
 
353
        # This one can be encoded into utf8
 
354
        test(u'http://host/\u062c\u0648\u062c\u0648',
 
355
             'http://host/%d8%ac%d9%88%d8%ac%d9%88',
 
356
             encoding='utf-8')
 
357
 
 
358
        # This can't be put into 8859-1 and so stays as escapes
 
359
        test(u'http://host/%d8%ac%d9%88%d8%ac%d9%88',
 
360
             'http://host/%d8%ac%d9%88%d8%ac%d9%88',
 
361
             encoding='iso-8859-1')
358
362
 
359
363
    def test_escape(self):
360
364
        self.assertEqual('%25', urlutils.escape('%'))