49
49
self.assertEqual('foo', basename('http://host/path/to/foo'))
50
50
self.assertEqual('foo', basename('http://host/path/to/foo/'))
52
basename('http://host/path/to/foo/', exclude_trailing_slash=False))
52
'', basename('http://host/path/to/foo/',
53
exclude_trailing_slash=False))
53
54
self.assertEqual('path', basename('http://host/path'))
54
55
self.assertEqual('', basename('http://host/'))
55
56
self.assertEqual('', basename('http://host'))
56
57
self.assertEqual('path', basename('http:///nohost/path'))
58
self.assertEqual('path', basename('random+scheme://user:pass@ahost:port/path'))
59
self.assertEqual('path', basename('random+scheme://user:pass@ahost:port/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/'))
60
63
self.assertEqual('', basename('random+scheme://user:pass@ahost:port/'))
63
66
self.assertEqual('foo', basename('path/to/foo'))
64
67
self.assertEqual('foo', basename('path/to/foo/'))
65
68
self.assertEqual('', basename('path/to/foo/',
66
exclude_trailing_slash=False))
69
exclude_trailing_slash=False))
67
70
self.assertEqual('foo', basename('path/../foo'))
68
71
self.assertEqual('foo', basename('../path/foo'))
175
180
dirname = urlutils.dirname
176
181
if sys.platform == 'win32':
177
182
self.assertRaises(urlutils.InvalidURL, dirname,
178
'file:///path/to/foo')
183
'file:///path/to/foo')
179
184
self.assertEqual('file:///C|/', dirname('file:///C|/foo'))
180
185
self.assertEqual('file:///C|/', dirname('file:///C|/'))
182
187
self.assertEqual('file:///', dirname('file:///foo'))
183
188
self.assertEqual('file:///', dirname('file:///'))
185
self.assertEqual('http://host/path/to', dirname('http://host/path/to/foo'))
186
self.assertEqual('http://host/path/to', dirname('http://host/path/to/foo/'))
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/'))
187
194
self.assertEqual('http://host/path/to/foo',
188
dirname('http://host/path/to/foo/', exclude_trailing_slash=False))
195
dirname('http://host/path/to/foo/',
196
exclude_trailing_slash=False))
189
197
self.assertEqual('http://host/', dirname('http://host/path'))
190
198
self.assertEqual('http://host/', dirname('http://host/'))
191
199
self.assertEqual('http://host', dirname('http://host'))
192
200
self.assertEqual('http:///nohost', dirname('http:///nohost/path'))
194
202
self.assertEqual('random+scheme://user:pass@ahost:port/',
195
dirname('random+scheme://user:pass@ahost:port/path'))
196
self.assertEqual('random+scheme://user:pass@ahost:port/',
197
dirname('random+scheme://user:pass@ahost:port/path/'))
198
self.assertEqual('random+scheme://user:pass@ahost:port/',
199
dirname('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/'))
202
210
self.assertEqual('path/to', dirname('path/to/foo'))
203
211
self.assertEqual('path/to', dirname('path/to/foo/'))
204
212
self.assertEqual('path/to/foo',
205
dirname('path/to/foo/', exclude_trailing_slash=False))
213
dirname('path/to/foo/', exclude_trailing_slash=False))
206
214
self.assertEqual('path/..', dirname('path/../foo'))
207
215
self.assertEqual('../path', dirname('../path/foo'))
209
217
def test_is_url(self):
210
218
self.assertTrue(urlutils.is_url('http://foo/bar'))
211
219
self.assertTrue(urlutils.is_url('bzr+ssh://foo/bar'))
296
304
# Invalid joinings
297
305
# Cannot go above root
298
306
self.assertRaises(urlutils.InvalidURLJoin, urlutils.joinpath, '/',
300
self.assertRaises(urlutils.InvalidURLJoin, urlutils.joinpath, '/',
302
self.assertRaises(urlutils.InvalidURLJoin, urlutils.joinpath, '/',
308
self.assertRaises(urlutils.InvalidURLJoin, urlutils.joinpath, '/',
310
self.assertRaises(urlutils.InvalidURLJoin, urlutils.joinpath, '/',
305
313
def test_join_segment_parameters_raw(self):
306
314
join_segment_parameters_raw = urlutils.join_segment_parameters_raw
307
self.assertEqual("/somedir/path",
308
join_segment_parameters_raw("/somedir/path"))
309
self.assertEqual("/somedir/path,rawdata",
310
join_segment_parameters_raw("/somedir/path", "rawdata"))
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"))
311
320
self.assertRaises(urlutils.InvalidURLJoin,
312
join_segment_parameters_raw, "/somedir/path",
313
"rawdata1,rawdata2,rawdata3")
321
join_segment_parameters_raw, "/somedir/path",
322
"rawdata1,rawdata2,rawdata3")
314
323
self.assertEqual("/somedir/path,bla,bar",
315
join_segment_parameters_raw("/somedir/path", "bla", "bar"))
316
self.assertEqual("/somedir,exist=some/path,bla,bar",
324
join_segment_parameters_raw(
325
"/somedir/path", "bla", "bar"))
327
"/somedir,exist=some/path,bla,bar",
317
328
join_segment_parameters_raw("/somedir,exist=some/path",
319
self.assertRaises(TypeError, join_segment_parameters_raw,
330
self.assertRaises(TypeError, join_segment_parameters_raw,
322
333
def test_join_segment_parameters(self):
323
334
join_segment_parameters = urlutils.join_segment_parameters
324
self.assertEqual("/somedir/path",
325
join_segment_parameters("/somedir/path", {}))
326
self.assertEqual("/somedir/path,key1=val1",
335
self.assertEqual("/somedir/path",
336
join_segment_parameters("/somedir/path", {}))
338
"/somedir/path,key1=val1",
327
339
join_segment_parameters("/somedir/path", {"key1": "val1"}))
328
340
self.assertRaises(urlutils.InvalidURLJoin,
329
join_segment_parameters, "/somedir/path",
330
{"branch": "brr,brr,brr"})
331
self.assertRaises(urlutils.InvalidURLJoin,
341
join_segment_parameters, "/somedir/path",
342
{"branch": "brr,brr,brr"})
344
urlutils.InvalidURLJoin,
332
345
join_segment_parameters, "/somedir/path", {"key1=val1": "val2"})
333
346
self.assertEqual("/somedir/path,key1=val1,key2=val2",
334
join_segment_parameters("/somedir/path", {
335
"key1": "val1", "key2": "val2"}))
347
join_segment_parameters("/somedir/path", {
348
"key1": "val1", "key2": "val2"}))
336
349
self.assertEqual("/somedir/path,key1=val1,key2=val2",
337
join_segment_parameters("/somedir/path,key1=val1", {
350
join_segment_parameters("/somedir/path,key1=val1", {
339
352
self.assertEqual("/somedir/path,key1=val2",
340
join_segment_parameters("/somedir/path,key1=val1", {
353
join_segment_parameters("/somedir/path,key1=val1", {
342
355
self.assertEqual("/somedir,exist=some/path,key1=val1",
343
join_segment_parameters("/somedir,exist=some/path",
345
self.assertEqual("/,key1=val1,key2=val2",
356
join_segment_parameters("/somedir,exist=some/path",
359
"/,key1=val1,key2=val2",
346
360
join_segment_parameters("/,key1=val1", {"key2": "val2"}))
347
361
self.assertRaises(TypeError,
348
join_segment_parameters, "/,key1=val1", {"foo": 42})
362
join_segment_parameters, "/,key1=val1", {"foo": 42})
350
364
def test_function_type(self):
351
365
if sys.platform == 'win32':
352
366
self.assertEqual(urlutils._win32_local_path_to_url,
353
urlutils.local_path_to_url)
367
urlutils.local_path_to_url)
354
368
self.assertEqual(urlutils._win32_local_path_from_url,
355
urlutils.local_path_from_url)
369
urlutils.local_path_from_url)
357
371
self.assertEqual(urlutils._posix_local_path_to_url,
358
urlutils.local_path_to_url)
372
urlutils.local_path_to_url)
359
373
self.assertEqual(urlutils._posix_local_path_from_url,
360
urlutils.local_path_from_url)
374
urlutils.local_path_from_url)
362
376
def test_posix_local_path_to_url(self):
363
377
to_url = urlutils._posix_local_path_to_url
364
378
self.assertEqual('file:///path/to/foo',
365
to_url('/path/to/foo'))
379
to_url('/path/to/foo'))
367
381
self.assertEqual('file:///path/to/foo%2Cbar',
368
to_url('/path/to/foo,bar'))
382
to_url('/path/to/foo,bar'))
371
385
result = to_url(u'/path/to/r\xe4ksm\xf6rg\xe5s')
378
392
def test_posix_local_path_from_url(self):
379
393
from_url = urlutils._posix_local_path_from_url
380
394
self.assertEqual('/path/to/foo',
381
from_url('file:///path/to/foo'))
395
from_url('file:///path/to/foo'))
382
396
self.assertEqual('/path/to/foo',
383
from_url('file:///path/to/foo,branch=foo'))
384
self.assertEqual(u'/path/to/r\xe4ksm\xf6rg\xe5s',
385
from_url('file:///path/to/r%C3%A4ksm%C3%B6rg%C3%A5s'))
386
self.assertEqual(u'/path/to/r\xe4ksm\xf6rg\xe5s',
387
from_url('file:///path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))
388
self.assertEqual(u'/path/to/r\xe4ksm\xf6rg\xe5s',
397
from_url('file:///path/to/foo,branch=foo'))
398
self.assertEqual(u'/path/to/r\xe4ksm\xf6rg\xe5s',
399
from_url('file:///path/to/r%C3%A4ksm%C3%B6rg%C3%A5s'))
400
self.assertEqual(u'/path/to/r\xe4ksm\xf6rg\xe5s',
401
from_url('file:///path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))
403
u'/path/to/r\xe4ksm\xf6rg\xe5s',
389
404
from_url('file://localhost/path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))
391
406
self.assertRaises(urlutils.InvalidURL, from_url, '/path/to/foo')
404
419
# self.assertEqual('file:///C:/path/to/foo%20',
405
420
# to_url('C:/path/to/foo '))
406
421
self.assertEqual('file:///C:/path/to/f%20oo',
407
to_url('C:/path/to/f oo'))
422
to_url('C:/path/to/f oo'))
409
424
self.assertEqual('file:///', to_url('/'))
411
426
self.assertEqual('file:///C:/path/to/foo%2Cbar',
412
to_url('C:/path/to/foo,bar'))
427
to_url('C:/path/to/foo,bar'))
414
429
result = to_url(u'd:/path/to/r\xe4ksm\xf6rg\xe5s')
415
430
except UnicodeError:
416
431
raise TestSkipped("local encoding cannot handle unicode")
418
self.assertEqual('file:///D:/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
434
'file:///D:/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
419
435
self.assertIsInstance(result, str)
421
437
def test_win32_unc_path_to_url(self):
422
438
self.requireFeature(features.win32_feature)
423
439
to_url = urlutils._win32_local_path_to_url
424
440
self.assertEqual('file://HOST/path',
425
to_url(r'\\HOST\path'))
441
to_url(r'\\HOST\path'))
426
442
self.assertEqual('file://HOST/path',
427
to_url('//HOST/path'))
443
to_url('//HOST/path'))
430
446
result = to_url(u'//HOST/path/to/r\xe4ksm\xf6rg\xe5s')
431
447
except UnicodeError:
432
448
raise TestSkipped("local encoding cannot handle unicode")
434
self.assertEqual('file://HOST/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
451
'file://HOST/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
435
452
self.assertFalse(isinstance(result, text_type))
437
454
def test_win32_local_path_from_url(self):
438
455
from_url = urlutils._win32_local_path_from_url
439
456
self.assertEqual('C:/path/to/foo',
440
from_url('file:///C|/path/to/foo'))
441
self.assertEqual(u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
457
from_url('file:///C|/path/to/foo'))
459
u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
442
460
from_url('file:///d|/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s'))
443
self.assertEqual(u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
462
u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
444
463
from_url('file:///d:/path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))
445
464
self.assertEqual('/', from_url('file:///'))
446
465
self.assertEqual('C:/path/to/foo',
447
from_url('file:///C|/path/to/foo,branch=foo'))
466
from_url('file:///C|/path/to/foo,branch=foo'))
449
468
self.assertRaises(urlutils.InvalidURL, from_url, 'file:///C:')
450
469
self.assertRaises(urlutils.InvalidURL, from_url, 'file:///c')
456
475
from_url = urlutils._win32_local_path_from_url
457
476
self.assertEqual('//HOST/path', from_url('file://HOST/path'))
458
477
self.assertEqual('//HOST/path',
459
from_url('file://HOST/path,branch=foo'))
478
from_url('file://HOST/path,branch=foo'))
460
479
# despite IE allows 2, 4, 5 and 6 slashes in URL to another machine
461
480
# we want to use only 2 slashes
462
481
# Firefox understand only 5 slashes in URL, but it's ugly
463
482
self.assertRaises(urlutils.InvalidURL, from_url, 'file:////HOST/path')
464
483
self.assertRaises(urlutils.InvalidURL, from_url, 'file://///HOST/path')
465
self.assertRaises(urlutils.InvalidURL, from_url, 'file://////HOST/path')
484
self.assertRaises(urlutils.InvalidURL, from_url,
485
'file://////HOST/path')
466
486
# check for file://C:/ instead of file:///C:/
467
487
self.assertRaises(urlutils.InvalidURL, from_url, 'file://C:/path')
469
489
def test_win32_extract_drive_letter(self):
470
490
extract = urlutils._win32_extract_drive_letter
471
491
self.assertEqual(('file:///C:', '/foo'), extract('file://', '/C:/foo'))
472
self.assertEqual(('file:///d|', '/path'), extract('file://', '/d|/path'))
492
self.assertEqual(('file:///d|', '/path'),
493
extract('file://', '/d|/path'))
473
494
self.assertRaises(urlutils.InvalidURL, extract, 'file://', '/path')
474
495
# Root drives without slash treated as invalid, see bug #841322
475
496
self.assertEqual(('file:///C:', '/'), extract('file://', '/C:/'))
482
503
# Test breezy.urlutils.split()
483
504
split = urlutils.split
484
505
if sys.platform == 'win32':
485
self.assertRaises(urlutils.InvalidURL, split, 'file:///path/to/foo')
506
self.assertRaises(urlutils.InvalidURL, split,
507
'file:///path/to/foo')
486
508
self.assertEqual(('file:///C|/', 'foo'), split('file:///C|/foo'))
487
509
self.assertEqual(('file:///C:/', ''), split('file:///C:/'))
489
511
self.assertEqual(('file:///', 'foo'), split('file:///foo'))
490
512
self.assertEqual(('file:///', ''), split('file:///'))
492
self.assertEqual(('http://host/path/to', 'foo'), split('http://host/path/to/foo'))
493
self.assertEqual(('http://host/path/to', 'foo'), split('http://host/path/to/foo/'))
494
self.assertEqual(('http://host/path/to/foo', ''),
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', ''),
495
520
split('http://host/path/to/foo/', exclude_trailing_slash=False))
496
521
self.assertEqual(('http://host/', 'path'), split('http://host/path'))
497
522
self.assertEqual(('http://host/', ''), split('http://host/'))
498
523
self.assertEqual(('http://host', ''), split('http://host'))
499
self.assertEqual(('http:///nohost', 'path'), split('http:///nohost/path'))
524
self.assertEqual(('http:///nohost', 'path'),
525
split('http:///nohost/path'))
501
527
self.assertEqual(('random+scheme://user:pass@ahost:port/', 'path'),
502
split('random+scheme://user:pass@ahost:port/path'))
528
split('random+scheme://user:pass@ahost:port/path'))
503
529
self.assertEqual(('random+scheme://user:pass@ahost:port/', 'path'),
504
split('random+scheme://user:pass@ahost:port/path/'))
530
split('random+scheme://user:pass@ahost:port/path/'))
505
531
self.assertEqual(('random+scheme://user:pass@ahost:port/', ''),
506
split('random+scheme://user:pass@ahost:port/'))
532
split('random+scheme://user:pass@ahost:port/'))
509
535
self.assertEqual(('path/to', 'foo'), split('path/to/foo'))
510
536
self.assertEqual(('path/to', 'foo'), split('path/to/foo/'))
511
537
self.assertEqual(('path/to/foo', ''),
512
split('path/to/foo/', exclude_trailing_slash=False))
538
split('path/to/foo/', exclude_trailing_slash=False))
513
539
self.assertEqual(('path/..', 'foo'), split('path/../foo'))
514
540
self.assertEqual(('../path', 'foo'), split('../path/foo'))
517
543
split_segment_parameters_raw = urlutils.split_segment_parameters_raw
518
544
# Check relative references with absolute paths
519
545
self.assertEqual(("/some/path", []),
520
split_segment_parameters_raw("/some/path"))
546
split_segment_parameters_raw("/some/path"))
521
547
self.assertEqual(("/some/path", ["tip"]),
522
split_segment_parameters_raw("/some/path,tip"))
548
split_segment_parameters_raw("/some/path,tip"))
523
549
self.assertEqual(("/some,dir/path", ["tip"]),
524
split_segment_parameters_raw("/some,dir/path,tip"))
525
self.assertEqual(("/somedir/path", ["heads%2Ftip"]),
550
split_segment_parameters_raw("/some,dir/path,tip"))
552
("/somedir/path", ["heads%2Ftip"]),
526
553
split_segment_parameters_raw("/somedir/path,heads%2Ftip"))
527
self.assertEqual(("/somedir/path", ["heads%2Ftip", "bar"]),
555
("/somedir/path", ["heads%2Ftip", "bar"]),
528
556
split_segment_parameters_raw("/somedir/path,heads%2Ftip,bar"))
529
557
# Check relative references with relative paths
530
558
self.assertEqual(("", ["key1=val1"]),
531
split_segment_parameters_raw(",key1=val1"))
559
split_segment_parameters_raw(",key1=val1"))
532
560
self.assertEqual(("foo/", ["key1=val1"]),
533
split_segment_parameters_raw("foo/,key1=val1"))
561
split_segment_parameters_raw("foo/,key1=val1"))
534
562
self.assertEqual(("foo", ["key1=val1"]),
535
split_segment_parameters_raw("foo,key1=val1"))
536
self.assertEqual(("foo/base,la=bla/other/elements", []),
563
split_segment_parameters_raw("foo,key1=val1"))
565
("foo/base,la=bla/other/elements", []),
537
566
split_segment_parameters_raw("foo/base,la=bla/other/elements"))
538
self.assertEqual(("foo/base,la=bla/other/elements", ["a=b"]),
568
("foo/base,la=bla/other/elements", ["a=b"]),
539
569
split_segment_parameters_raw("foo/base,la=bla/other/elements,a=b"))
540
570
# TODO: Check full URLs as well as relative references
543
573
split_segment_parameters = urlutils.split_segment_parameters
544
574
# Check relative references with absolute paths
545
575
self.assertEqual(("/some/path", {}),
546
split_segment_parameters("/some/path"))
576
split_segment_parameters("/some/path"))
547
577
self.assertEqual(("/some/path", {"branch": "tip"}),
548
split_segment_parameters("/some/path,branch=tip"))
578
split_segment_parameters("/some/path,branch=tip"))
549
579
self.assertEqual(("/some,dir/path", {"branch": "tip"}),
550
split_segment_parameters("/some,dir/path,branch=tip"))
551
self.assertEqual(("/somedir/path", {"ref": "heads%2Ftip"}),
580
split_segment_parameters("/some,dir/path,branch=tip"))
582
("/somedir/path", {"ref": "heads%2Ftip"}),
552
583
split_segment_parameters("/somedir/path,ref=heads%2Ftip"))
553
584
self.assertEqual(("/somedir/path",
554
{"ref": "heads%2Ftip", "key1": "val1"}),
555
split_segment_parameters(
556
"/somedir/path,ref=heads%2Ftip,key1=val1"))
557
self.assertEqual(("/somedir/path", {"ref": "heads%2F=tip"}),
585
{"ref": "heads%2Ftip", "key1": "val1"}),
586
split_segment_parameters(
587
"/somedir/path,ref=heads%2Ftip,key1=val1"))
589
("/somedir/path", {"ref": "heads%2F=tip"}),
558
590
split_segment_parameters("/somedir/path,ref=heads%2F=tip"))
559
591
# Check relative references with relative paths
560
592
self.assertEqual(("", {"key1": "val1"}),
561
split_segment_parameters(",key1=val1"))
593
split_segment_parameters(",key1=val1"))
562
594
self.assertEqual(("foo/", {"key1": "val1"}),
563
split_segment_parameters("foo/,key1=val1"))
564
self.assertEqual(("foo/base,key1=val1/other/elements", {}),
595
split_segment_parameters("foo/,key1=val1"))
597
("foo/base,key1=val1/other/elements", {}),
565
598
split_segment_parameters("foo/base,key1=val1/other/elements"))
566
599
self.assertEqual(("foo/base,key1=val1/other/elements",
567
{"key2": "val2"}), split_segment_parameters(
568
"foo/base,key1=val1/other/elements,key2=val2"))
600
{"key2": "val2"}), split_segment_parameters(
601
"foo/base,key1=val1/other/elements,key2=val2"))
569
602
# TODO: Check full URLs as well as relative references
571
604
def test_win32_strip_local_trailing_slash(self):
684
718
test('a', 'http://host/', 'http://host/a')
685
719
test('http://entirely/different', 'sftp://host/branch',
686
'http://entirely/different')
720
'http://entirely/different')
687
721
test('../person/feature', 'http://host/branch/mainline',
688
'http://host/branch/person/feature')
722
'http://host/branch/person/feature')
689
723
test('..', 'http://host/branch', 'http://host/')
690
test('http://host2/branch', 'http://host1/branch', 'http://host2/branch')
724
test('http://host2/branch', 'http://host1/branch',
725
'http://host2/branch')
691
726
test('.', 'http://host1/branch', 'http://host1/branch')
692
727
test('../../../branch/2b', 'file:///home/jelmer/foo/bar/2b',
693
'file:///home/jelmer/branch/2b')
728
'file:///home/jelmer/branch/2b')
694
729
test('../../branch/2b', 'sftp://host/home/jelmer/bar/2b',
695
'sftp://host/home/jelmer/branch/2b')
730
'sftp://host/home/jelmer/branch/2b')
696
731
test('../../branch/feature/%2b', 'http://host/home/jelmer/bar/%2b',
697
'http://host/home/jelmer/branch/feature/%2b')
732
'http://host/home/jelmer/branch/feature/%2b')
698
733
test('../../branch/feature/2b', 'http://host/home/jelmer/bar/2b/',
699
'http://host/home/jelmer/branch/feature/2b')
734
'http://host/home/jelmer/branch/feature/2b')
700
735
# relative_url should preserve a trailing slash
701
736
test('../../branch/feature/2b/', 'http://host/home/jelmer/bar/2b/',
702
'http://host/home/jelmer/branch/feature/2b/')
737
'http://host/home/jelmer/branch/feature/2b/')
703
738
test('../../branch/feature/2b/', 'http://host/home/jelmer/bar/2b',
704
'http://host/home/jelmer/branch/feature/2b/')
739
'http://host/home/jelmer/branch/feature/2b/')
706
741
# TODO: treat http://host as http://host/
707
742
# relative_url is typically called from a branch.base or
708
743
# transport.base which always ends with a /
709
#test('a', 'http://host', 'http://host/a')
744
# test('a', 'http://host', 'http://host/a')
710
745
test('http://host/a', 'http://host', 'http://host/a')
711
#test('.', 'http://host', 'http://host/')
746
# test('.', 'http://host', 'http://host/')
712
747
test('http://host/', 'http://host', 'http://host/')
713
#test('.', 'http://host/', 'http://host')
748
# test('.', 'http://host/', 'http://host')
714
749
test('http://host', 'http://host/', 'http://host')
716
751
# On Windows file:///C:/path/to and file:///D:/other/path
718
753
if sys.platform == 'win32':
719
754
# on the same drive
720
755
test('../../other/path',
721
'file:///C:/path/to', 'file:///C:/other/path')
722
#~next two tests is failed, i.e. urlutils.relative_url expects
723
#~to see normalized file URLs?
724
#~test('../../other/path',
725
#~ 'file:///C:/path/to', 'file:///c:/other/path')
726
#~test('../../other/path',
727
#~ 'file:///C:/path/to', 'file:///C|/other/path')
756
'file:///C:/path/to', 'file:///C:/other/path')
757
# ~next two tests is failed, i.e. urlutils.relative_url expects
758
# ~to see normalized file URLs?
759
# ~test('../../other/path',
760
# ~ 'file:///C:/path/to', 'file:///c:/other/path')
761
# ~test('../../other/path',
762
# ~ 'file:///C:/path/to', 'file:///C|/other/path')
729
764
# check UNC paths too
730
765
test('../../other/path',
731
'file://HOST/base/path/to', 'file://HOST/base/other/path')
766
'file://HOST/base/path/to', 'file://HOST/base/other/path')
732
767
# on different drives
733
768
test('file:///D:/other/path',
734
'file:///C:/path/to', 'file:///D:/other/path')
769
'file:///C:/path/to', 'file:///D:/other/path')
735
770
# TODO: strictly saying in UNC path //HOST/base is full analog
736
771
# of drive letter for hard disk, and this situation is also
737
772
# should be exception from rules. [bialix 20071221]
814
849
def test_rebase_success(self):
815
850
self.assertEqual('../bar', urlutils.rebase_url('bar', 'http://baz/',
817
self.assertEqual('qux/bar', urlutils.rebase_url('bar',
818
'http://baz/qux', 'http://baz/'))
819
self.assertEqual('.', urlutils.rebase_url('foo',
820
'http://bar/', 'http://bar/foo/'))
821
self.assertEqual('qux/bar', urlutils.rebase_url('../bar',
822
'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/'))
824
861
def test_determine_relative_path(self):
825
862
self.assertEqual('../../baz/bar',
826
863
urlutils.determine_relative_path(
827
'/qux/quxx', '/baz/bar'))
864
'/qux/quxx', '/baz/bar'))
828
865
self.assertEqual('..',
829
866
urlutils.determine_relative_path(
831
868
self.assertEqual('baz',
832
869
urlutils.determine_relative_path(
834
871
self.assertEqual('.', urlutils.determine_relative_path(
973
1010
def test_same_url_posix(self):
974
1011
self._with_posix_paths()
975
1012
self.assertEqual("",
976
urlutils.file_relpath("file:///a", "file:///a"))
978
urlutils.file_relpath("file:///a", "file:///a/"))
980
urlutils.file_relpath("file:///a/", "file:///a"))
1013
urlutils.file_relpath("file:///a", "file:///a"))
1014
self.assertEqual("",
1015
urlutils.file_relpath("file:///a", "file:///a/"))
1016
self.assertEqual("",
1017
urlutils.file_relpath("file:///a/", "file:///a"))
982
1019
def test_same_url_win32(self):
983
1020
self._with_win32_paths()
984
1021
self.assertEqual("",
985
urlutils.file_relpath("file:///A:/", "file:///A:/"))
987
urlutils.file_relpath("file:///A|/", "file:///A:/"))
989
urlutils.file_relpath("file:///A:/b/", "file:///A:/b/"))
991
urlutils.file_relpath("file:///A:/b", "file:///A:/b/"))
993
urlutils.file_relpath("file:///A:/b/", "file:///A:/b"))
1022
urlutils.file_relpath("file:///A:/", "file:///A:/"))
1023
self.assertEqual("",
1024
urlutils.file_relpath("file:///A|/", "file:///A:/"))
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"))
995
1032
def test_child_posix(self):
996
1033
self._with_posix_paths()
997
self.assertEqual("b",
998
urlutils.file_relpath("file:///a", "file:///a/b"))
999
self.assertEqual("b",
1000
urlutils.file_relpath("file:///a/", "file:///a/b"))
1001
self.assertEqual("b/c",
1002
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"))
1004
1041
def test_child_win32(self):
1005
1042
self._with_win32_paths()
1006
self.assertEqual("b",
1007
urlutils.file_relpath("file:///A:/", "file:///A:/b"))
1008
self.assertEqual("b",
1009
urlutils.file_relpath("file:///A|/", "file:///A:/b"))
1010
self.assertEqual("c",
1011
urlutils.file_relpath("file:///A:/b", "file:///A:/b/c"))
1012
self.assertEqual("c",
1013
urlutils.file_relpath("file:///A:/b/", "file:///A:/b/c"))
1014
self.assertEqual("c/d",
1015
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"))
1017
1054
def test_sibling_posix(self):
1018
1055
self._with_posix_paths()
1019
self.assertRaises(PathNotChild,
1020
1058
urlutils.file_relpath, "file:///a/b", "file:///a/c")
1021
self.assertRaises(PathNotChild,
1022
1061
urlutils.file_relpath, "file:///a/b/", "file:///a/c")
1023
self.assertRaises(PathNotChild,
1024
1064
urlutils.file_relpath, "file:///a/b/", "file:///a/c/")
1026
1066
def test_sibling_win32(self):
1027
1067
self._with_win32_paths()
1028
self.assertRaises(PathNotChild,
1029
1070
urlutils.file_relpath, "file:///A:/b", "file:///A:/c")
1030
self.assertRaises(PathNotChild,
1031
1073
urlutils.file_relpath, "file:///A:/b/", "file:///A:/c")
1032
self.assertRaises(PathNotChild,
1033
1076
urlutils.file_relpath, "file:///A:/b/", "file:///A:/c/")
1035
1078
def test_parent_posix(self):
1036
1079
self._with_posix_paths()
1037
1080
self.assertRaises(PathNotChild,
1038
urlutils.file_relpath, "file:///a/b", "file:///a")
1081
urlutils.file_relpath, "file:///a/b", "file:///a")
1039
1082
self.assertRaises(PathNotChild,
1040
urlutils.file_relpath, "file:///a/b", "file:///a/")
1083
urlutils.file_relpath, "file:///a/b", "file:///a/")
1042
1085
def test_parent_win32(self):
1043
1086
self._with_win32_paths()
1044
self.assertRaises(PathNotChild,
1045
1089
urlutils.file_relpath, "file:///A:/b", "file:///A:/")
1046
self.assertRaises(PathNotChild,
1047
1092
urlutils.file_relpath, "file:///A:/b/c", "file:///A:/b")