/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: John Arbash Meinel
  • Date: 2006-05-12 01:44:08 UTC
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060512014408-204a193b59d5ee61
Adding bzrlib.urlutils.join() to handle joining URLs

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import sys
21
21
 
22
22
import bzrlib
23
 
from bzrlib.errors import InvalidURL
 
23
from bzrlib.errors import InvalidURL, InvalidURLJoin
24
24
import bzrlib.urlutils as urlutils
25
25
from bzrlib.tests import TestCaseInTempDir, TestCase
26
26
 
181
181
        self.assertEqual('path/..', dirname('path/../foo'))
182
182
        self.assertEqual('../path', dirname('../path/foo'))
183
183
 
 
184
    def test_join(self):
 
185
        def test(expected, *args):
 
186
            joined = urlutils.join(*args)
 
187
            self.assertEqual(expected, joined)
 
188
 
 
189
        # Test a single element
 
190
        test('foo', 'foo')
 
191
 
 
192
        # Test relative path joining
 
193
        test('foo/bar', 'foo', 'bar')
 
194
        test('http://foo/bar', 'http://foo', 'bar')
 
195
        test('http://foo/bar', 'http://foo', '.', 'bar')
 
196
        test('http://foo/baz', 'http://foo', 'bar', '../baz')
 
197
        test('http://foo/bar/baz', 'http://foo', 'bar/baz')
 
198
        test('http://foo/baz', 'http://foo', 'bar/../baz')
 
199
 
 
200
        # Absolute paths
 
201
        test('http://bar', 'http://foo', 'http://bar')
 
202
        test('sftp://bzr/foo', 'http://foo', 'bar', 'sftp://bzr/foo')
 
203
        test('file:///bar', 'foo', 'file:///bar')
 
204
        
 
205
        # Invalid joinings
 
206
        # Cannot go above root
 
207
        self.assertRaises(InvalidURLJoin, urlutils.join,
 
208
                'http://foo', '../baz')
 
209
 
184
210
    def test_function_type(self):
185
211
        if sys.platform == 'win32':
186
212
            self.assertEqual(urlutils._win32_local_path_to_url, urlutils.local_path_to_url)