/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_urlutils.py

  • Committer: Martin Pool
  • Date: 2006-06-20 05:32:16 UTC
  • mfrom: (1797 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1798.
  • Revision ID: mbp@sourcefrog.net-20060620053216-817857d7ca3e9d1f
[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
        norm_file('uni/%25C2%25B5', u'uni/%C2%B5')
92
92
        norm_file('uni/%20b', u'uni/ b')
93
93
        # All the crazy characters get escaped in local paths => file:/// urls
94
 
        norm_file('%27%3B/%3F%3A%40%26%3D%2B%24%2C%23%20', "';/?:@&=+$,# ")
 
94
        # The ' ' character must not be at the end, because on win32
 
95
        # it gets stripped off by ntpath.abspath
 
96
        norm_file('%27%20%3B/%3F%3A%40%26%3D%2B%24%2C%23', "' ;/?:@&=+$,#")
95
97
 
96
98
    def test_normalize_url_hybrid(self):
97
99
        # Anything with a scheme:// should be treated as a hybrid url
209
211
        test('http://bar', 'http://foo', 'http://bar')
210
212
        test('sftp://bzr/foo', 'http://foo', 'bar', 'sftp://bzr/foo')
211
213
        test('file:///bar', 'foo', 'file:///bar')
 
214
 
 
215
        # From a base path
 
216
        test('file:///foo', 'file:///', 'foo')
 
217
        test('file:///bar/foo', 'file:///bar/', 'foo')
 
218
        test('http://host/foo', 'http://host/', 'foo')
 
219
        test('http://host/', 'http://host', '')
212
220
        
213
221
        # Invalid joinings
214
222
        # Cannot go above root
248
256
 
249
257
    def test_win32_local_path_to_url(self):
250
258
        to_url = urlutils._win32_local_path_to_url
251
 
        self.assertEqual('file:///C:/path/to/foo',
 
259
        self.assertEqual('file:///c:/path/to/foo',
252
260
            to_url('C:/path/to/foo'))
 
261
        # BOGUS: on win32, ntpath.abspath will strip trailing
 
262
        #       whitespace, so this will always fail
 
263
        #       Though under linux, it fakes abspath support
 
264
        #       and thus will succeed
 
265
        # self.assertEqual('file:///C:/path/to/foo%20',
 
266
        #     to_url('C:/path/to/foo '))
 
267
        self.assertEqual('file:///c:/path/to/f%20oo',
 
268
            to_url('C:/path/to/f oo'))
253
269
 
254
270
        try:
255
271
            result = to_url(u'd:/path/to/r\xe4ksm\xf6rg\xe5s')
256
272
        except UnicodeError:
257
273
            raise TestSkipped("local encoding cannot handle unicode")
258
274
 
259
 
        self.assertEqual('file:///D:/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
 
275
        self.assertEqual('file:///d:/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
260
276
 
261
277
    def test_win32_local_path_from_url(self):
262
278
        from_url = urlutils._win32_local_path_from_url
263
 
        self.assertEqual('C:/path/to/foo',
 
279
        self.assertEqual('c:/path/to/foo',
264
280
            from_url('file:///C|/path/to/foo'))
265
 
        self.assertEqual(u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
 
281
        self.assertEqual(u'd:/path/to/r\xe4ksm\xf6rg\xe5s',
266
282
            from_url('file:///d|/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s'))
267
 
        self.assertEqual(u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
 
283
        self.assertEqual(u'd:/path/to/r\xe4ksm\xf6rg\xe5s',
268
284
            from_url('file:///d:/path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))
269
285
 
270
286
        self.assertRaises(InvalidURL, from_url, '/path/to/foo')
271
287
        # Not a valid _win32 url, no drive letter
272
288
        self.assertRaises(InvalidURL, from_url, 'file:///path/to/foo')
273
289
 
 
290
    def test__win32_extract_drive_letter(self):
 
291
        extract = urlutils._win32_extract_drive_letter
 
292
        self.assertEqual(('file:///C:', '/foo'), extract('file://', '/C:/foo'))
 
293
        self.assertEqual(('file:///d|', '/path'), extract('file://', '/d|/path'))
 
294
        self.assertRaises(InvalidURL, extract, 'file://', '/path')
 
295
 
274
296
    def test_split(self):
275
297
        # Test bzrlib.urlutils.split()
276
298
        split = urlutils.split
306
328
        self.assertEqual(('path/..', 'foo'), split('path/../foo'))
307
329
        self.assertEqual(('../path', 'foo'), split('../path/foo'))
308
330
 
 
331
    def test__win32_strip_local_trailing_slash(self):
 
332
        strip = urlutils._win32_strip_local_trailing_slash
 
333
        self.assertEqual('file://', strip('file://'))
 
334
        self.assertEqual('file:///', strip('file:///'))
 
335
        self.assertEqual('file:///C', strip('file:///C'))
 
336
        self.assertEqual('file:///C:', strip('file:///C:'))
 
337
        self.assertEqual('file:///d|', strip('file:///d|'))
 
338
        self.assertEqual('file:///C:/', strip('file:///C:/'))
 
339
        self.assertEqual('file:///C:/a', strip('file:///C:/a/'))
 
340
 
309
341
    def test_strip_trailing_slash(self):
310
342
        sts = urlutils.strip_trailing_slash
311
343
        if sys.platform == 'win32':
348
380
 
349
381
        test('http://foo', 'http://foo')
350
382
        if sys.platform == 'win32':
351
 
            test('C:/foo/path', 'file:///C|/foo/path')
352
 
            test('C:/foo/path', 'file:///C:/foo/path')
 
383
            test('c:/foo/path', 'file:///C|/foo/path')
 
384
            test('c:/foo/path', 'file:///C:/foo/path')
353
385
        else:
354
386
            test('/foo/path', 'file:///foo/path')
355
387