291
292
# Invalid joinings
292
293
# Cannot go above root
293
self.assertRaises(InvalidURLJoin, urlutils.joinpath, '/', '../baz')
294
self.assertRaises(InvalidURLJoin, urlutils.joinpath, '/', '..')
295
self.assertRaises(InvalidURLJoin, urlutils.joinpath, '/', '/..')
294
self.assertRaises(urlutils.InvalidURLJoin, urlutils.joinpath, '/',
296
self.assertRaises(urlutils.InvalidURLJoin, urlutils.joinpath, '/',
298
self.assertRaises(urlutils.InvalidURLJoin, urlutils.joinpath, '/',
297
301
def test_join_segment_parameters_raw(self):
298
302
join_segment_parameters_raw = urlutils.join_segment_parameters_raw
299
self.assertEquals("/somedir/path",
300
join_segment_parameters_raw("/somedir/path"))
301
self.assertEquals("/somedir/path,rawdata",
302
join_segment_parameters_raw("/somedir/path", "rawdata"))
303
self.assertRaises(InvalidURLJoin,
304
join_segment_parameters_raw, "/somedir/path",
305
"rawdata1,rawdata2,rawdata3")
306
self.assertEquals("/somedir/path,bla,bar",
307
join_segment_parameters_raw("/somedir/path", "bla", "bar"))
308
self.assertEquals("/somedir,exist=some/path,bla,bar",
303
self.assertEqual("/somedir/path",
304
join_segment_parameters_raw("/somedir/path"))
305
self.assertEqual("/somedir/path,rawdata",
306
join_segment_parameters_raw(
307
"/somedir/path", "rawdata"))
308
self.assertRaises(urlutils.InvalidURLJoin,
309
join_segment_parameters_raw, "/somedir/path",
310
"rawdata1,rawdata2,rawdata3")
311
self.assertEqual("/somedir/path,bla,bar",
312
join_segment_parameters_raw(
313
"/somedir/path", "bla", "bar"))
315
"/somedir,exist=some/path,bla,bar",
309
316
join_segment_parameters_raw("/somedir,exist=some/path",
311
self.assertRaises(TypeError, join_segment_parameters_raw,
318
self.assertRaises(TypeError, join_segment_parameters_raw,
314
321
def test_join_segment_parameters(self):
315
322
join_segment_parameters = urlutils.join_segment_parameters
316
self.assertEquals("/somedir/path",
317
join_segment_parameters("/somedir/path", {}))
318
self.assertEquals("/somedir/path,key1=val1",
323
self.assertEqual("/somedir/path",
324
join_segment_parameters("/somedir/path", {}))
326
"/somedir/path,key1=val1",
319
327
join_segment_parameters("/somedir/path", {"key1": "val1"}))
320
self.assertRaises(InvalidURLJoin,
321
join_segment_parameters, "/somedir/path",
322
{"branch": "brr,brr,brr"})
323
self.assertRaises(InvalidURLJoin,
328
self.assertRaises(urlutils.InvalidURLJoin,
329
join_segment_parameters, "/somedir/path",
330
{"branch": "brr,brr,brr"})
332
urlutils.InvalidURLJoin,
324
333
join_segment_parameters, "/somedir/path", {"key1=val1": "val2"})
325
self.assertEquals("/somedir/path,key1=val1,key2=val2",
326
join_segment_parameters("/somedir/path", {
327
"key1": "val1", "key2": "val2"}))
328
self.assertEquals("/somedir/path,key1=val1,key2=val2",
329
join_segment_parameters("/somedir/path,key1=val1", {
331
self.assertEquals("/somedir/path,key1=val2",
332
join_segment_parameters("/somedir/path,key1=val1", {
334
self.assertEquals("/somedir,exist=some/path,key1=val1",
335
join_segment_parameters("/somedir,exist=some/path",
337
self.assertEquals("/,key1=val1,key2=val2",
334
self.assertEqual("/somedir/path,key1=val1,key2=val2",
335
join_segment_parameters("/somedir/path", {
336
"key1": "val1", "key2": "val2"}))
337
self.assertEqual("/somedir/path,key1=val1,key2=val2",
338
join_segment_parameters("/somedir/path,key1=val1", {
340
self.assertEqual("/somedir/path,key1=val2",
341
join_segment_parameters("/somedir/path,key1=val1", {
343
self.assertEqual("/somedir,exist=some/path,key1=val1",
344
join_segment_parameters("/somedir,exist=some/path",
347
"/,key1=val1,key2=val2",
338
348
join_segment_parameters("/,key1=val1", {"key2": "val2"}))
339
349
self.assertRaises(TypeError,
340
join_segment_parameters, "/,key1=val1", {"foo": 42})
350
join_segment_parameters, "/,key1=val1", {"foo": 42})
342
352
def test_function_type(self):
343
353
if sys.platform == 'win32':
344
354
self.assertEqual(urlutils._win32_local_path_to_url,
345
urlutils.local_path_to_url)
355
urlutils.local_path_to_url)
346
356
self.assertEqual(urlutils._win32_local_path_from_url,
347
urlutils.local_path_from_url)
357
urlutils.local_path_from_url)
349
359
self.assertEqual(urlutils._posix_local_path_to_url,
350
urlutils.local_path_to_url)
360
urlutils.local_path_to_url)
351
361
self.assertEqual(urlutils._posix_local_path_from_url,
352
urlutils.local_path_from_url)
362
urlutils.local_path_from_url)
354
364
def test_posix_local_path_to_url(self):
355
365
to_url = urlutils._posix_local_path_to_url
356
366
self.assertEqual('file:///path/to/foo',
357
to_url('/path/to/foo'))
367
to_url('/path/to/foo'))
359
369
self.assertEqual('file:///path/to/foo%2Cbar',
360
to_url('/path/to/foo,bar'))
370
to_url('/path/to/foo,bar'))
363
373
result = to_url(u'/path/to/r\xe4ksm\xf6rg\xe5s')
396
407
# self.assertEqual('file:///C:/path/to/foo%20',
397
408
# to_url('C:/path/to/foo '))
398
409
self.assertEqual('file:///C:/path/to/f%20oo',
399
to_url('C:/path/to/f oo'))
410
to_url('C:/path/to/f oo'))
401
412
self.assertEqual('file:///', to_url('/'))
403
414
self.assertEqual('file:///C:/path/to/foo%2Cbar',
404
to_url('C:/path/to/foo,bar'))
415
to_url('C:/path/to/foo,bar'))
406
417
result = to_url(u'd:/path/to/r\xe4ksm\xf6rg\xe5s')
407
418
except UnicodeError:
408
419
raise TestSkipped("local encoding cannot handle unicode")
410
self.assertEqual('file:///D:/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
411
self.assertFalse(isinstance(result, unicode))
422
'file:///D:/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
423
self.assertIsInstance(result, str)
413
425
def test_win32_unc_path_to_url(self):
414
426
self.requireFeature(features.win32_feature)
415
427
to_url = urlutils._win32_local_path_to_url
416
428
self.assertEqual('file://HOST/path',
417
to_url(r'\\HOST\path'))
429
to_url(r'\\HOST\path'))
418
430
self.assertEqual('file://HOST/path',
419
to_url('//HOST/path'))
431
to_url('//HOST/path'))
422
434
result = to_url(u'//HOST/path/to/r\xe4ksm\xf6rg\xe5s')
423
435
except UnicodeError:
424
436
raise TestSkipped("local encoding cannot handle unicode")
426
self.assertEqual('file://HOST/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
427
self.assertFalse(isinstance(result, unicode))
439
'file://HOST/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
440
self.assertFalse(isinstance(result, str))
429
442
def test_win32_local_path_from_url(self):
430
443
from_url = urlutils._win32_local_path_from_url
431
444
self.assertEqual('C:/path/to/foo',
432
from_url('file:///C|/path/to/foo'))
433
self.assertEqual(u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
445
from_url('file:///C|/path/to/foo'))
447
u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
434
448
from_url('file:///d|/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s'))
435
self.assertEqual(u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
450
u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
436
451
from_url('file:///d:/path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))
437
452
self.assertEqual('/', from_url('file:///'))
438
453
self.assertEqual('C:/path/to/foo',
439
from_url('file:///C|/path/to/foo,branch=foo'))
454
from_url('file:///C|/path/to/foo,branch=foo'))
441
self.assertRaises(InvalidURL, from_url, 'file:///C:')
442
self.assertRaises(InvalidURL, from_url, 'file:///c')
443
self.assertRaises(InvalidURL, from_url, '/path/to/foo')
456
self.assertRaises(urlutils.InvalidURL, from_url, 'file:///C:')
457
self.assertRaises(urlutils.InvalidURL, from_url, 'file:///c')
458
self.assertRaises(urlutils.InvalidURL, from_url, '/path/to/foo')
444
459
# Not a valid _win32 url, no drive letter
445
self.assertRaises(InvalidURL, from_url, 'file:///path/to/foo')
460
self.assertRaises(urlutils.InvalidURL, from_url, 'file:///path/to/foo')
447
462
def test_win32_unc_path_from_url(self):
448
463
from_url = urlutils._win32_local_path_from_url
449
464
self.assertEqual('//HOST/path', from_url('file://HOST/path'))
450
465
self.assertEqual('//HOST/path',
451
from_url('file://HOST/path,branch=foo'))
466
from_url('file://HOST/path,branch=foo'))
452
467
# despite IE allows 2, 4, 5 and 6 slashes in URL to another machine
453
468
# we want to use only 2 slashes
454
469
# Firefox understand only 5 slashes in URL, but it's ugly
455
self.assertRaises(InvalidURL, from_url, 'file:////HOST/path')
456
self.assertRaises(InvalidURL, from_url, 'file://///HOST/path')
457
self.assertRaises(InvalidURL, from_url, 'file://////HOST/path')
470
self.assertRaises(urlutils.InvalidURL, from_url, 'file:////HOST/path')
471
self.assertRaises(urlutils.InvalidURL, from_url, 'file://///HOST/path')
472
self.assertRaises(urlutils.InvalidURL, from_url,
473
'file://////HOST/path')
458
474
# check for file://C:/ instead of file:///C:/
459
self.assertRaises(InvalidURL, from_url, 'file://C:/path')
475
self.assertRaises(urlutils.InvalidURL, from_url, 'file://C:/path')
461
477
def test_win32_extract_drive_letter(self):
462
478
extract = urlutils._win32_extract_drive_letter
463
479
self.assertEqual(('file:///C:', '/foo'), extract('file://', '/C:/foo'))
464
self.assertEqual(('file:///d|', '/path'), extract('file://', '/d|/path'))
465
self.assertRaises(InvalidURL, extract, 'file://', '/path')
480
self.assertEqual(('file:///d|', '/path'),
481
extract('file://', '/d|/path'))
482
self.assertRaises(urlutils.InvalidURL, extract, 'file://', '/path')
466
483
# Root drives without slash treated as invalid, see bug #841322
467
484
self.assertEqual(('file:///C:', '/'), extract('file://', '/C:/'))
468
self.assertRaises(InvalidURL, extract, 'file://', '/C:')
485
self.assertRaises(urlutils.InvalidURL, extract, 'file://', '/C:')
469
486
# Invalid without drive separator or following forward slash
470
self.assertRaises(InvalidURL, extract, 'file://', '/C')
471
self.assertRaises(InvalidURL, extract, 'file://', '/C:ool')
487
self.assertRaises(urlutils.InvalidURL, extract, 'file://', '/C')
488
self.assertRaises(urlutils.InvalidURL, extract, 'file://', '/C:ool')
473
490
def test_split(self):
474
# Test bzrlib.urlutils.split()
491
# Test breezy.urlutils.split()
475
492
split = urlutils.split
476
493
if sys.platform == 'win32':
477
self.assertRaises(InvalidURL, split, 'file:///path/to/foo')
494
self.assertRaises(urlutils.InvalidURL, split,
495
'file:///path/to/foo')
478
496
self.assertEqual(('file:///C|/', 'foo'), split('file:///C|/foo'))
479
497
self.assertEqual(('file:///C:/', ''), split('file:///C:/'))
481
499
self.assertEqual(('file:///', 'foo'), split('file:///foo'))
482
500
self.assertEqual(('file:///', ''), split('file:///'))
484
self.assertEqual(('http://host/path/to', 'foo'), split('http://host/path/to/foo'))
485
self.assertEqual(('http://host/path/to', 'foo'), split('http://host/path/to/foo/'))
486
self.assertEqual(('http://host/path/to/foo', ''),
502
self.assertEqual(('http://host/path/to', 'foo'),
503
split('http://host/path/to/foo'))
504
self.assertEqual(('http://host/path/to', 'foo'),
505
split('http://host/path/to/foo/'))
507
('http://host/path/to/foo', ''),
487
508
split('http://host/path/to/foo/', exclude_trailing_slash=False))
488
509
self.assertEqual(('http://host/', 'path'), split('http://host/path'))
489
510
self.assertEqual(('http://host/', ''), split('http://host/'))
490
511
self.assertEqual(('http://host', ''), split('http://host'))
491
self.assertEqual(('http:///nohost', 'path'), split('http:///nohost/path'))
512
self.assertEqual(('http:///nohost', 'path'),
513
split('http:///nohost/path'))
493
515
self.assertEqual(('random+scheme://user:pass@ahost:port/', 'path'),
494
split('random+scheme://user:pass@ahost:port/path'))
516
split('random+scheme://user:pass@ahost:port/path'))
495
517
self.assertEqual(('random+scheme://user:pass@ahost:port/', 'path'),
496
split('random+scheme://user:pass@ahost:port/path/'))
518
split('random+scheme://user:pass@ahost:port/path/'))
497
519
self.assertEqual(('random+scheme://user:pass@ahost:port/', ''),
498
split('random+scheme://user:pass@ahost:port/'))
520
split('random+scheme://user:pass@ahost:port/'))
501
523
self.assertEqual(('path/to', 'foo'), split('path/to/foo'))
502
524
self.assertEqual(('path/to', 'foo'), split('path/to/foo/'))
503
525
self.assertEqual(('path/to/foo', ''),
504
split('path/to/foo/', exclude_trailing_slash=False))
526
split('path/to/foo/', exclude_trailing_slash=False))
505
527
self.assertEqual(('path/..', 'foo'), split('path/../foo'))
506
528
self.assertEqual(('../path', 'foo'), split('../path/foo'))
530
def test_strip_segment_parameters(self):
531
strip_segment_parameters = urlutils.strip_segment_parameters
532
# Check relative references with absolute paths
533
self.assertEqual("/some/path",
534
strip_segment_parameters("/some/path"))
535
self.assertEqual("/some/path",
536
strip_segment_parameters("/some/path,tip"))
537
self.assertEqual("/some,dir/path",
538
strip_segment_parameters("/some,dir/path,tip"))
541
strip_segment_parameters("/somedir/path,heads%2Ftip"))
544
strip_segment_parameters("/somedir/path,heads%2Ftip,bar"))
545
# Check relative references with relative paths
546
self.assertEqual("", strip_segment_parameters(",key1=val1"))
547
self.assertEqual("foo/", strip_segment_parameters("foo/,key1=val1"))
548
self.assertEqual("foo", strip_segment_parameters("foo,key1=val1"))
550
"foo/base,la=bla/other/elements",
551
strip_segment_parameters("foo/base,la=bla/other/elements"))
553
"foo/base,la=bla/other/elements",
554
strip_segment_parameters("foo/base,la=bla/other/elements,a=b"))
555
# TODO: Check full URLs as well as relative references
508
557
def test_split_segment_parameters_raw(self):
509
558
split_segment_parameters_raw = urlutils.split_segment_parameters_raw
510
559
# Check relative references with absolute paths
511
self.assertEquals(("/some/path", []),
512
split_segment_parameters_raw("/some/path"))
513
self.assertEquals(("/some/path", ["tip"]),
514
split_segment_parameters_raw("/some/path,tip"))
515
self.assertEquals(("/some,dir/path", ["tip"]),
516
split_segment_parameters_raw("/some,dir/path,tip"))
517
self.assertEquals(("/somedir/path", ["heads%2Ftip"]),
560
self.assertEqual(("/some/path", []),
561
split_segment_parameters_raw("/some/path"))
562
self.assertEqual(("/some/path", ["tip"]),
563
split_segment_parameters_raw("/some/path,tip"))
564
self.assertEqual(("/some,dir/path", ["tip"]),
565
split_segment_parameters_raw("/some,dir/path,tip"))
567
("/somedir/path", ["heads%2Ftip"]),
518
568
split_segment_parameters_raw("/somedir/path,heads%2Ftip"))
519
self.assertEquals(("/somedir/path", ["heads%2Ftip", "bar"]),
570
("/somedir/path", ["heads%2Ftip", "bar"]),
520
571
split_segment_parameters_raw("/somedir/path,heads%2Ftip,bar"))
521
572
# Check relative references with relative paths
522
self.assertEquals(("", ["key1=val1"]),
523
split_segment_parameters_raw(",key1=val1"))
524
self.assertEquals(("foo/", ["key1=val1"]),
525
split_segment_parameters_raw("foo/,key1=val1"))
526
self.assertEquals(("foo", ["key1=val1"]),
527
split_segment_parameters_raw("foo,key1=val1"))
528
self.assertEquals(("foo/base,la=bla/other/elements", []),
573
self.assertEqual(("", ["key1=val1"]),
574
split_segment_parameters_raw(",key1=val1"))
575
self.assertEqual(("foo/", ["key1=val1"]),
576
split_segment_parameters_raw("foo/,key1=val1"))
577
self.assertEqual(("foo", ["key1=val1"]),
578
split_segment_parameters_raw("foo,key1=val1"))
580
("foo/base,la=bla/other/elements", []),
529
581
split_segment_parameters_raw("foo/base,la=bla/other/elements"))
530
self.assertEquals(("foo/base,la=bla/other/elements", ["a=b"]),
583
("foo/base,la=bla/other/elements", ["a=b"]),
531
584
split_segment_parameters_raw("foo/base,la=bla/other/elements,a=b"))
532
585
# TODO: Check full URLs as well as relative references
534
587
def test_split_segment_parameters(self):
535
588
split_segment_parameters = urlutils.split_segment_parameters
536
589
# Check relative references with absolute paths
537
self.assertEquals(("/some/path", {}),
538
split_segment_parameters("/some/path"))
539
self.assertEquals(("/some/path", {"branch": "tip"}),
540
split_segment_parameters("/some/path,branch=tip"))
541
self.assertEquals(("/some,dir/path", {"branch": "tip"}),
542
split_segment_parameters("/some,dir/path,branch=tip"))
543
self.assertEquals(("/somedir/path", {"ref": "heads%2Ftip"}),
590
self.assertEqual(("/some/path", {}),
591
split_segment_parameters("/some/path"))
592
self.assertEqual(("/some/path", {"branch": "tip"}),
593
split_segment_parameters("/some/path,branch=tip"))
594
self.assertEqual(("/some,dir/path", {"branch": "tip"}),
595
split_segment_parameters("/some,dir/path,branch=tip"))
597
("/somedir/path", {"ref": "heads%2Ftip"}),
544
598
split_segment_parameters("/somedir/path,ref=heads%2Ftip"))
545
self.assertEquals(("/somedir/path",
546
{"ref": "heads%2Ftip", "key1": "val1"}),
547
split_segment_parameters(
548
"/somedir/path,ref=heads%2Ftip,key1=val1"))
549
self.assertEquals(("/somedir/path", {"ref": "heads%2F=tip"}),
599
self.assertEqual(("/somedir/path",
600
{"ref": "heads%2Ftip", "key1": "val1"}),
601
split_segment_parameters(
602
"/somedir/path,ref=heads%2Ftip,key1=val1"))
604
("/somedir/path", {"ref": "heads%2F=tip"}),
550
605
split_segment_parameters("/somedir/path,ref=heads%2F=tip"))
551
606
# Check relative references with relative paths
552
self.assertEquals(("", {"key1": "val1"}),
553
split_segment_parameters(",key1=val1"))
554
self.assertEquals(("foo/", {"key1": "val1"}),
555
split_segment_parameters("foo/,key1=val1"))
556
self.assertEquals(("foo/base,key1=val1/other/elements", {}),
607
self.assertEqual(("", {"key1": "val1"}),
608
split_segment_parameters(",key1=val1"))
609
self.assertEqual(("foo/", {"key1": "val1"}),
610
split_segment_parameters("foo/,key1=val1"))
612
("foo/base,key1=val1/other/elements", {}),
557
613
split_segment_parameters("foo/base,key1=val1/other/elements"))
558
self.assertEquals(("foo/base,key1=val1/other/elements",
559
{"key2": "val2"}), split_segment_parameters(
560
"foo/base,key1=val1/other/elements,key2=val2"))
614
self.assertEqual(("foo/base,key1=val1/other/elements",
615
{"key2": "val2"}), split_segment_parameters(
616
"foo/base,key1=val1/other/elements,key2=val2"))
618
urlutils.InvalidURL, split_segment_parameters,
561
620
# TODO: Check full URLs as well as relative references
563
622
def test_win32_strip_local_trailing_slash(self):
831
890
def test_parse_simple(self):
832
891
parsed = urlutils.parse_url('http://example.com:80/one')
833
self.assertEquals(('http', None, None, 'example.com', 80, '/one'),
892
self.assertEqual(('http', None, None, 'example.com', 80, '/one'),
836
895
def test_ipv6(self):
837
896
parsed = urlutils.parse_url('http://[1:2:3::40]/one')
838
self.assertEquals(('http', None, None, '1:2:3::40', None, '/one'),
897
self.assertEqual(('http', None, None, '1:2:3::40', None, '/one'),
841
900
def test_ipv6_port(self):
842
901
parsed = urlutils.parse_url('http://[1:2:3::40]:80/one')
843
self.assertEquals(('http', None, None, '1:2:3::40', 80, '/one'),
902
self.assertEqual(('http', None, None, '1:2:3::40', 80, '/one'),
847
906
class TestURL(TestCase):
849
908
def test_parse_simple(self):
850
909
parsed = urlutils.URL.from_string('http://example.com:80/one')
851
self.assertEquals('http', parsed.scheme)
910
self.assertEqual('http', parsed.scheme)
852
911
self.assertIs(None, parsed.user)
853
912
self.assertIs(None, parsed.password)
854
self.assertEquals('example.com', parsed.host)
855
self.assertEquals(80, parsed.port)
856
self.assertEquals('/one', parsed.path)
913
self.assertEqual('example.com', parsed.host)
914
self.assertEqual(80, parsed.port)
915
self.assertEqual('/one', parsed.path)
858
917
def test_ipv6(self):
859
918
parsed = urlutils.URL.from_string('http://[1:2:3::40]/one')
860
self.assertEquals('http', parsed.scheme)
919
self.assertEqual('http', parsed.scheme)
861
920
self.assertIs(None, parsed.port)
862
921
self.assertIs(None, parsed.user)
863
922
self.assertIs(None, parsed.password)
864
self.assertEquals('1:2:3::40', parsed.host)
865
self.assertEquals('/one', parsed.path)
923
self.assertEqual('1:2:3::40', parsed.host)
924
self.assertEqual('/one', parsed.path)
867
926
def test_ipv6_port(self):
868
927
parsed = urlutils.URL.from_string('http://[1:2:3::40]:80/one')
869
self.assertEquals('http', parsed.scheme)
870
self.assertEquals('1:2:3::40', parsed.host)
928
self.assertEqual('http', parsed.scheme)
929
self.assertEqual('1:2:3::40', parsed.host)
871
930
self.assertIs(None, parsed.user)
872
931
self.assertIs(None, parsed.password)
873
self.assertEquals(80, parsed.port)
874
self.assertEquals('/one', parsed.path)
932
self.assertEqual(80, parsed.port)
933
self.assertEqual('/one', parsed.path)
876
935
def test_quoted(self):
877
936
parsed = urlutils.URL.from_string(
878
937
'http://ro%62ey:h%40t@ex%41mple.com:2222/path')
879
self.assertEquals(parsed.quoted_host, 'ex%41mple.com')
880
self.assertEquals(parsed.host, 'exAmple.com')
881
self.assertEquals(parsed.port, 2222)
882
self.assertEquals(parsed.quoted_user, 'ro%62ey')
883
self.assertEquals(parsed.user, 'robey')
884
self.assertEquals(parsed.quoted_password, 'h%40t')
885
self.assertEquals(parsed.password, 'h@t')
886
self.assertEquals(parsed.path, '/path')
938
self.assertEqual(parsed.quoted_host, 'ex%41mple.com')
939
self.assertEqual(parsed.host, 'exAmple.com')
940
self.assertEqual(parsed.port, 2222)
941
self.assertEqual(parsed.quoted_user, 'ro%62ey')
942
self.assertEqual(parsed.user, 'robey')
943
self.assertEqual(parsed.quoted_password, 'h%40t')
944
self.assertEqual(parsed.password, 'h@t')
945
self.assertEqual(parsed.path, '/path')
888
947
def test_eq(self):
889
948
parsed1 = urlutils.URL.from_string('http://[1:2:3::40]:80/one')
890
949
parsed2 = urlutils.URL.from_string('http://[1:2:3::40]:80/one')
891
self.assertEquals(parsed1, parsed2)
892
self.assertEquals(parsed1, parsed1)
950
self.assertEqual(parsed1, parsed2)
951
self.assertEqual(parsed1, parsed1)
893
952
parsed2.path = '/two'
894
self.assertNotEquals(parsed1, parsed2)
953
self.assertNotEqual(parsed1, parsed2)
896
955
def test_repr(self):
897
956
parsed = urlutils.URL.from_string('http://[1:2:3::40]:80/one')
899
958
"<URL('http', None, None, '1:2:3::40', 80, '/one')>",
902
961
def test_str(self):
903
962
parsed = urlutils.URL.from_string('http://[1:2:3::40]:80/one')
904
self.assertEquals('http://[1:2:3::40]:80/one', str(parsed))
963
self.assertEqual('http://[1:2:3::40]:80/one', str(parsed))
906
965
def test__combine_paths(self):
907
966
combine = urlutils.URL._combine_paths
955
1023
def test_same_url_posix(self):
956
1024
self._with_posix_paths()
957
self.assertEquals("",
958
urlutils.file_relpath("file:///a", "file:///a"))
959
self.assertEquals("",
960
urlutils.file_relpath("file:///a", "file:///a/"))
961
self.assertEquals("",
962
urlutils.file_relpath("file:///a/", "file:///a"))
1025
self.assertEqual("",
1026
urlutils.file_relpath("file:///a", "file:///a"))
1027
self.assertEqual("",
1028
urlutils.file_relpath("file:///a", "file:///a/"))
1029
self.assertEqual("",
1030
urlutils.file_relpath("file:///a/", "file:///a"))
964
1032
def test_same_url_win32(self):
965
1033
self._with_win32_paths()
966
self.assertEquals("",
967
urlutils.file_relpath("file:///A:/", "file:///A:/"))
968
self.assertEquals("",
969
urlutils.file_relpath("file:///A|/", "file:///A:/"))
970
self.assertEquals("",
971
urlutils.file_relpath("file:///A:/b/", "file:///A:/b/"))
972
self.assertEquals("",
973
urlutils.file_relpath("file:///A:/b", "file:///A:/b/"))
974
self.assertEquals("",
975
urlutils.file_relpath("file:///A:/b/", "file:///A:/b"))
1034
self.assertEqual("",
1035
urlutils.file_relpath("file:///A:/", "file:///A:/"))
1036
self.assertEqual("",
1037
urlutils.file_relpath("file:///A|/", "file:///A:/"))
1039
"", urlutils.file_relpath("file:///A:/b/", "file:///A:/b/"))
1041
"", urlutils.file_relpath("file:///A:/b", "file:///A:/b/"))
1043
"", urlutils.file_relpath("file:///A:/b/", "file:///A:/b"))
977
1045
def test_child_posix(self):
978
1046
self._with_posix_paths()
979
self.assertEquals("b",
980
urlutils.file_relpath("file:///a", "file:///a/b"))
981
self.assertEquals("b",
982
urlutils.file_relpath("file:///a/", "file:///a/b"))
983
self.assertEquals("b/c",
984
urlutils.file_relpath("file:///a", "file:///a/b/c"))
1048
"b", urlutils.file_relpath("file:///a", "file:///a/b"))
1050
"b", urlutils.file_relpath("file:///a/", "file:///a/b"))
1052
"b/c", urlutils.file_relpath("file:///a", "file:///a/b/c"))
986
1054
def test_child_win32(self):
987
1055
self._with_win32_paths()
988
self.assertEquals("b",
989
urlutils.file_relpath("file:///A:/", "file:///A:/b"))
990
self.assertEquals("b",
991
urlutils.file_relpath("file:///A|/", "file:///A:/b"))
992
self.assertEquals("c",
993
urlutils.file_relpath("file:///A:/b", "file:///A:/b/c"))
994
self.assertEquals("c",
995
urlutils.file_relpath("file:///A:/b/", "file:///A:/b/c"))
996
self.assertEquals("c/d",
997
urlutils.file_relpath("file:///A:/b", "file:///A:/b/c/d"))
1057
"b", urlutils.file_relpath("file:///A:/", "file:///A:/b"))
1059
"b", urlutils.file_relpath("file:///A|/", "file:///A:/b"))
1061
"c", urlutils.file_relpath("file:///A:/b", "file:///A:/b/c"))
1063
"c", urlutils.file_relpath("file:///A:/b/", "file:///A:/b/c"))
1065
"c/d", urlutils.file_relpath("file:///A:/b", "file:///A:/b/c/d"))
999
1067
def test_sibling_posix(self):
1000
1068
self._with_posix_paths()
1001
self.assertRaises(PathNotChild,
1002
1071
urlutils.file_relpath, "file:///a/b", "file:///a/c")
1003
self.assertRaises(PathNotChild,
1004
1074
urlutils.file_relpath, "file:///a/b/", "file:///a/c")
1005
self.assertRaises(PathNotChild,
1006
1077
urlutils.file_relpath, "file:///a/b/", "file:///a/c/")
1008
1079
def test_sibling_win32(self):
1009
1080
self._with_win32_paths()
1010
self.assertRaises(PathNotChild,
1011
1083
urlutils.file_relpath, "file:///A:/b", "file:///A:/c")
1012
self.assertRaises(PathNotChild,
1013
1086
urlutils.file_relpath, "file:///A:/b/", "file:///A:/c")
1014
self.assertRaises(PathNotChild,
1015
1089
urlutils.file_relpath, "file:///A:/b/", "file:///A:/c/")
1017
1091
def test_parent_posix(self):
1018
1092
self._with_posix_paths()
1019
1093
self.assertRaises(PathNotChild,
1020
urlutils.file_relpath, "file:///a/b", "file:///a")
1094
urlutils.file_relpath, "file:///a/b", "file:///a")
1021
1095
self.assertRaises(PathNotChild,
1022
urlutils.file_relpath, "file:///a/b", "file:///a/")
1096
urlutils.file_relpath, "file:///a/b", "file:///a/")
1024
1098
def test_parent_win32(self):
1025
1099
self._with_win32_paths()
1026
self.assertRaises(PathNotChild,
1027
1102
urlutils.file_relpath, "file:///A:/b", "file:///A:/")
1028
self.assertRaises(PathNotChild,
1029
1105
urlutils.file_relpath, "file:///A:/b/c", "file:///A:/b")