49
46
self.assertEqual('foo', basename('http://host/path/to/foo'))
50
47
self.assertEqual('foo', basename('http://host/path/to/foo/'))
52
'', basename('http://host/path/to/foo/',
53
exclude_trailing_slash=False))
49
basename('http://host/path/to/foo/', exclude_trailing_slash=False))
54
50
self.assertEqual('path', basename('http://host/path'))
55
51
self.assertEqual('', basename('http://host/'))
56
52
self.assertEqual('', basename('http://host'))
57
53
self.assertEqual('path', basename('http:///nohost/path'))
59
self.assertEqual('path', basename(
60
'random+scheme://user:pass@ahost:port/path'))
61
self.assertEqual('path', basename(
62
'random+scheme://user:pass@ahost:port/path/'))
55
self.assertEqual('path', basename('random+scheme://user:pass@ahost:port/path'))
56
self.assertEqual('path', basename('random+scheme://user:pass@ahost:port/path/'))
63
57
self.assertEqual('', basename('random+scheme://user:pass@ahost:port/'))
66
60
self.assertEqual('foo', basename('path/to/foo'))
67
61
self.assertEqual('foo', basename('path/to/foo/'))
68
62
self.assertEqual('', basename('path/to/foo/',
69
exclude_trailing_slash=False))
63
exclude_trailing_slash=False))
70
64
self.assertEqual('foo', basename('path/../foo'))
71
65
self.assertEqual('foo', basename('../path/foo'))
180
171
dirname = urlutils.dirname
181
172
if sys.platform == 'win32':
182
173
self.assertRaises(urlutils.InvalidURL, dirname,
183
'file:///path/to/foo')
174
'file:///path/to/foo')
184
175
self.assertEqual('file:///C|/', dirname('file:///C|/foo'))
185
176
self.assertEqual('file:///C|/', dirname('file:///C|/'))
187
178
self.assertEqual('file:///', dirname('file:///foo'))
188
179
self.assertEqual('file:///', dirname('file:///'))
190
self.assertEqual('http://host/path/to',
191
dirname('http://host/path/to/foo'))
192
self.assertEqual('http://host/path/to',
193
dirname('http://host/path/to/foo/'))
181
self.assertEqual('http://host/path/to', dirname('http://host/path/to/foo'))
182
self.assertEqual('http://host/path/to', dirname('http://host/path/to/foo/'))
194
183
self.assertEqual('http://host/path/to/foo',
195
dirname('http://host/path/to/foo/',
196
exclude_trailing_slash=False))
184
dirname('http://host/path/to/foo/', exclude_trailing_slash=False))
197
185
self.assertEqual('http://host/', dirname('http://host/path'))
198
186
self.assertEqual('http://host/', dirname('http://host/'))
199
187
self.assertEqual('http://host', dirname('http://host'))
200
188
self.assertEqual('http:///nohost', dirname('http:///nohost/path'))
202
190
self.assertEqual('random+scheme://user:pass@ahost:port/',
203
dirname('random+scheme://user:pass@ahost:port/path'))
204
self.assertEqual('random+scheme://user:pass@ahost:port/',
205
dirname('random+scheme://user:pass@ahost:port/path/'))
206
self.assertEqual('random+scheme://user:pass@ahost:port/',
207
dirname('random+scheme://user:pass@ahost:port/'))
191
dirname('random+scheme://user:pass@ahost:port/path'))
192
self.assertEqual('random+scheme://user:pass@ahost:port/',
193
dirname('random+scheme://user:pass@ahost:port/path/'))
194
self.assertEqual('random+scheme://user:pass@ahost:port/',
195
dirname('random+scheme://user:pass@ahost:port/'))
210
198
self.assertEqual('path/to', dirname('path/to/foo'))
211
199
self.assertEqual('path/to', dirname('path/to/foo/'))
212
200
self.assertEqual('path/to/foo',
213
dirname('path/to/foo/', exclude_trailing_slash=False))
201
dirname('path/to/foo/', exclude_trailing_slash=False))
214
202
self.assertEqual('path/..', dirname('path/../foo'))
215
203
self.assertEqual('../path', dirname('../path/foo'))
217
205
def test_is_url(self):
218
206
self.assertTrue(urlutils.is_url('http://foo/bar'))
219
207
self.assertTrue(urlutils.is_url('bzr+ssh://foo/bar'))
304
292
# Invalid joinings
305
293
# Cannot go above root
306
294
self.assertRaises(urlutils.InvalidURLJoin, urlutils.joinpath, '/',
308
self.assertRaises(urlutils.InvalidURLJoin, urlutils.joinpath, '/',
310
self.assertRaises(urlutils.InvalidURLJoin, urlutils.joinpath, '/',
296
self.assertRaises(urlutils.InvalidURLJoin, urlutils.joinpath, '/',
298
self.assertRaises(urlutils.InvalidURLJoin, urlutils.joinpath, '/',
313
301
def test_join_segment_parameters_raw(self):
314
302
join_segment_parameters_raw = urlutils.join_segment_parameters_raw
315
self.assertEqual("/somedir/path",
316
join_segment_parameters_raw("/somedir/path"))
317
self.assertEqual("/somedir/path,rawdata",
318
join_segment_parameters_raw(
319
"/somedir/path", "rawdata"))
303
self.assertEqual("/somedir/path",
304
join_segment_parameters_raw("/somedir/path"))
305
self.assertEqual("/somedir/path,rawdata",
306
join_segment_parameters_raw("/somedir/path", "rawdata"))
320
307
self.assertRaises(urlutils.InvalidURLJoin,
321
join_segment_parameters_raw, "/somedir/path",
322
"rawdata1,rawdata2,rawdata3")
308
join_segment_parameters_raw, "/somedir/path",
309
"rawdata1,rawdata2,rawdata3")
323
310
self.assertEqual("/somedir/path,bla,bar",
324
join_segment_parameters_raw(
325
"/somedir/path", "bla", "bar"))
327
"/somedir,exist=some/path,bla,bar",
311
join_segment_parameters_raw("/somedir/path", "bla", "bar"))
312
self.assertEqual("/somedir,exist=some/path,bla,bar",
328
313
join_segment_parameters_raw("/somedir,exist=some/path",
330
self.assertRaises(TypeError, join_segment_parameters_raw,
315
self.assertRaises(TypeError, join_segment_parameters_raw,
333
318
def test_join_segment_parameters(self):
334
319
join_segment_parameters = urlutils.join_segment_parameters
335
self.assertEqual("/somedir/path",
336
join_segment_parameters("/somedir/path", {}))
338
"/somedir/path,key1=val1",
320
self.assertEqual("/somedir/path",
321
join_segment_parameters("/somedir/path", {}))
322
self.assertEqual("/somedir/path,key1=val1",
339
323
join_segment_parameters("/somedir/path", {"key1": "val1"}))
340
324
self.assertRaises(urlutils.InvalidURLJoin,
341
join_segment_parameters, "/somedir/path",
342
{"branch": "brr,brr,brr"})
344
urlutils.InvalidURLJoin,
325
join_segment_parameters, "/somedir/path",
326
{"branch": "brr,brr,brr"})
327
self.assertRaises(urlutils.InvalidURLJoin,
345
328
join_segment_parameters, "/somedir/path", {"key1=val1": "val2"})
346
329
self.assertEqual("/somedir/path,key1=val1,key2=val2",
347
join_segment_parameters("/somedir/path", {
348
"key1": "val1", "key2": "val2"}))
330
join_segment_parameters("/somedir/path", {
331
"key1": "val1", "key2": "val2"}))
349
332
self.assertEqual("/somedir/path,key1=val1,key2=val2",
350
join_segment_parameters("/somedir/path,key1=val1", {
333
join_segment_parameters("/somedir/path,key1=val1", {
352
335
self.assertEqual("/somedir/path,key1=val2",
353
join_segment_parameters("/somedir/path,key1=val1", {
336
join_segment_parameters("/somedir/path,key1=val1", {
355
338
self.assertEqual("/somedir,exist=some/path,key1=val1",
356
join_segment_parameters("/somedir,exist=some/path",
359
"/,key1=val1,key2=val2",
339
join_segment_parameters("/somedir,exist=some/path",
341
self.assertEqual("/,key1=val1,key2=val2",
360
342
join_segment_parameters("/,key1=val1", {"key2": "val2"}))
361
343
self.assertRaises(TypeError,
362
join_segment_parameters, "/,key1=val1", {"foo": 42})
344
join_segment_parameters, "/,key1=val1", {"foo": 42})
364
346
def test_function_type(self):
365
347
if sys.platform == 'win32':
366
348
self.assertEqual(urlutils._win32_local_path_to_url,
367
urlutils.local_path_to_url)
349
urlutils.local_path_to_url)
368
350
self.assertEqual(urlutils._win32_local_path_from_url,
369
urlutils.local_path_from_url)
351
urlutils.local_path_from_url)
371
353
self.assertEqual(urlutils._posix_local_path_to_url,
372
urlutils.local_path_to_url)
354
urlutils.local_path_to_url)
373
355
self.assertEqual(urlutils._posix_local_path_from_url,
374
urlutils.local_path_from_url)
356
urlutils.local_path_from_url)
376
358
def test_posix_local_path_to_url(self):
377
359
to_url = urlutils._posix_local_path_to_url
378
360
self.assertEqual('file:///path/to/foo',
379
to_url('/path/to/foo'))
361
to_url('/path/to/foo'))
381
363
self.assertEqual('file:///path/to/foo%2Cbar',
382
to_url('/path/to/foo,bar'))
364
to_url('/path/to/foo,bar'))
385
367
result = to_url(u'/path/to/r\xe4ksm\xf6rg\xe5s')
419
400
# self.assertEqual('file:///C:/path/to/foo%20',
420
401
# to_url('C:/path/to/foo '))
421
402
self.assertEqual('file:///C:/path/to/f%20oo',
422
to_url('C:/path/to/f oo'))
403
to_url('C:/path/to/f oo'))
424
405
self.assertEqual('file:///', to_url('/'))
426
407
self.assertEqual('file:///C:/path/to/foo%2Cbar',
427
to_url('C:/path/to/foo,bar'))
408
to_url('C:/path/to/foo,bar'))
429
410
result = to_url(u'd:/path/to/r\xe4ksm\xf6rg\xe5s')
430
411
except UnicodeError:
431
412
raise TestSkipped("local encoding cannot handle unicode")
434
'file:///D:/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
435
self.assertIsInstance(result, str)
414
self.assertEqual('file:///D:/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
415
self.assertFalse(isinstance(result, text_type))
437
417
def test_win32_unc_path_to_url(self):
438
418
self.requireFeature(features.win32_feature)
439
419
to_url = urlutils._win32_local_path_to_url
440
420
self.assertEqual('file://HOST/path',
441
to_url(r'\\HOST\path'))
421
to_url(r'\\HOST\path'))
442
422
self.assertEqual('file://HOST/path',
443
to_url('//HOST/path'))
423
to_url('//HOST/path'))
446
426
result = to_url(u'//HOST/path/to/r\xe4ksm\xf6rg\xe5s')
447
427
except UnicodeError:
448
428
raise TestSkipped("local encoding cannot handle unicode")
451
'file://HOST/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
430
self.assertEqual('file://HOST/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
452
431
self.assertFalse(isinstance(result, text_type))
454
433
def test_win32_local_path_from_url(self):
455
434
from_url = urlutils._win32_local_path_from_url
456
435
self.assertEqual('C:/path/to/foo',
457
from_url('file:///C|/path/to/foo'))
459
u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
436
from_url('file:///C|/path/to/foo'))
437
self.assertEqual(u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
460
438
from_url('file:///d|/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s'))
462
u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
439
self.assertEqual(u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
463
440
from_url('file:///d:/path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))
464
441
self.assertEqual('/', from_url('file:///'))
465
442
self.assertEqual('C:/path/to/foo',
466
from_url('file:///C|/path/to/foo,branch=foo'))
443
from_url('file:///C|/path/to/foo,branch=foo'))
468
445
self.assertRaises(urlutils.InvalidURL, from_url, 'file:///C:')
469
446
self.assertRaises(urlutils.InvalidURL, from_url, 'file:///c')
475
452
from_url = urlutils._win32_local_path_from_url
476
453
self.assertEqual('//HOST/path', from_url('file://HOST/path'))
477
454
self.assertEqual('//HOST/path',
478
from_url('file://HOST/path,branch=foo'))
455
from_url('file://HOST/path,branch=foo'))
479
456
# despite IE allows 2, 4, 5 and 6 slashes in URL to another machine
480
457
# we want to use only 2 slashes
481
458
# Firefox understand only 5 slashes in URL, but it's ugly
482
459
self.assertRaises(urlutils.InvalidURL, from_url, 'file:////HOST/path')
483
460
self.assertRaises(urlutils.InvalidURL, from_url, 'file://///HOST/path')
484
self.assertRaises(urlutils.InvalidURL, from_url,
485
'file://////HOST/path')
461
self.assertRaises(urlutils.InvalidURL, from_url, 'file://////HOST/path')
486
462
# check for file://C:/ instead of file:///C:/
487
463
self.assertRaises(urlutils.InvalidURL, from_url, 'file://C:/path')
489
465
def test_win32_extract_drive_letter(self):
490
466
extract = urlutils._win32_extract_drive_letter
491
467
self.assertEqual(('file:///C:', '/foo'), extract('file://', '/C:/foo'))
492
self.assertEqual(('file:///d|', '/path'),
493
extract('file://', '/d|/path'))
468
self.assertEqual(('file:///d|', '/path'), extract('file://', '/d|/path'))
494
469
self.assertRaises(urlutils.InvalidURL, extract, 'file://', '/path')
495
470
# Root drives without slash treated as invalid, see bug #841322
496
471
self.assertEqual(('file:///C:', '/'), extract('file://', '/C:/'))
503
478
# Test breezy.urlutils.split()
504
479
split = urlutils.split
505
480
if sys.platform == 'win32':
506
self.assertRaises(urlutils.InvalidURL, split,
507
'file:///path/to/foo')
481
self.assertRaises(urlutils.InvalidURL, split, 'file:///path/to/foo')
508
482
self.assertEqual(('file:///C|/', 'foo'), split('file:///C|/foo'))
509
483
self.assertEqual(('file:///C:/', ''), split('file:///C:/'))
511
485
self.assertEqual(('file:///', 'foo'), split('file:///foo'))
512
486
self.assertEqual(('file:///', ''), split('file:///'))
514
self.assertEqual(('http://host/path/to', 'foo'),
515
split('http://host/path/to/foo'))
516
self.assertEqual(('http://host/path/to', 'foo'),
517
split('http://host/path/to/foo/'))
519
('http://host/path/to/foo', ''),
488
self.assertEqual(('http://host/path/to', 'foo'), split('http://host/path/to/foo'))
489
self.assertEqual(('http://host/path/to', 'foo'), split('http://host/path/to/foo/'))
490
self.assertEqual(('http://host/path/to/foo', ''),
520
491
split('http://host/path/to/foo/', exclude_trailing_slash=False))
521
492
self.assertEqual(('http://host/', 'path'), split('http://host/path'))
522
493
self.assertEqual(('http://host/', ''), split('http://host/'))
523
494
self.assertEqual(('http://host', ''), split('http://host'))
524
self.assertEqual(('http:///nohost', 'path'),
525
split('http:///nohost/path'))
495
self.assertEqual(('http:///nohost', 'path'), split('http:///nohost/path'))
527
497
self.assertEqual(('random+scheme://user:pass@ahost:port/', 'path'),
528
split('random+scheme://user:pass@ahost:port/path'))
498
split('random+scheme://user:pass@ahost:port/path'))
529
499
self.assertEqual(('random+scheme://user:pass@ahost:port/', 'path'),
530
split('random+scheme://user:pass@ahost:port/path/'))
500
split('random+scheme://user:pass@ahost:port/path/'))
531
501
self.assertEqual(('random+scheme://user:pass@ahost:port/', ''),
532
split('random+scheme://user:pass@ahost:port/'))
502
split('random+scheme://user:pass@ahost:port/'))
535
505
self.assertEqual(('path/to', 'foo'), split('path/to/foo'))
536
506
self.assertEqual(('path/to', 'foo'), split('path/to/foo/'))
537
507
self.assertEqual(('path/to/foo', ''),
538
split('path/to/foo/', exclude_trailing_slash=False))
508
split('path/to/foo/', exclude_trailing_slash=False))
539
509
self.assertEqual(('path/..', 'foo'), split('path/../foo'))
540
510
self.assertEqual(('../path', 'foo'), split('../path/foo'))
542
def test_strip_segment_parameters(self):
543
strip_segment_parameters = urlutils.strip_segment_parameters
544
# Check relative references with absolute paths
545
self.assertEqual("/some/path",
546
strip_segment_parameters("/some/path"))
547
self.assertEqual("/some/path",
548
strip_segment_parameters("/some/path,tip"))
549
self.assertEqual("/some,dir/path",
550
strip_segment_parameters("/some,dir/path,tip"))
553
strip_segment_parameters("/somedir/path,heads%2Ftip"))
556
strip_segment_parameters("/somedir/path,heads%2Ftip,bar"))
557
# Check relative references with relative paths
558
self.assertEqual("", strip_segment_parameters(",key1=val1"))
559
self.assertEqual("foo/", strip_segment_parameters("foo/,key1=val1"))
560
self.assertEqual("foo", strip_segment_parameters("foo,key1=val1"))
562
"foo/base,la=bla/other/elements",
563
strip_segment_parameters("foo/base,la=bla/other/elements"))
565
"foo/base,la=bla/other/elements",
566
strip_segment_parameters("foo/base,la=bla/other/elements,a=b"))
567
# TODO: Check full URLs as well as relative references
569
512
def test_split_segment_parameters_raw(self):
570
513
split_segment_parameters_raw = urlutils.split_segment_parameters_raw
571
514
# Check relative references with absolute paths
572
515
self.assertEqual(("/some/path", []),
573
split_segment_parameters_raw("/some/path"))
516
split_segment_parameters_raw("/some/path"))
574
517
self.assertEqual(("/some/path", ["tip"]),
575
split_segment_parameters_raw("/some/path,tip"))
518
split_segment_parameters_raw("/some/path,tip"))
576
519
self.assertEqual(("/some,dir/path", ["tip"]),
577
split_segment_parameters_raw("/some,dir/path,tip"))
579
("/somedir/path", ["heads%2Ftip"]),
520
split_segment_parameters_raw("/some,dir/path,tip"))
521
self.assertEqual(("/somedir/path", ["heads%2Ftip"]),
580
522
split_segment_parameters_raw("/somedir/path,heads%2Ftip"))
582
("/somedir/path", ["heads%2Ftip", "bar"]),
523
self.assertEqual(("/somedir/path", ["heads%2Ftip", "bar"]),
583
524
split_segment_parameters_raw("/somedir/path,heads%2Ftip,bar"))
584
525
# Check relative references with relative paths
585
526
self.assertEqual(("", ["key1=val1"]),
586
split_segment_parameters_raw(",key1=val1"))
527
split_segment_parameters_raw(",key1=val1"))
587
528
self.assertEqual(("foo/", ["key1=val1"]),
588
split_segment_parameters_raw("foo/,key1=val1"))
529
split_segment_parameters_raw("foo/,key1=val1"))
589
530
self.assertEqual(("foo", ["key1=val1"]),
590
split_segment_parameters_raw("foo,key1=val1"))
592
("foo/base,la=bla/other/elements", []),
531
split_segment_parameters_raw("foo,key1=val1"))
532
self.assertEqual(("foo/base,la=bla/other/elements", []),
593
533
split_segment_parameters_raw("foo/base,la=bla/other/elements"))
595
("foo/base,la=bla/other/elements", ["a=b"]),
534
self.assertEqual(("foo/base,la=bla/other/elements", ["a=b"]),
596
535
split_segment_parameters_raw("foo/base,la=bla/other/elements,a=b"))
597
536
# TODO: Check full URLs as well as relative references
600
539
split_segment_parameters = urlutils.split_segment_parameters
601
540
# Check relative references with absolute paths
602
541
self.assertEqual(("/some/path", {}),
603
split_segment_parameters("/some/path"))
542
split_segment_parameters("/some/path"))
604
543
self.assertEqual(("/some/path", {"branch": "tip"}),
605
split_segment_parameters("/some/path,branch=tip"))
544
split_segment_parameters("/some/path,branch=tip"))
606
545
self.assertEqual(("/some,dir/path", {"branch": "tip"}),
607
split_segment_parameters("/some,dir/path,branch=tip"))
609
("/somedir/path", {"ref": "heads%2Ftip"}),
546
split_segment_parameters("/some,dir/path,branch=tip"))
547
self.assertEqual(("/somedir/path", {"ref": "heads%2Ftip"}),
610
548
split_segment_parameters("/somedir/path,ref=heads%2Ftip"))
611
549
self.assertEqual(("/somedir/path",
612
{"ref": "heads%2Ftip", "key1": "val1"}),
613
split_segment_parameters(
614
"/somedir/path,ref=heads%2Ftip,key1=val1"))
616
("/somedir/path", {"ref": "heads%2F=tip"}),
550
{"ref": "heads%2Ftip", "key1": "val1"}),
551
split_segment_parameters(
552
"/somedir/path,ref=heads%2Ftip,key1=val1"))
553
self.assertEqual(("/somedir/path", {"ref": "heads%2F=tip"}),
617
554
split_segment_parameters("/somedir/path,ref=heads%2F=tip"))
618
555
# Check relative references with relative paths
619
556
self.assertEqual(("", {"key1": "val1"}),
620
split_segment_parameters(",key1=val1"))
557
split_segment_parameters(",key1=val1"))
621
558
self.assertEqual(("foo/", {"key1": "val1"}),
622
split_segment_parameters("foo/,key1=val1"))
624
("foo/base,key1=val1/other/elements", {}),
559
split_segment_parameters("foo/,key1=val1"))
560
self.assertEqual(("foo/base,key1=val1/other/elements", {}),
625
561
split_segment_parameters("foo/base,key1=val1/other/elements"))
626
562
self.assertEqual(("foo/base,key1=val1/other/elements",
627
{"key2": "val2"}), split_segment_parameters(
628
"foo/base,key1=val1/other/elements,key2=val2"))
630
urlutils.InvalidURL, split_segment_parameters,
563
{"key2": "val2"}), split_segment_parameters(
564
"foo/base,key1=val1/other/elements,key2=val2"))
632
565
# TODO: Check full URLs as well as relative references
634
567
def test_win32_strip_local_trailing_slash(self):
748
676
test('a', 'http://host/', 'http://host/a')
749
677
test('http://entirely/different', 'sftp://host/branch',
750
'http://entirely/different')
678
'http://entirely/different')
751
679
test('../person/feature', 'http://host/branch/mainline',
752
'http://host/branch/person/feature')
680
'http://host/branch/person/feature')
753
681
test('..', 'http://host/branch', 'http://host/')
754
test('http://host2/branch', 'http://host1/branch',
755
'http://host2/branch')
682
test('http://host2/branch', 'http://host1/branch', 'http://host2/branch')
756
683
test('.', 'http://host1/branch', 'http://host1/branch')
757
684
test('../../../branch/2b', 'file:///home/jelmer/foo/bar/2b',
758
'file:///home/jelmer/branch/2b')
685
'file:///home/jelmer/branch/2b')
759
686
test('../../branch/2b', 'sftp://host/home/jelmer/bar/2b',
760
'sftp://host/home/jelmer/branch/2b')
687
'sftp://host/home/jelmer/branch/2b')
761
688
test('../../branch/feature/%2b', 'http://host/home/jelmer/bar/%2b',
762
'http://host/home/jelmer/branch/feature/%2b')
689
'http://host/home/jelmer/branch/feature/%2b')
763
690
test('../../branch/feature/2b', 'http://host/home/jelmer/bar/2b/',
764
'http://host/home/jelmer/branch/feature/2b')
691
'http://host/home/jelmer/branch/feature/2b')
765
692
# relative_url should preserve a trailing slash
766
693
test('../../branch/feature/2b/', 'http://host/home/jelmer/bar/2b/',
767
'http://host/home/jelmer/branch/feature/2b/')
694
'http://host/home/jelmer/branch/feature/2b/')
768
695
test('../../branch/feature/2b/', 'http://host/home/jelmer/bar/2b',
769
'http://host/home/jelmer/branch/feature/2b/')
696
'http://host/home/jelmer/branch/feature/2b/')
771
698
# TODO: treat http://host as http://host/
772
699
# relative_url is typically called from a branch.base or
773
700
# transport.base which always ends with a /
774
# test('a', 'http://host', 'http://host/a')
701
#test('a', 'http://host', 'http://host/a')
775
702
test('http://host/a', 'http://host', 'http://host/a')
776
# test('.', 'http://host', 'http://host/')
703
#test('.', 'http://host', 'http://host/')
777
704
test('http://host/', 'http://host', 'http://host/')
778
# test('.', 'http://host/', 'http://host')
705
#test('.', 'http://host/', 'http://host')
779
706
test('http://host', 'http://host/', 'http://host')
781
708
# On Windows file:///C:/path/to and file:///D:/other/path
783
710
if sys.platform == 'win32':
784
711
# on the same drive
785
712
test('../../other/path',
786
'file:///C:/path/to', 'file:///C:/other/path')
787
# ~next two tests is failed, i.e. urlutils.relative_url expects
788
# ~to see normalized file URLs?
789
# ~test('../../other/path',
790
# ~ 'file:///C:/path/to', 'file:///c:/other/path')
791
# ~test('../../other/path',
792
# ~ 'file:///C:/path/to', 'file:///C|/other/path')
713
'file:///C:/path/to', 'file:///C:/other/path')
714
#~next two tests is failed, i.e. urlutils.relative_url expects
715
#~to see normalized file URLs?
716
#~test('../../other/path',
717
#~ 'file:///C:/path/to', 'file:///c:/other/path')
718
#~test('../../other/path',
719
#~ 'file:///C:/path/to', 'file:///C|/other/path')
794
721
# check UNC paths too
795
722
test('../../other/path',
796
'file://HOST/base/path/to', 'file://HOST/base/other/path')
723
'file://HOST/base/path/to', 'file://HOST/base/other/path')
797
724
# on different drives
798
725
test('file:///D:/other/path',
799
'file:///C:/path/to', 'file:///D:/other/path')
726
'file:///C:/path/to', 'file:///D:/other/path')
800
727
# TODO: strictly saying in UNC path //HOST/base is full analog
801
728
# of drive letter for hard disk, and this situation is also
802
729
# should be exception from rules. [bialix 20071221]
879
806
def test_rebase_success(self):
880
807
self.assertEqual('../bar', urlutils.rebase_url('bar', 'http://baz/',
884
urlutils.rebase_url('bar', 'http://baz/qux', 'http://baz/'))
886
'.', urlutils.rebase_url('foo', 'http://bar/', 'http://bar/foo/'))
889
urlutils.rebase_url('../bar', 'http://baz/qux/foo', 'http://baz/'))
809
self.assertEqual('qux/bar', urlutils.rebase_url('bar',
810
'http://baz/qux', 'http://baz/'))
811
self.assertEqual('.', urlutils.rebase_url('foo',
812
'http://bar/', 'http://bar/foo/'))
813
self.assertEqual('qux/bar', urlutils.rebase_url('../bar',
814
'http://baz/qux/foo', 'http://baz/'))
891
816
def test_determine_relative_path(self):
892
817
self.assertEqual('../../baz/bar',
893
818
urlutils.determine_relative_path(
894
'/qux/quxx', '/baz/bar'))
819
'/qux/quxx', '/baz/bar'))
895
820
self.assertEqual('..',
896
821
urlutils.determine_relative_path(
898
823
self.assertEqual('baz',
899
824
urlutils.determine_relative_path(
901
826
self.assertEqual('.', urlutils.determine_relative_path(
1040
956
def test_same_url_posix(self):
1041
957
self._with_posix_paths()
1042
958
self.assertEqual("",
1043
urlutils.file_relpath("file:///a", "file:///a"))
1044
self.assertEqual("",
1045
urlutils.file_relpath("file:///a", "file:///a/"))
1046
self.assertEqual("",
1047
urlutils.file_relpath("file:///a/", "file:///a"))
959
urlutils.file_relpath("file:///a", "file:///a"))
961
urlutils.file_relpath("file:///a", "file:///a/"))
963
urlutils.file_relpath("file:///a/", "file:///a"))
1049
965
def test_same_url_win32(self):
1050
966
self._with_win32_paths()
1051
967
self.assertEqual("",
1052
urlutils.file_relpath("file:///A:/", "file:///A:/"))
1053
self.assertEqual("",
1054
urlutils.file_relpath("file:///A|/", "file:///A:/"))
1056
"", urlutils.file_relpath("file:///A:/b/", "file:///A:/b/"))
1058
"", urlutils.file_relpath("file:///A:/b", "file:///A:/b/"))
1060
"", urlutils.file_relpath("file:///A:/b/", "file:///A:/b"))
968
urlutils.file_relpath("file:///A:/", "file:///A:/"))
970
urlutils.file_relpath("file:///A|/", "file:///A:/"))
972
urlutils.file_relpath("file:///A:/b/", "file:///A:/b/"))
974
urlutils.file_relpath("file:///A:/b", "file:///A:/b/"))
976
urlutils.file_relpath("file:///A:/b/", "file:///A:/b"))
1062
978
def test_child_posix(self):
1063
979
self._with_posix_paths()
1065
"b", urlutils.file_relpath("file:///a", "file:///a/b"))
1067
"b", urlutils.file_relpath("file:///a/", "file:///a/b"))
1069
"b/c", urlutils.file_relpath("file:///a", "file:///a/b/c"))
980
self.assertEqual("b",
981
urlutils.file_relpath("file:///a", "file:///a/b"))
982
self.assertEqual("b",
983
urlutils.file_relpath("file:///a/", "file:///a/b"))
984
self.assertEqual("b/c",
985
urlutils.file_relpath("file:///a", "file:///a/b/c"))
1071
987
def test_child_win32(self):
1072
988
self._with_win32_paths()
1074
"b", urlutils.file_relpath("file:///A:/", "file:///A:/b"))
1076
"b", urlutils.file_relpath("file:///A|/", "file:///A:/b"))
1078
"c", urlutils.file_relpath("file:///A:/b", "file:///A:/b/c"))
1080
"c", urlutils.file_relpath("file:///A:/b/", "file:///A:/b/c"))
1082
"c/d", urlutils.file_relpath("file:///A:/b", "file:///A:/b/c/d"))
989
self.assertEqual("b",
990
urlutils.file_relpath("file:///A:/", "file:///A:/b"))
991
self.assertEqual("b",
992
urlutils.file_relpath("file:///A|/", "file:///A:/b"))
993
self.assertEqual("c",
994
urlutils.file_relpath("file:///A:/b", "file:///A:/b/c"))
995
self.assertEqual("c",
996
urlutils.file_relpath("file:///A:/b/", "file:///A:/b/c"))
997
self.assertEqual("c/d",
998
urlutils.file_relpath("file:///A:/b", "file:///A:/b/c/d"))
1084
1000
def test_sibling_posix(self):
1085
1001
self._with_posix_paths()
1002
self.assertRaises(PathNotChild,
1088
1003
urlutils.file_relpath, "file:///a/b", "file:///a/c")
1004
self.assertRaises(PathNotChild,
1091
1005
urlutils.file_relpath, "file:///a/b/", "file:///a/c")
1006
self.assertRaises(PathNotChild,
1094
1007
urlutils.file_relpath, "file:///a/b/", "file:///a/c/")
1096
1009
def test_sibling_win32(self):
1097
1010
self._with_win32_paths()
1011
self.assertRaises(PathNotChild,
1100
1012
urlutils.file_relpath, "file:///A:/b", "file:///A:/c")
1013
self.assertRaises(PathNotChild,
1103
1014
urlutils.file_relpath, "file:///A:/b/", "file:///A:/c")
1015
self.assertRaises(PathNotChild,
1106
1016
urlutils.file_relpath, "file:///A:/b/", "file:///A:/c/")
1108
1018
def test_parent_posix(self):
1109
1019
self._with_posix_paths()
1110
1020
self.assertRaises(PathNotChild,
1111
urlutils.file_relpath, "file:///a/b", "file:///a")
1021
urlutils.file_relpath, "file:///a/b", "file:///a")
1112
1022
self.assertRaises(PathNotChild,
1113
urlutils.file_relpath, "file:///a/b", "file:///a/")
1023
urlutils.file_relpath, "file:///a/b", "file:///a/")
1115
1025
def test_parent_win32(self):
1116
1026
self._with_win32_paths()
1027
self.assertRaises(PathNotChild,
1119
1028
urlutils.file_relpath, "file:///A:/b", "file:///A:/")
1029
self.assertRaises(PathNotChild,
1122
1030
urlutils.file_relpath, "file:///A:/b/c", "file:///A:/b")