~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_urlutils.py

  • Committer: John Arbash Meinel
  • Date: 2008-09-05 02:29:34 UTC
  • mto: (3697.7.4 1.7)
  • mto: This revision was merged to the branch mainline in revision 3748.
  • Revision ID: john@arbash-meinel.com-20080905022934-s8692mbwpkdwi106
Cleanups to the algorithm documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Tests for the urlutils wrapper."""
18
18
 
21
21
import sys
22
22
 
23
23
from bzrlib import osutils, urlutils, win32utils
 
24
import bzrlib
24
25
from bzrlib.errors import InvalidURL, InvalidURLJoin, InvalidRebaseURLs
25
26
from bzrlib.tests import TestCaseInTempDir, TestCase, TestSkipped
26
27
 
27
28
 
28
29
class TestUrlToPath(TestCase):
29
 
 
 
30
    
30
31
    def test_basename(self):
31
32
        # bzrlib.urlutils.basename
32
33
        # Test bzrlib.urlutils.split()
81
82
 
82
83
        # Local paths are assumed to *not* be escaped at all
83
84
        try:
84
 
            u'uni/\xb5'.encode(osutils.get_user_encoding())
 
85
            u'uni/\xb5'.encode(bzrlib.user_encoding)
85
86
        except UnicodeError:
86
 
            # locale cannot handle unicode
 
87
            # locale cannot handle unicode 
87
88
            pass
88
89
        else:
89
90
            norm_file('uni/%C2%B5', u'uni/\xb5')
226
227
        test('file:///bar/foo', 'file:///bar/', 'foo')
227
228
        test('http://host/foo', 'http://host/', 'foo')
228
229
        test('http://host/', 'http://host', '')
229
 
 
 
230
        
230
231
        # Invalid joinings
231
232
        # Cannot go above root
232
233
        # Implicitly at root:
264
265
 
265
266
        # Test joining to a path with a trailing slash
266
267
        test('foo/bar', 'foo/', 'bar')
267
 
 
 
268
        
268
269
        # Invalid joinings
269
270
        # Cannot go above root
270
271
        self.assertRaises(InvalidURLJoin, urlutils.joinpath, '/', '../baz')
315
316
        #     to_url('C:/path/to/foo '))
316
317
        self.assertEqual('file:///C:/path/to/f%20oo',
317
318
            to_url('C:/path/to/f oo'))
318
 
 
 
319
        
319
320
        self.assertEqual('file:///', to_url('/'))
320
321
 
321
322
        try:
497
498
        self.assertEqual('%C3%A5', urlutils.escape(u'\xe5'))
498
499
        self.assertFalse(isinstance(urlutils.escape(u'\xe5'), unicode))
499
500
 
500
 
    def test_escape_tildes(self):
501
 
        self.assertEqual('~foo', urlutils.escape('~foo'))
502
 
 
503
501
    def test_unescape(self):
504
502
        self.assertEqual('%', urlutils.unescape('%25'))
505
503
        self.assertEqual(u'\xe5', urlutils.unescape('%C3%A5'))
516
514
        def test(expected, base, other):
517
515
            result = urlutils.relative_url(base, other)
518
516
            self.assertEqual(expected, result)
519
 
 
 
517
            
520
518
        test('a', 'http://host/', 'http://host/a')
521
519
        test('http://entirely/different', 'sftp://host/branch',
522
520
                    'http://entirely/different')
531
529
                    'sftp://host/home/jelmer/branch/2b')
532
530
        test('../../branch/feature/%2b', 'http://host/home/jelmer/bar/%2b',
533
531
                    'http://host/home/jelmer/branch/feature/%2b')
534
 
        test('../../branch/feature/2b', 'http://host/home/jelmer/bar/2b/',
 
532
        test('../../branch/feature/2b', 'http://host/home/jelmer/bar/2b/', 
535
533
                    'http://host/home/jelmer/branch/feature/2b')
536
534
        # relative_url should preserve a trailing slash
537
535
        test('../../branch/feature/2b/', 'http://host/home/jelmer/bar/2b/',
595
593
 
596
594
        os.chdir(u'dod\xe9')
597
595
 
598
 
        # On Mac OSX this directory is actually:
 
596
        # On Mac OSX this directory is actually: 
599
597
        #   u'/dode\u0301' => '/dode\xcc\x81
600
 
        # but we should normalize it back to
 
598
        # but we should normalize it back to 
601
599
        #   u'/dod\xe9' => '/dod\xc3\xa9'
602
600
        url = urlutils.local_path_to_url('.')
603
601
        self.assertEndsWith(url, '/dod%C3%A9')
657
655
                         'http://baz/qux', 'http://baz/'))
658
656
        self.assertEqual('.', urlutils.rebase_url('foo',
659
657
                         'http://bar/', 'http://bar/foo/'))
660
 
        self.assertEqual('qux/bar', urlutils.rebase_url('../bar',
661
 
                         'http://baz/qux/foo', 'http://baz/'))
662
658
 
663
659
    def test_determine_relative_path(self):
664
660
        self.assertEqual('../../baz/bar',
672
668
                         '/bar', '/bar/baz'))
673
669
        self.assertEqual('.', urlutils.determine_relative_path(
674
670
                         '/bar', '/bar'))
675
 
 
676
 
 
677
 
class TestParseURL(TestCase):
678
 
 
679
 
    def test_parse_url(self):
680
 
        self.assertEqual(urlutils.parse_url('http://example.com:80/one'),
681
 
            ('http', None, None, 'example.com', 80, '/one'))
682
 
        self.assertEqual(urlutils.parse_url('http://[1:2:3::40]/one'),
683
 
                ('http', None, None, '1:2:3::40', None, '/one'))
684
 
        self.assertEqual(urlutils.parse_url('http://[1:2:3::40]:80/one'),
685
 
                ('http', None, None, '1:2:3::40', 80, '/one'))