~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_urlutils.py

  • Committer: Matt Nordhoff
  • Date: 2009-04-04 02:50:01 UTC
  • mfrom: (4253 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4256.
  • Revision ID: mnordhoff@mattnordhoff.com-20090404025001-z1403k0tatmc8l91
Merge bzr.dev, fixing conflicts.

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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for the urlutils wrapper."""
18
18
 
26
26
 
27
27
 
28
28
class TestUrlToPath(TestCase):
29
 
    
 
29
 
30
30
    def test_basename(self):
31
31
        # bzrlib.urlutils.basename
32
32
        # Test bzrlib.urlutils.split()
83
83
        try:
84
84
            u'uni/\xb5'.encode(osutils.get_user_encoding())
85
85
        except UnicodeError:
86
 
            # locale cannot handle unicode 
 
86
            # locale cannot handle unicode
87
87
            pass
88
88
        else:
89
89
            norm_file('uni/%C2%B5', u'uni/\xb5')
226
226
        test('file:///bar/foo', 'file:///bar/', 'foo')
227
227
        test('http://host/foo', 'http://host/', 'foo')
228
228
        test('http://host/', 'http://host', '')
229
 
        
 
229
 
230
230
        # Invalid joinings
231
231
        # Cannot go above root
232
232
        # Implicitly at root:
264
264
 
265
265
        # Test joining to a path with a trailing slash
266
266
        test('foo/bar', 'foo/', 'bar')
267
 
        
 
267
 
268
268
        # Invalid joinings
269
269
        # Cannot go above root
270
270
        self.assertRaises(InvalidURLJoin, urlutils.joinpath, '/', '../baz')
315
315
        #     to_url('C:/path/to/foo '))
316
316
        self.assertEqual('file:///C:/path/to/f%20oo',
317
317
            to_url('C:/path/to/f oo'))
318
 
        
 
318
 
319
319
        self.assertEqual('file:///', to_url('/'))
320
320
 
321
321
        try:
497
497
        self.assertEqual('%C3%A5', urlutils.escape(u'\xe5'))
498
498
        self.assertFalse(isinstance(urlutils.escape(u'\xe5'), unicode))
499
499
 
 
500
    def test_escape_tildes(self):
 
501
        self.assertEqual('~foo', urlutils.escape('~foo'))
 
502
 
500
503
    def test_unescape(self):
501
504
        self.assertEqual('%', urlutils.unescape('%25'))
502
505
        self.assertEqual(u'\xe5', urlutils.unescape('%C3%A5'))
513
516
        def test(expected, base, other):
514
517
            result = urlutils.relative_url(base, other)
515
518
            self.assertEqual(expected, result)
516
 
            
 
519
 
517
520
        test('a', 'http://host/', 'http://host/a')
518
521
        test('http://entirely/different', 'sftp://host/branch',
519
522
                    'http://entirely/different')
528
531
                    'sftp://host/home/jelmer/branch/2b')
529
532
        test('../../branch/feature/%2b', 'http://host/home/jelmer/bar/%2b',
530
533
                    'http://host/home/jelmer/branch/feature/%2b')
531
 
        test('../../branch/feature/2b', 'http://host/home/jelmer/bar/2b/', 
 
534
        test('../../branch/feature/2b', 'http://host/home/jelmer/bar/2b/',
532
535
                    'http://host/home/jelmer/branch/feature/2b')
533
536
        # relative_url should preserve a trailing slash
534
537
        test('../../branch/feature/2b/', 'http://host/home/jelmer/bar/2b/',
592
595
 
593
596
        os.chdir(u'dod\xe9')
594
597
 
595
 
        # On Mac OSX this directory is actually: 
 
598
        # On Mac OSX this directory is actually:
596
599
        #   u'/dode\u0301' => '/dode\xcc\x81
597
 
        # but we should normalize it back to 
 
600
        # but we should normalize it back to
598
601
        #   u'/dod\xe9' => '/dod\xc3\xa9'
599
602
        url = urlutils.local_path_to_url('.')
600
603
        self.assertEndsWith(url, '/dod%C3%A9')