197
197
joined = urlutils.join(*args)
198
198
self.assertEqual(expected, joined)
200
# Test a single element
203
200
# Test relative path joining
201
test('foo', 'foo') # relative fragment with nothing is preserved.
204
202
test('foo/bar', 'foo', 'bar')
205
203
test('http://foo/bar', 'http://foo', 'bar')
206
204
test('http://foo/bar', 'http://foo', '.', 'bar')
207
205
test('http://foo/baz', 'http://foo', 'bar', '../baz')
208
206
test('http://foo/bar/baz', 'http://foo', 'bar/baz')
209
207
test('http://foo/baz', 'http://foo', 'bar/../baz')
208
test('http://foo/baz', 'http://foo/bar/', '../baz')
211
test('http://foo', 'http://foo') # abs url with nothing is preserved.
212
212
test('http://bar', 'http://foo', 'http://bar')
213
213
test('sftp://bzr/foo', 'http://foo', 'bar', 'sftp://bzr/foo')
214
214
test('file:///bar', 'foo', 'file:///bar')
215
test('http://bar/', 'http://foo', 'http://bar/')
216
test('http://bar/a', 'http://foo', 'http://bar/a')
217
test('http://bar/a/', 'http://foo', 'http://bar/a/')
216
219
# From a base path
217
220
test('file:///foo', 'file:///', 'foo')
222
225
# Invalid joinings
223
226
# Cannot go above root
227
# Implicitly at root:
224
228
self.assertRaises(InvalidURLJoin, urlutils.join,
225
229
'http://foo', '../baz')
230
self.assertRaises(InvalidURLJoin, urlutils.join,
232
# Joining from a path explicitly under the root.
233
self.assertRaises(InvalidURLJoin, urlutils.join,
234
'http://foo/a', '../../b')
236
def test_joinpath(self):
237
def test(expected, *args):
238
joined = urlutils.joinpath(*args)
239
self.assertEqual(expected, joined)
241
# Test a single element
244
# Test relative path joining
245
test('foo/bar', 'foo', 'bar')
246
test('foo/bar', 'foo', '.', 'bar')
247
test('foo/baz', 'foo', 'bar', '../baz')
248
test('foo/bar/baz', 'foo', 'bar/baz')
249
test('foo/baz', 'foo', 'bar/../baz')
251
# Test joining to an absolute path
253
test('/foo', '/foo', '.')
254
test('/foo/bar', '/foo', 'bar')
255
test('/', '/foo', '..')
257
# Test joining with an absolute path
258
test('/bar', 'foo', '/bar')
260
# Test joining to a path with a trailing slash
261
test('foo/bar', 'foo/', 'bar')
264
# Cannot go above root
265
self.assertRaises(InvalidURLJoin, urlutils.joinpath, '/', '../baz')
266
self.assertRaises(InvalidURLJoin, urlutils.joinpath, '/', '..')
267
self.assertRaises(InvalidURLJoin, urlutils.joinpath, '/', '/..')
227
269
def test_function_type(self):
228
270
if sys.platform == 'win32':