~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_urlutils.py

  • Committer: Andrew Bennetts
  • Date: 2008-07-28 06:53:44 UTC
  • mfrom: (3581 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3583.
  • Revision ID: andrew.bennetts@canonical.com-20080728065344-ocndjoycs903q6fz
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from bzrlib import osutils, urlutils, win32utils
24
24
import bzrlib
25
 
from bzrlib.errors import InvalidURL, InvalidURLJoin
 
25
from bzrlib.errors import InvalidURL, InvalidURLJoin, InvalidRebaseURLs
26
26
from bzrlib.tests import TestCaseInTempDir, TestCase, TestSkipped
27
27
 
28
28
 
316
316
        #     to_url('C:/path/to/foo '))
317
317
        self.assertEqual('file:///C:/path/to/f%20oo',
318
318
            to_url('C:/path/to/f oo'))
 
319
        
 
320
        self.assertEqual('file:///', to_url('/'))
319
321
 
320
322
        try:
321
323
            result = to_url(u'd:/path/to/r\xe4ksm\xf6rg\xe5s')
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:///'))
351
354
 
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"))
 
620
 
 
621
 
 
622
class TestRebaseURL(TestCase):
 
623
    """Test the behavior of rebase_url."""
 
624
 
 
625
    def test_non_relative(self):
 
626
        result = urlutils.rebase_url('file://foo', 'file://foo',
 
627
                                     'file://foo/bar')
 
628
        self.assertEqual('file://foo', result)
 
629
        result = urlutils.rebase_url('/foo', 'file://foo',
 
630
                                     'file://foo/bar')
 
631
        self.assertEqual('/foo', result)
 
632
 
 
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'")
 
638
 
 
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'"
 
643
                         " and 'http://baz'")
 
644
 
 
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'"
 
649
                         " and 'ftp://bar'")
 
650
 
 
651
    def test_rebase_success(self):
 
652
        self.assertEqual('../bar', urlutils.rebase_url('bar', 'http://baz/',
 
653
                         'http://baz/qux'))
 
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/'))
 
660
 
 
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(
 
667
                         '/bar/baz', '/bar'))
 
668
        self.assertEqual('baz',
 
669
                         urlutils.determine_relative_path(
 
670
                         '/bar', '/bar/baz'))
 
671
        self.assertEqual('.', urlutils.determine_relative_path(
 
672
                         '/bar', '/bar'))