191
192
self.assertEqual('http://host/path/to',
192
193
dirname('http://host/path/to/foo/'))
193
194
self.assertEqual('http://host/path/to/foo',
194
dirname('http://host/path/to/foo/', exclude_trailing_slash=False))
195
dirname('http://host/path/to/foo/',
196
exclude_trailing_slash=False))
195
197
self.assertEqual('http://host/', dirname('http://host/path'))
196
198
self.assertEqual('http://host/', dirname('http://host/'))
197
199
self.assertEqual('http://host', dirname('http://host'))
313
315
self.assertEqual("/somedir/path",
314
316
join_segment_parameters_raw("/somedir/path"))
315
317
self.assertEqual("/somedir/path,rawdata",
316
join_segment_parameters_raw("/somedir/path", "rawdata"))
318
join_segment_parameters_raw(
319
"/somedir/path", "rawdata"))
317
320
self.assertRaises(urlutils.InvalidURLJoin,
318
321
join_segment_parameters_raw, "/somedir/path",
319
322
"rawdata1,rawdata2,rawdata3")
320
323
self.assertEqual("/somedir/path,bla,bar",
321
join_segment_parameters_raw("/somedir/path", "bla", "bar"))
322
self.assertEqual("/somedir,exist=some/path,bla,bar",
323
join_segment_parameters_raw("/somedir,exist=some/path",
324
join_segment_parameters_raw(
325
"/somedir/path", "bla", "bar"))
327
"/somedir,exist=some/path,bla,bar",
328
join_segment_parameters_raw("/somedir,exist=some/path",
325
330
self.assertRaises(TypeError, join_segment_parameters_raw,
329
334
join_segment_parameters = urlutils.join_segment_parameters
330
335
self.assertEqual("/somedir/path",
331
336
join_segment_parameters("/somedir/path", {}))
332
self.assertEqual("/somedir/path,key1=val1",
333
join_segment_parameters("/somedir/path", {"key1": "val1"}))
338
"/somedir/path,key1=val1",
339
join_segment_parameters("/somedir/path", {"key1": "val1"}))
334
340
self.assertRaises(urlutils.InvalidURLJoin,
335
341
join_segment_parameters, "/somedir/path",
336
342
{"branch": "brr,brr,brr"})
337
self.assertRaises(urlutils.InvalidURLJoin,
338
join_segment_parameters, "/somedir/path", {"key1=val1": "val2"})
344
urlutils.InvalidURLJoin,
345
join_segment_parameters, "/somedir/path", {"key1=val1": "val2"})
339
346
self.assertEqual("/somedir/path,key1=val1,key2=val2",
340
347
join_segment_parameters("/somedir/path", {
341
348
"key1": "val1", "key2": "val2"}))
348
355
self.assertEqual("/somedir,exist=some/path,key1=val1",
349
356
join_segment_parameters("/somedir,exist=some/path",
350
357
{"key1": "val1"}))
351
self.assertEqual("/,key1=val1,key2=val2",
352
join_segment_parameters("/,key1=val1", {"key2": "val2"}))
359
"/,key1=val1,key2=val2",
360
join_segment_parameters("/,key1=val1", {"key2": "val2"}))
353
361
self.assertRaises(TypeError,
354
362
join_segment_parameters, "/,key1=val1", {"foo": 42})
446
455
from_url = urlutils._win32_local_path_from_url
447
456
self.assertEqual('C:/path/to/foo',
448
457
from_url('file:///C|/path/to/foo'))
449
self.assertEqual(u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
450
from_url('file:///d|/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s'))
451
self.assertEqual(u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
452
from_url('file:///d:/path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))
459
u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
460
from_url('file:///d|/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s'))
462
u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
463
from_url('file:///d:/path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))
453
464
self.assertEqual('/', from_url('file:///'))
454
465
self.assertEqual('C:/path/to/foo',
455
466
from_url('file:///C|/path/to/foo,branch=foo'))
504
515
split('http://host/path/to/foo'))
505
516
self.assertEqual(('http://host/path/to', 'foo'),
506
517
split('http://host/path/to/foo/'))
507
self.assertEqual(('http://host/path/to/foo', ''),
508
split('http://host/path/to/foo/', exclude_trailing_slash=False))
519
('http://host/path/to/foo', ''),
520
split('http://host/path/to/foo/', exclude_trailing_slash=False))
509
521
self.assertEqual(('http://host/', 'path'), split('http://host/path'))
510
522
self.assertEqual(('http://host/', ''), split('http://host/'))
511
523
self.assertEqual(('http://host', ''), split('http://host'))
536
548
split_segment_parameters_raw("/some/path,tip"))
537
549
self.assertEqual(("/some,dir/path", ["tip"]),
538
550
split_segment_parameters_raw("/some,dir/path,tip"))
539
self.assertEqual(("/somedir/path", ["heads%2Ftip"]),
540
split_segment_parameters_raw("/somedir/path,heads%2Ftip"))
541
self.assertEqual(("/somedir/path", ["heads%2Ftip", "bar"]),
542
split_segment_parameters_raw("/somedir/path,heads%2Ftip,bar"))
552
("/somedir/path", ["heads%2Ftip"]),
553
split_segment_parameters_raw("/somedir/path,heads%2Ftip"))
555
("/somedir/path", ["heads%2Ftip", "bar"]),
556
split_segment_parameters_raw("/somedir/path,heads%2Ftip,bar"))
543
557
# Check relative references with relative paths
544
558
self.assertEqual(("", ["key1=val1"]),
545
559
split_segment_parameters_raw(",key1=val1"))
547
561
split_segment_parameters_raw("foo/,key1=val1"))
548
562
self.assertEqual(("foo", ["key1=val1"]),
549
563
split_segment_parameters_raw("foo,key1=val1"))
550
self.assertEqual(("foo/base,la=bla/other/elements", []),
551
split_segment_parameters_raw("foo/base,la=bla/other/elements"))
552
self.assertEqual(("foo/base,la=bla/other/elements", ["a=b"]),
553
split_segment_parameters_raw("foo/base,la=bla/other/elements,a=b"))
565
("foo/base,la=bla/other/elements", []),
566
split_segment_parameters_raw("foo/base,la=bla/other/elements"))
568
("foo/base,la=bla/other/elements", ["a=b"]),
569
split_segment_parameters_raw("foo/base,la=bla/other/elements,a=b"))
554
570
# TODO: Check full URLs as well as relative references
556
572
def test_split_segment_parameters(self):
562
578
split_segment_parameters("/some/path,branch=tip"))
563
579
self.assertEqual(("/some,dir/path", {"branch": "tip"}),
564
580
split_segment_parameters("/some,dir/path,branch=tip"))
565
self.assertEqual(("/somedir/path", {"ref": "heads%2Ftip"}),
566
split_segment_parameters("/somedir/path,ref=heads%2Ftip"))
582
("/somedir/path", {"ref": "heads%2Ftip"}),
583
split_segment_parameters("/somedir/path,ref=heads%2Ftip"))
567
584
self.assertEqual(("/somedir/path",
568
585
{"ref": "heads%2Ftip", "key1": "val1"}),
569
586
split_segment_parameters(
570
587
"/somedir/path,ref=heads%2Ftip,key1=val1"))
571
self.assertEqual(("/somedir/path", {"ref": "heads%2F=tip"}),
572
split_segment_parameters("/somedir/path,ref=heads%2F=tip"))
589
("/somedir/path", {"ref": "heads%2F=tip"}),
590
split_segment_parameters("/somedir/path,ref=heads%2F=tip"))
573
591
# Check relative references with relative paths
574
592
self.assertEqual(("", {"key1": "val1"}),
575
593
split_segment_parameters(",key1=val1"))
576
594
self.assertEqual(("foo/", {"key1": "val1"}),
577
595
split_segment_parameters("foo/,key1=val1"))
578
self.assertEqual(("foo/base,key1=val1/other/elements", {}),
579
split_segment_parameters("foo/base,key1=val1/other/elements"))
597
("foo/base,key1=val1/other/elements", {}),
598
split_segment_parameters("foo/base,key1=val1/other/elements"))
580
599
self.assertEqual(("foo/base,key1=val1/other/elements",
581
600
{"key2": "val2"}), split_segment_parameters(
582
601
"foo/base,key1=val1/other/elements,key2=val2"))
702
721
test('../person/feature', 'http://host/branch/mainline',
703
722
'http://host/branch/person/feature')
704
723
test('..', 'http://host/branch', 'http://host/')
705
test('http://host2/branch', 'http://host1/branch', 'http://host2/branch')
724
test('http://host2/branch', 'http://host1/branch',
725
'http://host2/branch')
706
726
test('.', 'http://host1/branch', 'http://host1/branch')
707
727
test('../../../branch/2b', 'file:///home/jelmer/foo/bar/2b',
708
728
'file:///home/jelmer/branch/2b')
721
741
# TODO: treat http://host as http://host/
722
742
# relative_url is typically called from a branch.base or
723
743
# transport.base which always ends with a /
724
#test('a', 'http://host', 'http://host/a')
744
# test('a', 'http://host', 'http://host/a')
725
745
test('http://host/a', 'http://host', 'http://host/a')
726
#test('.', 'http://host', 'http://host/')
746
# test('.', 'http://host', 'http://host/')
727
747
test('http://host/', 'http://host', 'http://host/')
728
#test('.', 'http://host/', 'http://host')
748
# test('.', 'http://host/', 'http://host')
729
749
test('http://host', 'http://host/', 'http://host')
731
751
# On Windows file:///C:/path/to and file:///D:/other/path
829
849
def test_rebase_success(self):
830
850
self.assertEqual('../bar', urlutils.rebase_url('bar', 'http://baz/',
831
851
'http://baz/qux'))
832
self.assertEqual('qux/bar', urlutils.rebase_url('bar',
833
'http://baz/qux', 'http://baz/'))
834
self.assertEqual('.', urlutils.rebase_url('foo',
835
'http://bar/', 'http://bar/foo/'))
836
self.assertEqual('qux/bar', urlutils.rebase_url('../bar',
837
'http://baz/qux/foo', 'http://baz/'))
854
urlutils.rebase_url('bar', 'http://baz/qux', 'http://baz/'))
856
'.', urlutils.rebase_url('foo', 'http://bar/', 'http://bar/foo/'))
859
urlutils.rebase_url('../bar', 'http://baz/qux/foo', 'http://baz/'))
839
861
def test_determine_relative_path(self):
840
862
self.assertEqual('../../baz/bar',
1000
1022
urlutils.file_relpath("file:///A:/", "file:///A:/"))
1001
1023
self.assertEqual("",
1002
1024
urlutils.file_relpath("file:///A|/", "file:///A:/"))
1003
self.assertEqual("",
1004
urlutils.file_relpath("file:///A:/b/", "file:///A:/b/"))
1005
self.assertEqual("",
1006
urlutils.file_relpath("file:///A:/b", "file:///A:/b/"))
1007
self.assertEqual("",
1008
urlutils.file_relpath("file:///A:/b/", "file:///A:/b"))
1026
"", urlutils.file_relpath("file:///A:/b/", "file:///A:/b/"))
1028
"", urlutils.file_relpath("file:///A:/b", "file:///A:/b/"))
1030
"", urlutils.file_relpath("file:///A:/b/", "file:///A:/b"))
1010
1032
def test_child_posix(self):
1011
1033
self._with_posix_paths()
1012
self.assertEqual("b",
1013
urlutils.file_relpath("file:///a", "file:///a/b"))
1014
self.assertEqual("b",
1015
urlutils.file_relpath("file:///a/", "file:///a/b"))
1016
self.assertEqual("b/c",
1017
urlutils.file_relpath("file:///a", "file:///a/b/c"))
1035
"b", urlutils.file_relpath("file:///a", "file:///a/b"))
1037
"b", urlutils.file_relpath("file:///a/", "file:///a/b"))
1039
"b/c", urlutils.file_relpath("file:///a", "file:///a/b/c"))
1019
1041
def test_child_win32(self):
1020
1042
self._with_win32_paths()
1021
self.assertEqual("b",
1022
urlutils.file_relpath("file:///A:/", "file:///A:/b"))
1023
self.assertEqual("b",
1024
urlutils.file_relpath("file:///A|/", "file:///A:/b"))
1025
self.assertEqual("c",
1026
urlutils.file_relpath("file:///A:/b", "file:///A:/b/c"))
1027
self.assertEqual("c",
1028
urlutils.file_relpath("file:///A:/b/", "file:///A:/b/c"))
1029
self.assertEqual("c/d",
1030
urlutils.file_relpath("file:///A:/b", "file:///A:/b/c/d"))
1044
"b", urlutils.file_relpath("file:///A:/", "file:///A:/b"))
1046
"b", urlutils.file_relpath("file:///A|/", "file:///A:/b"))
1048
"c", urlutils.file_relpath("file:///A:/b", "file:///A:/b/c"))
1050
"c", urlutils.file_relpath("file:///A:/b/", "file:///A:/b/c"))
1052
"c/d", urlutils.file_relpath("file:///A:/b", "file:///A:/b/c/d"))
1032
1054
def test_sibling_posix(self):
1033
1055
self._with_posix_paths()
1034
self.assertRaises(PathNotChild,
1035
urlutils.file_relpath, "file:///a/b", "file:///a/c")
1036
self.assertRaises(PathNotChild,
1037
urlutils.file_relpath, "file:///a/b/", "file:///a/c")
1038
self.assertRaises(PathNotChild,
1039
urlutils.file_relpath, "file:///a/b/", "file:///a/c/")
1058
urlutils.file_relpath, "file:///a/b", "file:///a/c")
1061
urlutils.file_relpath, "file:///a/b/", "file:///a/c")
1064
urlutils.file_relpath, "file:///a/b/", "file:///a/c/")
1041
1066
def test_sibling_win32(self):
1042
1067
self._with_win32_paths()
1043
self.assertRaises(PathNotChild,
1044
urlutils.file_relpath, "file:///A:/b", "file:///A:/c")
1045
self.assertRaises(PathNotChild,
1046
urlutils.file_relpath, "file:///A:/b/", "file:///A:/c")
1047
self.assertRaises(PathNotChild,
1048
urlutils.file_relpath, "file:///A:/b/", "file:///A:/c/")
1070
urlutils.file_relpath, "file:///A:/b", "file:///A:/c")
1073
urlutils.file_relpath, "file:///A:/b/", "file:///A:/c")
1076
urlutils.file_relpath, "file:///A:/b/", "file:///A:/c/")
1050
1078
def test_parent_posix(self):
1051
1079
self._with_posix_paths()
1057
1085
def test_parent_win32(self):
1058
1086
self._with_win32_paths()
1059
self.assertRaises(PathNotChild,
1060
urlutils.file_relpath, "file:///A:/b", "file:///A:/")
1061
self.assertRaises(PathNotChild,
1062
urlutils.file_relpath, "file:///A:/b/c", "file:///A:/b")
1089
urlutils.file_relpath, "file:///A:/b", "file:///A:/")
1092
urlutils.file_relpath, "file:///A:/b/c", "file:///A:/b")
1065
1095
class QuoteTests(TestCase):