~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_urlutils.py

  • Committer: Martin Pool
  • Date: 2008-10-20 23:58:12 UTC
  • mto: This revision was merged to the branch mainline in revision 3787.
  • Revision ID: mbp@sourcefrog.net-20081020235812-itg90mk0u4dez92z
lp-upload-release now handles names like bzr-1.8.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Tests for the urlutils wrapper."""
18
18
 
19
19
import os
 
20
import re
20
21
import sys
21
22
 
22
23
from bzrlib import osutils, urlutils, win32utils
25
26
 
26
27
 
27
28
class TestUrlToPath(TestCase):
28
 
 
 
29
    
29
30
    def test_basename(self):
30
31
        # bzrlib.urlutils.basename
31
32
        # Test bzrlib.urlutils.split()
82
83
        try:
83
84
            u'uni/\xb5'.encode(osutils.get_user_encoding())
84
85
        except UnicodeError:
85
 
            # locale cannot handle unicode
 
86
            # locale cannot handle unicode 
86
87
            pass
87
88
        else:
88
89
            norm_file('uni/%C2%B5', u'uni/\xb5')
225
226
        test('file:///bar/foo', 'file:///bar/', 'foo')
226
227
        test('http://host/foo', 'http://host/', 'foo')
227
228
        test('http://host/', 'http://host', '')
228
 
 
 
229
        
229
230
        # Invalid joinings
230
231
        # Cannot go above root
231
232
        # Implicitly at root:
263
264
 
264
265
        # Test joining to a path with a trailing slash
265
266
        test('foo/bar', 'foo/', 'bar')
266
 
 
 
267
        
267
268
        # Invalid joinings
268
269
        # Cannot go above root
269
270
        self.assertRaises(InvalidURLJoin, urlutils.joinpath, '/', '../baz')
299
300
            from_url('file:///path/to/r%C3%A4ksm%C3%B6rg%C3%A5s'))
300
301
        self.assertEqual(u'/path/to/r\xe4ksm\xf6rg\xe5s',
301
302
            from_url('file:///path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))
302
 
        self.assertEqual(u'/path/to/r\xe4ksm\xf6rg\xe5s',
303
 
            from_url('file://localhost/path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))
304
303
 
305
304
        self.assertRaises(InvalidURL, from_url, '/path/to/foo')
306
 
        self.assertRaises(
307
 
            InvalidURL, from_url,
308
 
            'file://remotehost/path/to/r%c3%a4ksm%c3%b6rg%c3%a5s')
309
305
 
310
306
    def test_win32_local_path_to_url(self):
311
307
        to_url = urlutils._win32_local_path_to_url
319
315
        #     to_url('C:/path/to/foo '))
320
316
        self.assertEqual('file:///C:/path/to/f%20oo',
321
317
            to_url('C:/path/to/f oo'))
322
 
 
 
318
        
323
319
        self.assertEqual('file:///', to_url('/'))
324
320
 
325
321
        try:
501
497
        self.assertEqual('%C3%A5', urlutils.escape(u'\xe5'))
502
498
        self.assertFalse(isinstance(urlutils.escape(u'\xe5'), unicode))
503
499
 
504
 
    def test_escape_tildes(self):
505
 
        self.assertEqual('~foo', urlutils.escape('~foo'))
506
 
 
507
500
    def test_unescape(self):
508
501
        self.assertEqual('%', urlutils.unescape('%25'))
509
502
        self.assertEqual(u'\xe5', urlutils.unescape('%C3%A5'))
520
513
        def test(expected, base, other):
521
514
            result = urlutils.relative_url(base, other)
522
515
            self.assertEqual(expected, result)
523
 
 
 
516
            
524
517
        test('a', 'http://host/', 'http://host/a')
525
518
        test('http://entirely/different', 'sftp://host/branch',
526
519
                    'http://entirely/different')
535
528
                    'sftp://host/home/jelmer/branch/2b')
536
529
        test('../../branch/feature/%2b', 'http://host/home/jelmer/bar/%2b',
537
530
                    'http://host/home/jelmer/branch/feature/%2b')
538
 
        test('../../branch/feature/2b', 'http://host/home/jelmer/bar/2b/',
 
531
        test('../../branch/feature/2b', 'http://host/home/jelmer/bar/2b/', 
539
532
                    'http://host/home/jelmer/branch/feature/2b')
540
533
        # relative_url should preserve a trailing slash
541
534
        test('../../branch/feature/2b/', 'http://host/home/jelmer/bar/2b/',
599
592
 
600
593
        os.chdir(u'dod\xe9')
601
594
 
602
 
        # On Mac OSX this directory is actually:
 
595
        # On Mac OSX this directory is actually: 
603
596
        #   u'/dode\u0301' => '/dode\xcc\x81
604
 
        # but we should normalize it back to
 
597
        # but we should normalize it back to 
605
598
        #   u'/dod\xe9' => '/dod\xc3\xa9'
606
599
        url = urlutils.local_path_to_url('.')
607
600
        self.assertEndsWith(url, '/dod%C3%A9')
676
669
                         '/bar', '/bar/baz'))
677
670
        self.assertEqual('.', urlutils.determine_relative_path(
678
671
                         '/bar', '/bar'))
679
 
 
680
 
 
681
 
class TestParseURL(TestCase):
682
 
 
683
 
    def test_parse_url(self):
684
 
        self.assertEqual(urlutils.parse_url('http://example.com:80/one'),
685
 
            ('http', None, None, 'example.com', 80, '/one'))
686
 
        self.assertEqual(urlutils.parse_url('http://[1:2:3::40]/one'),
687
 
                ('http', None, None, '1:2:3::40', None, '/one'))
688
 
        self.assertEqual(urlutils.parse_url('http://[1:2:3::40]:80/one'),
689
 
                ('http', None, None, '1:2:3::40', 80, '/one'))