348
350
from_url('file:///d|/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s'))
349
351
self.assertEqual(u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
350
352
from_url('file:///d:/path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))
353
self.assertEqual('/', from_url('file:///'))
352
355
self.assertRaises(InvalidURL, from_url, '/path/to/foo')
353
356
# Not a valid _win32 url, no drive letter
614
617
self.assertEqual("bar", derive("http://foo/bar"))
615
618
self.assertEqual("bar", derive("bzr+ssh://foo/bar"))
616
619
self.assertEqual("foo-bar", derive("lp:foo-bar"))
622
class TestRebaseURL(TestCase):
623
"""Test the behavior of rebase_url."""
625
def test_non_relative(self):
626
result = urlutils.rebase_url('file://foo', 'file://foo',
628
self.assertEqual('file://foo', result)
629
result = urlutils.rebase_url('/foo', 'file://foo',
631
self.assertEqual('/foo', result)
633
def test_different_ports(self):
634
e = self.assertRaises(InvalidRebaseURLs, urlutils.rebase_url,
635
'foo', 'http://bar:80', 'http://bar:81')
636
self.assertEqual(str(e), "URLs differ by more than path:"
637
" 'http://bar:80' and 'http://bar:81'")
639
def test_different_hosts(self):
640
e = self.assertRaises(InvalidRebaseURLs, urlutils.rebase_url,
641
'foo', 'http://bar', 'http://baz')
642
self.assertEqual(str(e), "URLs differ by more than path: 'http://bar'"
645
def test_different_protocol(self):
646
e = self.assertRaises(InvalidRebaseURLs, urlutils.rebase_url,
647
'foo', 'http://bar', 'ftp://bar')
648
self.assertEqual(str(e), "URLs differ by more than path: 'http://bar'"
651
def test_rebase_success(self):
652
self.assertEqual('../bar', urlutils.rebase_url('bar', 'http://baz/',
654
self.assertEqual('qux/bar', urlutils.rebase_url('bar',
655
'http://baz/qux', 'http://baz/'))
656
self.assertEqual('.', urlutils.rebase_url('foo',
657
'http://bar/', 'http://bar/foo/'))
658
self.assertEqual('qux/bar', urlutils.rebase_url('../bar',
659
'http://baz/qux/foo', 'http://baz/'))
661
def test_determine_relative_path(self):
662
self.assertEqual('../../baz/bar',
663
urlutils.determine_relative_path(
664
'/qux/quxx', '/baz/bar'))
665
self.assertEqual('..',
666
urlutils.determine_relative_path(
668
self.assertEqual('baz',
669
urlutils.determine_relative_path(
671
self.assertEqual('.', urlutils.determine_relative_path(