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
181
181
self.assertEqual('path/..', dirname('path/../foo'))
182
182
self.assertEqual('../path', dirname('../path/foo'))
185
def test(expected, *args):
186
joined = urlutils.join(*args)
187
self.assertEqual(expected, joined)
189
# Test a single element
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')
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')
206
# Cannot go above root
207
self.assertRaises(InvalidURLJoin, urlutils.join,
208
'http://foo', '../baz')
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)