23
from bzrlib import osutils, urlutils
23
from bzrlib import osutils, urlutils, win32utils
25
25
from bzrlib.errors import InvalidURL, InvalidURLJoin
26
26
from bzrlib.tests import TestCaseInTempDir, TestCase, TestSkipped
203
203
joined = urlutils.join(*args)
204
204
self.assertEqual(expected, joined)
206
# Test a single element
209
206
# Test relative path joining
207
test('foo', 'foo') # relative fragment with nothing is preserved.
210
208
test('foo/bar', 'foo', 'bar')
211
209
test('http://foo/bar', 'http://foo', 'bar')
212
210
test('http://foo/bar', 'http://foo', '.', 'bar')
213
211
test('http://foo/baz', 'http://foo', 'bar', '../baz')
214
212
test('http://foo/bar/baz', 'http://foo', 'bar/baz')
215
213
test('http://foo/baz', 'http://foo', 'bar/../baz')
214
test('http://foo/baz', 'http://foo/bar/', '../baz')
217
test('http://foo', 'http://foo') # abs url with nothing is preserved.
218
218
test('http://bar', 'http://foo', 'http://bar')
219
219
test('sftp://bzr/foo', 'http://foo', 'bar', 'sftp://bzr/foo')
220
220
test('file:///bar', 'foo', 'file:///bar')
221
test('http://bar/', 'http://foo', 'http://bar/')
222
test('http://bar/a', 'http://foo', 'http://bar/a')
223
test('http://bar/a/', 'http://foo', 'http://bar/a/')
222
225
# From a base path
223
226
test('file:///foo', 'file:///', 'foo')
228
231
# Invalid joinings
229
232
# Cannot go above root
233
# Implicitly at root:
230
234
self.assertRaises(InvalidURLJoin, urlutils.join,
231
235
'http://foo', '../baz')
236
self.assertRaises(InvalidURLJoin, urlutils.join,
238
# Joining from a path explicitly under the root.
239
self.assertRaises(InvalidURLJoin, urlutils.join,
240
'http://foo/a', '../../b')
242
def test_joinpath(self):
243
def test(expected, *args):
244
joined = urlutils.joinpath(*args)
245
self.assertEqual(expected, joined)
247
# Test a single element
250
# Test relative path joining
251
test('foo/bar', 'foo', 'bar')
252
test('foo/bar', 'foo', '.', 'bar')
253
test('foo/baz', 'foo', 'bar', '../baz')
254
test('foo/bar/baz', 'foo', 'bar/baz')
255
test('foo/baz', 'foo', 'bar/../baz')
257
# Test joining to an absolute path
259
test('/foo', '/foo', '.')
260
test('/foo/bar', '/foo', 'bar')
261
test('/', '/foo', '..')
263
# Test joining with an absolute path
264
test('/bar', 'foo', '/bar')
266
# Test joining to a path with a trailing slash
267
test('foo/bar', 'foo/', 'bar')
270
# Cannot go above root
271
self.assertRaises(InvalidURLJoin, urlutils.joinpath, '/', '../baz')
272
self.assertRaises(InvalidURLJoin, urlutils.joinpath, '/', '..')
273
self.assertRaises(InvalidURLJoin, urlutils.joinpath, '/', '/..')
233
275
def test_function_type(self):
234
276
if sys.platform == 'win32':