~ubuntu-branches/ubuntu/gutsy/bzr/gutsy

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_urlutils.py

  • Committer: Bazaar Package Importer
  • Author(s): Etienne Goyer
  • Date: 2007-04-27 17:53:49 UTC
  • mfrom: (1.1.23 upstream)
  • Revision ID: james.westby@ubuntu.com-20070427175349-rvowqx994rfuikuu
Tags: 0.16~rc1-0ubuntu1
New upstream development release 

Show diffs side-by-side

added added

removed removed

Lines of Context:
115
115
        eq('http://host/ab/%C2%B5/%C2%B5',
116
116
            normalize_url(u'http://host/ab/%C2%B5/\xb5'))
117
117
 
 
118
        # Unescape characters that don't need to be escaped
 
119
        eq('http://host/~bob%2525-._',
 
120
                normalize_url('http://host/%7Ebob%2525%2D%2E%5F'))
 
121
        eq('http://host/~bob%2525-._',
 
122
                normalize_url(u'http://host/%7Ebob%2525%2D%2E%5F'))
 
123
 
118
124
        # Normalize verifies URLs when they are not unicode
119
125
        # (indicating they did not come from the user)
120
126
        self.assertRaises(InvalidURL, normalize_url, 'http://host/\xb5')
197
203
            joined = urlutils.join(*args)
198
204
            self.assertEqual(expected, joined)
199
205
 
200
 
        # Test a single element
201
 
        test('foo', 'foo')
202
 
 
203
206
        # Test relative path joining
 
207
        test('foo', 'foo') # relative fragment with nothing is preserved.
204
208
        test('foo/bar', 'foo', 'bar')
205
209
        test('http://foo/bar', 'http://foo', 'bar')
206
210
        test('http://foo/bar', 'http://foo', '.', 'bar')
207
211
        test('http://foo/baz', 'http://foo', 'bar', '../baz')
208
212
        test('http://foo/bar/baz', 'http://foo', 'bar/baz')
209
213
        test('http://foo/baz', 'http://foo', 'bar/../baz')
 
214
        test('http://foo/baz', 'http://foo/bar/', '../baz')
210
215
 
211
216
        # Absolute paths
 
217
        test('http://foo', 'http://foo') # abs url with nothing is preserved.
212
218
        test('http://bar', 'http://foo', 'http://bar')
213
219
        test('sftp://bzr/foo', 'http://foo', 'bar', 'sftp://bzr/foo')
214
220
        test('file:///bar', 'foo', 'file:///bar')
 
221
        test('http://bar/', 'http://foo', 'http://bar/')
 
222
        test('http://bar/a', 'http://foo', 'http://bar/a')
 
223
        test('http://bar/a/', 'http://foo', 'http://bar/a/')
215
224
 
216
225
        # From a base path
217
226
        test('file:///foo', 'file:///', 'foo')
221
230
        
222
231
        # Invalid joinings
223
232
        # Cannot go above root
 
233
        # Implicitly at root:
224
234
        self.assertRaises(InvalidURLJoin, urlutils.join,
225
235
                'http://foo', '../baz')
 
236
        self.assertRaises(InvalidURLJoin, urlutils.join,
 
237
                'http://foo', '/..')
 
238
        # Joining from a path explicitly under the root.
 
239
        self.assertRaises(InvalidURLJoin, urlutils.join,
 
240
                'http://foo/a', '../../b')
 
241
 
 
242
    def test_joinpath(self):
 
243
        def test(expected, *args):
 
244
            joined = urlutils.joinpath(*args)
 
245
            self.assertEqual(expected, joined)
 
246
 
 
247
        # Test a single element
 
248
        test('foo', 'foo')
 
249
 
 
250
        # Test relative path joining
 
251
        test('foo/bar', 'foo', 'bar')
 
252
        test('foo/bar', 'foo', '.', 'bar')
 
253
        test('foo/baz', 'foo', 'bar', '../baz')
 
254
        test('foo/bar/baz', 'foo', 'bar/baz')
 
255
        test('foo/baz', 'foo', 'bar/../baz')
 
256
 
 
257
        # Test joining to an absolute path
 
258
        test('/foo', '/foo')
 
259
        test('/foo', '/foo', '.')
 
260
        test('/foo/bar', '/foo', 'bar')
 
261
        test('/', '/foo', '..')
 
262
 
 
263
        # Test joining with an absolute path
 
264
        test('/bar', 'foo', '/bar')
 
265
 
 
266
        # Test joining to a path with a trailing slash
 
267
        test('foo/bar', 'foo/', 'bar')
 
268
        
 
269
        # Invalid joinings
 
270
        # Cannot go above root
 
271
        self.assertRaises(InvalidURLJoin, urlutils.joinpath, '/', '../baz')
 
272
        self.assertRaises(InvalidURLJoin, urlutils.joinpath, '/', '..')
 
273
        self.assertRaises(InvalidURLJoin, urlutils.joinpath, '/', '/..')
226
274
 
227
275
    def test_function_type(self):
228
276
        if sys.platform == 'win32':