/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: Jan Balster
  • Date: 2006-08-15 12:39:42 UTC
  • mfrom: (1923 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1928.
  • Revision ID: jan@merlinux.de-20060815123942-22c388c6e9a8ac91
merge bzr.dev 1923

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Tests for the urlutils wrapper."""
18
18
 
19
19
import os
 
20
import re
20
21
import sys
21
22
 
 
23
from bzrlib import osutils, urlutils
22
24
import bzrlib
23
25
from bzrlib.errors import InvalidURL, InvalidURLJoin
24
 
import bzrlib.urlutils as urlutils
25
26
from bzrlib.tests import TestCaseInTempDir, TestCase, TestSkipped
26
27
 
27
28
 
256
257
 
257
258
    def test_win32_local_path_to_url(self):
258
259
        to_url = urlutils._win32_local_path_to_url
259
 
        self.assertEqual('file:///c:/path/to/foo',
 
260
        self.assertEqual('file:///C:/path/to/foo',
260
261
            to_url('C:/path/to/foo'))
261
262
        # BOGUS: on win32, ntpath.abspath will strip trailing
262
263
        #       whitespace, so this will always fail
264
265
        #       and thus will succeed
265
266
        # self.assertEqual('file:///C:/path/to/foo%20',
266
267
        #     to_url('C:/path/to/foo '))
267
 
        self.assertEqual('file:///c:/path/to/f%20oo',
 
268
        self.assertEqual('file:///C:/path/to/f%20oo',
268
269
            to_url('C:/path/to/f oo'))
269
270
 
270
271
        try:
272
273
        except UnicodeError:
273
274
            raise TestSkipped("local encoding cannot handle unicode")
274
275
 
275
 
        self.assertEqual('file:///d:/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
 
276
        self.assertEqual('file:///D:/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
276
277
 
277
278
    def test_win32_local_path_from_url(self):
278
279
        from_url = urlutils._win32_local_path_from_url
279
 
        self.assertEqual('c:/path/to/foo',
 
280
        self.assertEqual('C:/path/to/foo',
280
281
            from_url('file:///C|/path/to/foo'))
281
 
        self.assertEqual(u'd:/path/to/r\xe4ksm\xf6rg\xe5s',
 
282
        self.assertEqual(u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
282
283
            from_url('file:///d|/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s'))
283
 
        self.assertEqual(u'd:/path/to/r\xe4ksm\xf6rg\xe5s',
 
284
        self.assertEqual(u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
284
285
            from_url('file:///d:/path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))
285
286
 
286
287
        self.assertRaises(InvalidURL, from_url, '/path/to/foo')
380
381
 
381
382
        test('http://foo', 'http://foo')
382
383
        if sys.platform == 'win32':
383
 
            test('c:/foo/path', 'file:///C|/foo/path')
384
 
            test('c:/foo/path', 'file:///C:/foo/path')
 
384
            test('C:/foo/path', 'file:///C|/foo/path')
 
385
            test('C:/foo/path', 'file:///C:/foo/path')
385
386
        else:
386
387
            test('/foo/path', 'file:///foo/path')
387
388
 
464
465
        test('http://host/', 'http://host', 'http://host/')
465
466
        #test('.', 'http://host/', 'http://host')
466
467
        test('http://host', 'http://host/', 'http://host')
 
468
 
 
469
 
 
470
class TestCwdToURL(TestCaseInTempDir):
 
471
    """Test that local_path_to_url works base on the cwd"""
 
472
 
 
473
    def test_dot(self):
 
474
        # This test will fail if getcwd is not ascii
 
475
        os.mkdir('mytest')
 
476
        os.chdir('mytest')
 
477
 
 
478
        url = urlutils.local_path_to_url('.')
 
479
        self.assertEndsWith(url, '/mytest')
 
480
 
 
481
    def test_non_ascii(self):
 
482
        try:
 
483
            os.mkdir(u'dod\xe9')
 
484
        except UnicodeError:
 
485
            raise TestSkipped('cannot create unicode directory')
 
486
 
 
487
        os.chdir(u'dod\xe9')
 
488
 
 
489
        # On Mac OSX this directory is actually: 
 
490
        #   u'/dode\u0301' => '/dode\xcc\x81
 
491
        # but we should normalize it back to 
 
492
        #   u'/dod\xe9' => '/dod\xc3\xa9'
 
493
        url = urlutils.local_path_to_url('.')
 
494
        self.assertEndsWith(url, '/dod%C3%A9')