270
270
self.assertRaises(InvalidURLJoin, urlutils.joinpath, '/', '..')
271
271
self.assertRaises(InvalidURLJoin, urlutils.joinpath, '/', '/..')
273
def test_join_segment_parameters_raw(self):
274
join_segment_parameters_raw = urlutils.join_segment_parameters_raw
275
self.assertEquals("/somedir/path",
276
join_segment_parameters_raw("/somedir/path"))
277
self.assertEquals("/somedir/path,rawdata",
278
join_segment_parameters_raw("/somedir/path", "rawdata"))
279
self.assertRaises(InvalidURLJoin,
280
join_segment_parameters_raw, "/somedir/path",
281
"rawdata1,rawdata2,rawdata3")
282
self.assertEquals("/somedir/path,bla,bar",
283
join_segment_parameters_raw("/somedir/path", "bla", "bar"))
284
self.assertEquals("/somedir,exist=some/path,bla,bar",
285
join_segment_parameters_raw("/somedir,exist=some/path",
287
self.assertRaises(TypeError, join_segment_parameters_raw,
290
def test_join_segment_parameters(self):
291
join_segment_parameters = urlutils.join_segment_parameters
292
self.assertEquals("/somedir/path",
293
join_segment_parameters("/somedir/path", {}))
294
self.assertEquals("/somedir/path,key1=val1",
295
join_segment_parameters("/somedir/path", {"key1": "val1"}))
296
self.assertRaises(InvalidURLJoin,
297
join_segment_parameters, "/somedir/path",
298
{"branch": "brr,brr,brr"})
299
self.assertRaises(InvalidURLJoin,
300
join_segment_parameters, "/somedir/path", {"key1=val1": "val2"})
301
self.assertEquals("/somedir/path,key1=val1,key2=val2",
302
join_segment_parameters("/somedir/path", {
303
"key1": "val1", "key2": "val2"}))
304
self.assertEquals("/somedir/path,key1=val1,key2=val2",
305
join_segment_parameters("/somedir/path,key1=val1", {
307
self.assertEquals("/somedir/path,key1=val2",
308
join_segment_parameters("/somedir/path,key1=val1", {
310
self.assertEquals("/somedir,exist=some/path,key1=val1",
311
join_segment_parameters("/somedir,exist=some/path",
313
self.assertEquals("/,key1=val1,key2=val2",
314
join_segment_parameters("/,key1=val1", {"key2": "val2"}))
315
self.assertRaises(TypeError,
316
join_segment_parameters, "/,key1=val1", {"foo": 42})
273
318
def test_function_type(self):
274
319
if sys.platform == 'win32':
275
320
self.assertEqual(urlutils._win32_local_path_to_url, urlutils.local_path_to_url)
412
457
self.assertEqual(('path/..', 'foo'), split('path/../foo'))
413
458
self.assertEqual(('../path', 'foo'), split('../path/foo'))
460
def test_split_segment_parameters_raw(self):
461
split_segment_parameters_raw = urlutils.split_segment_parameters_raw
462
self.assertEquals(("/some/path", []),
463
split_segment_parameters_raw("/some/path"))
464
self.assertEquals(("/some/path", ["tip"]),
465
split_segment_parameters_raw("/some/path,tip"))
466
self.assertEquals(("/some,dir/path", ["tip"]),
467
split_segment_parameters_raw("/some,dir/path,tip"))
468
self.assertEquals(("/somedir/path", ["heads%2Ftip"]),
469
split_segment_parameters_raw("/somedir/path,heads%2Ftip"))
470
self.assertEquals(("/somedir/path", ["heads%2Ftip", "bar"]),
471
split_segment_parameters_raw("/somedir/path,heads%2Ftip,bar"))
472
self.assertEquals(("/", ["key1=val1"]),
473
split_segment_parameters_raw(",key1=val1"))
474
self.assertEquals(("foo/", ["key1=val1"]),
475
split_segment_parameters_raw("foo/,key1=val1"))
476
self.assertEquals(("foo/base,la=bla/other/elements", []),
477
split_segment_parameters_raw("foo/base,la=bla/other/elements"))
478
self.assertEquals(("foo/base,la=bla/other/elements", ["a=b"]),
479
split_segment_parameters_raw("foo/base,la=bla/other/elements,a=b"))
481
def test_split_segment_parameters(self):
482
split_segment_parameters = urlutils.split_segment_parameters
483
self.assertEquals(("/some/path", {}),
484
split_segment_parameters("/some/path"))
485
self.assertEquals(("/some/path", {"branch": "tip"}),
486
split_segment_parameters("/some/path,branch=tip"))
487
self.assertEquals(("/some,dir/path", {"branch": "tip"}),
488
split_segment_parameters("/some,dir/path,branch=tip"))
489
self.assertEquals(("/somedir/path", {"ref": "heads%2Ftip"}),
490
split_segment_parameters("/somedir/path,ref=heads%2Ftip"))
491
self.assertEquals(("/somedir/path",
492
{"ref": "heads%2Ftip", "key1": "val1"}),
493
split_segment_parameters(
494
"/somedir/path,ref=heads%2Ftip,key1=val1"))
495
self.assertEquals(("/somedir/path", {"ref": "heads%2F=tip"}),
496
split_segment_parameters("/somedir/path,ref=heads%2F=tip"))
497
self.assertEquals(("/", {"key1": "val1"}),
498
split_segment_parameters(",key1=val1"))
499
self.assertEquals(("foo/", {"key1": "val1"}),
500
split_segment_parameters("foo/,key1=val1"))
501
self.assertEquals(("foo/base,key1=val1/other/elements", {}),
502
split_segment_parameters("foo/base,key1=val1/other/elements"))
503
self.assertEquals(("foo/base,key1=val1/other/elements",
504
{"key2": "val2"}), split_segment_parameters(
505
"foo/base,key1=val1/other/elements,key2=val2"))
415
507
def test_win32_strip_local_trailing_slash(self):
416
508
strip = urlutils._win32_strip_local_trailing_slash
417
509
self.assertEqual('file://', strip('file://'))