48
55
class TestTransport(tests.TestCase):
49
56
"""Test the non transport-concrete class functionality."""
51
# FIXME: These tests should use addCleanup() and/or overrideAttr() instead
52
# of try/finally -- vila 20100205
54
58
def test__get_set_protocol_handlers(self):
55
59
handlers = transport._get_protocol_handlers()
56
self.assertNotEqual([], handlers.keys( ))
58
transport._clear_protocol_handlers()
59
self.assertEqual([], transport._get_protocol_handlers().keys())
61
transport._set_protocol_handlers(handlers)
60
self.assertNotEqual([], handlers.keys())
61
transport._clear_protocol_handlers()
62
self.addCleanup(transport._set_protocol_handlers, handlers)
63
self.assertEqual([], transport._get_protocol_handlers().keys())
63
65
def test_get_transport_modules(self):
64
66
handlers = transport._get_protocol_handlers()
67
self.addCleanup(transport._set_protocol_handlers, handlers)
65
68
# don't pollute the current handlers
66
69
transport._clear_protocol_handlers()
67
71
class SampleHandler(object):
68
72
"""I exist, isnt that enough?"""
70
transport._clear_protocol_handlers()
71
transport.register_transport_proto('foo')
72
transport.register_lazy_transport('foo',
73
'bzrlib.tests.test_transport',
74
'TestTransport.SampleHandler')
75
transport.register_transport_proto('bar')
76
transport.register_lazy_transport('bar',
77
'bzrlib.tests.test_transport',
78
'TestTransport.SampleHandler')
79
self.assertEqual([SampleHandler.__module__,
80
'bzrlib.transport.chroot',
81
'bzrlib.transport.pathfilter'],
82
transport._get_transport_modules())
84
transport._set_protocol_handlers(handlers)
73
transport._clear_protocol_handlers()
74
transport.register_transport_proto('foo')
75
transport.register_lazy_transport('foo',
76
'breezy.tests.test_transport',
77
'TestTransport.SampleHandler')
78
transport.register_transport_proto('bar')
79
transport.register_lazy_transport('bar',
80
'breezy.tests.test_transport',
81
'TestTransport.SampleHandler')
82
self.assertEqual([SampleHandler.__module__,
83
'breezy.transport.chroot',
84
'breezy.transport.pathfilter'],
85
transport._get_transport_modules())
86
87
def test_transport_dependency(self):
87
88
"""Transport with missing dependency causes no error"""
88
89
saved_handlers = transport._get_protocol_handlers()
90
self.addCleanup(transport._set_protocol_handlers, saved_handlers)
89
91
# don't pollute the current handlers
90
92
transport._clear_protocol_handlers()
93
transport.register_transport_proto('foo')
94
transport.register_lazy_transport(
95
'foo', 'breezy.tests.test_transport', 'BadTransportHandler')
92
transport.register_transport_proto('foo')
93
transport.register_lazy_transport(
94
'foo', 'bzrlib.tests.test_transport', 'BadTransportHandler')
96
transport.get_transport('foo://fooserver/foo')
97
except errors.UnsupportedProtocol, e:
99
self.assertEquals('Unsupported protocol'
100
' for url "foo://fooserver/foo":'
101
' Unable to import library "some_lib":'
102
' testing missing dependency', str(e))
104
self.fail('Did not raise UnsupportedProtocol')
106
# restore original values
107
transport._set_protocol_handlers(saved_handlers)
97
transport.get_transport_from_url('foo://fooserver/foo')
98
except errors.UnsupportedProtocol as e:
100
self.assertEqual('Unsupported protocol'
101
' for url "foo://fooserver/foo":'
102
' Unable to import library "some_lib":'
103
' testing missing dependency', str(e))
105
self.fail('Did not raise UnsupportedProtocol')
109
107
def test_transport_fallback(self):
110
108
"""Transport with missing dependency causes no error"""
111
109
saved_handlers = transport._get_protocol_handlers()
113
transport._clear_protocol_handlers()
114
transport.register_transport_proto('foo')
115
transport.register_lazy_transport(
116
'foo', 'bzrlib.tests.test_transport', 'BackupTransportHandler')
117
transport.register_lazy_transport(
118
'foo', 'bzrlib.tests.test_transport', 'BadTransportHandler')
119
t = transport.get_transport('foo://fooserver/foo')
120
self.assertTrue(isinstance(t, BackupTransportHandler))
122
transport._set_protocol_handlers(saved_handlers)
110
self.addCleanup(transport._set_protocol_handlers, saved_handlers)
111
transport._clear_protocol_handlers()
112
transport.register_transport_proto('foo')
113
transport.register_lazy_transport(
114
'foo', 'breezy.tests.test_transport', 'BackupTransportHandler')
115
transport.register_lazy_transport(
116
'foo', 'breezy.tests.test_transport', 'BadTransportHandler')
117
t = transport.get_transport_from_url('foo://fooserver/foo')
118
self.assertTrue(isinstance(t, BackupTransportHandler))
124
120
def test_ssh_hints(self):
125
121
"""Transport ssh:// should raise an error pointing out bzr+ssh://"""
127
transport.get_transport('ssh://fooserver/foo')
128
except errors.UnsupportedProtocol, e:
123
transport.get_transport_from_url('ssh://fooserver/foo')
124
except errors.UnsupportedProtocol as e:
130
self.assertEquals('Unsupported protocol'
126
self.assertEqual('Unsupported protocol'
131
127
' for url "ssh://fooserver/foo":'
132
128
' bzr supports bzr+ssh to operate over ssh,'
133
129
' use "bzr+ssh://fooserver/foo".',
219
204
def test_coalesce_fudge(self):
220
205
self.check([(10, 30, [(0, 10), (20, 10)]),
221
(100, 10, [(0, 10),]),
206
(100, 10, [(0, 10)]),
222
207
], [(10, 10), (30, 10), (100, 10)],
225
210
def test_coalesce_max_size(self):
226
211
self.check([(10, 20, [(0, 10), (10, 10)]),
227
212
(30, 50, [(0, 50)]),
228
213
# If one range is above max_size, it gets its own coalesced
230
(100, 80, [(0, 80),]),],
215
(100, 80, [(0, 80)]),],
231
216
[(10, 10), (20, 10), (30, 50), (100, 80)],
235
219
def test_coalesce_no_max_size(self):
236
self.check([(10, 170, [(0, 10), (10, 10), (20, 50), (70, 100)]),],
220
self.check([(10, 170, [(0, 10), (10, 10), (20, 50), (70, 100)])],
237
221
[(10, 10), (20, 10), (30, 50), (80, 100)],
240
224
def test_coalesce_default_limit(self):
241
225
# By default we use a 100MB max size.
242
ten_mb = 10*1024*1024
243
self.check([(0, 10*ten_mb, [(i*ten_mb, ten_mb) for i in range(10)]),
226
ten_mb = 10 * 1024 * 1024
227
self.check([(0, 10 * ten_mb, [(i * ten_mb, ten_mb) for i in range(10)]),
244
228
(10*ten_mb, ten_mb, [(0, ten_mb)])],
245
229
[(i*ten_mb, ten_mb) for i in range(11)])
246
self.check([(0, 11*ten_mb, [(i*ten_mb, ten_mb) for i in range(11)]),],
247
[(i*ten_mb, ten_mb) for i in range(11)],
230
self.check([(0, 11 * ten_mb, [(i * ten_mb, ten_mb) for i in range(11)])],
231
[(i * ten_mb, ten_mb) for i in range(11)],
248
232
max_size=1*1024*1024*1024)
289
273
def test_append_and_get(self):
290
274
t = memory.MemoryTransport()
291
t.append_bytes('path', 'content')
292
self.assertEqual(t.get('path').read(), 'content')
293
t.append_file('path', StringIO('content'))
294
self.assertEqual(t.get('path').read(), 'contentcontent')
275
t.append_bytes('path', b'content')
276
self.assertEqual(t.get('path').read(), b'content')
277
t.append_file('path', BytesIO(b'content'))
278
with t.get('path') as f:
279
self.assertEqual(f.read(), b'contentcontent')
296
281
def test_put_and_get(self):
297
282
t = memory.MemoryTransport()
298
t.put_file('path', StringIO('content'))
299
self.assertEqual(t.get('path').read(), 'content')
300
t.put_bytes('path', 'content')
301
self.assertEqual(t.get('path').read(), 'content')
283
t.put_file('path', BytesIO(b'content'))
284
self.assertEqual(t.get('path').read(), b'content')
285
t.put_bytes('path', b'content')
286
self.assertEqual(t.get('path').read(), b'content')
303
288
def test_append_without_dir_fails(self):
304
289
t = memory.MemoryTransport()
305
290
self.assertRaises(errors.NoSuchFile,
306
t.append_bytes, 'dir/path', 'content')
291
t.append_bytes, 'dir/path', b'content')
308
293
def test_put_without_dir_fails(self):
309
294
t = memory.MemoryTransport()
310
295
self.assertRaises(errors.NoSuchFile,
311
t.put_file, 'dir/path', StringIO('content'))
296
t.put_file, 'dir/path', BytesIO(b'content'))
313
298
def test_get_missing(self):
314
299
transport = memory.MemoryTransport()
317
302
def test_has_missing(self):
318
303
t = memory.MemoryTransport()
319
self.assertEquals(False, t.has('foo'))
304
self.assertEqual(False, t.has('foo'))
321
306
def test_has_present(self):
322
307
t = memory.MemoryTransport()
323
t.append_bytes('foo', 'content')
324
self.assertEquals(True, t.has('foo'))
308
t.append_bytes('foo', b'content')
309
self.assertEqual(True, t.has('foo'))
326
311
def test_list_dir(self):
327
312
t = memory.MemoryTransport()
328
t.put_bytes('foo', 'content')
313
t.put_bytes('foo', b'content')
330
t.put_bytes('dir/subfoo', 'content')
331
t.put_bytes('dirlike', 'content')
315
t.put_bytes('dir/subfoo', b'content')
316
t.put_bytes('dirlike', b'content')
333
self.assertEquals(['dir', 'dirlike', 'foo'], sorted(t.list_dir('.')))
334
self.assertEquals(['subfoo'], sorted(t.list_dir('dir')))
318
self.assertEqual(['dir', 'dirlike', 'foo'], sorted(t.list_dir('.')))
319
self.assertEqual(['subfoo'], sorted(t.list_dir('dir')))
336
321
def test_mkdir(self):
337
322
t = memory.MemoryTransport()
339
t.append_bytes('dir/path', 'content')
340
self.assertEqual(t.get('dir/path').read(), 'content')
324
t.append_bytes('dir/path', b'content')
325
with t.get('dir/path') as f:
326
self.assertEqual(f.read(), b'content')
342
328
def test_mkdir_missing_parent(self):
343
329
t = memory.MemoryTransport()
356
342
def test_iter_files_recursive(self):
357
343
t = memory.MemoryTransport()
359
t.put_bytes('dir/foo', 'content')
360
t.put_bytes('dir/bar', 'content')
361
t.put_bytes('bar', 'content')
345
t.put_bytes('dir/foo', b'content')
346
t.put_bytes('dir/bar', b'content')
347
t.put_bytes('bar', b'content')
362
348
paths = set(t.iter_files_recursive())
363
self.assertEqual(set(['dir/foo', 'dir/bar', 'bar']), paths)
349
self.assertEqual({'dir/foo', 'dir/bar', 'bar'}, paths)
365
351
def test_stat(self):
366
352
t = memory.MemoryTransport()
367
t.put_bytes('foo', 'content')
368
t.put_bytes('bar', 'phowar')
353
t.put_bytes('foo', b'content')
354
t.put_bytes('bar', b'phowar')
369
355
self.assertEqual(7, t.stat('foo').st_size)
370
356
self.assertEqual(6, t.stat('bar').st_size)
458
443
backing_transport = memory.MemoryTransport()
459
444
server = chroot.ChrootServer(backing_transport)
460
445
server.start_server()
462
self.assertEqual('chroot-%d:///' % id(server), server.get_url())
446
self.addCleanup(server.stop_server)
447
self.assertEqual('chroot-%d:///' % id(server), server.get_url())
450
class TestHooks(tests.TestCase):
451
"""Basic tests for transport hooks"""
453
def _get_connected_transport(self):
454
return transport.ConnectedTransport("bogus:nowhere")
456
def test_transporthooks_initialisation(self):
457
"""Check all expected transport hook points are set up"""
458
hookpoint = transport.TransportHooks()
459
self.assertTrue("post_connect" in hookpoint,
460
"post_connect not in %s" % (hookpoint,))
462
def test_post_connect(self):
463
"""Ensure the post_connect hook is called when _set_transport is"""
465
transport.Transport.hooks.install_named_hook("post_connect",
467
t = self._get_connected_transport()
468
self.assertLength(0, calls)
469
t._set_connection("connection", "auth")
470
self.assertEqual(calls, [t])
467
473
class PathFilteringDecoratorTransportTest(tests.TestCase):
705
class TestTransportFromPath(tests.TestCaseInTempDir):
707
def test_with_path(self):
708
t = transport.get_transport_from_path(self.test_dir)
709
self.assertIsInstance(t, local.LocalTransport)
710
self.assertEqual(t.base.rstrip("/"),
711
urlutils.local_path_to_url(self.test_dir))
713
def test_with_url(self):
714
t = transport.get_transport_from_path("file:")
715
self.assertIsInstance(t, local.LocalTransport)
716
self.assertEqual(t.base.rstrip("/"),
717
urlutils.local_path_to_url(os.path.join(self.test_dir, "file:")))
720
class TestTransportFromUrl(tests.TestCaseInTempDir):
722
def test_with_path(self):
723
self.assertRaises(urlutils.InvalidURL, transport.get_transport_from_url,
726
def test_with_url(self):
727
url = urlutils.local_path_to_url(self.test_dir)
728
t = transport.get_transport_from_url(url)
729
self.assertIsInstance(t, local.LocalTransport)
730
self.assertEqual(t.base.rstrip("/"), url)
732
def test_with_url_and_segment_parameters(self):
733
url = urlutils.local_path_to_url(self.test_dir)+",branch=foo"
734
t = transport.get_transport_from_url(url)
735
self.assertIsInstance(t, local.LocalTransport)
736
self.assertEqual(t.base.rstrip("/"), url)
737
with open(os.path.join(self.test_dir, "afile"), 'w') as f:
739
self.assertTrue(t.has("afile"))
698
742
class TestLocalTransports(tests.TestCase):
700
744
def test_get_transport_from_abspath(self):
701
745
here = osutils.abspath('.')
702
746
t = transport.get_transport(here)
703
747
self.assertIsInstance(t, local.LocalTransport)
704
self.assertEquals(t.base, urlutils.local_path_to_url(here) + '/')
748
self.assertEqual(t.base, urlutils.local_path_to_url(here) + '/')
706
750
def test_get_transport_from_relpath(self):
707
751
here = osutils.abspath('.')
708
752
t = transport.get_transport('.')
709
753
self.assertIsInstance(t, local.LocalTransport)
710
self.assertEquals(t.base, urlutils.local_path_to_url('.') + '/')
754
self.assertEqual(t.base, urlutils.local_path_to_url('.') + '/')
712
756
def test_get_transport_from_local_url(self):
713
757
here = osutils.abspath('.')
714
758
here_url = urlutils.local_path_to_url(here) + '/'
715
759
t = transport.get_transport(here_url)
716
760
self.assertIsInstance(t, local.LocalTransport)
717
self.assertEquals(t.base, here_url)
761
self.assertEqual(t.base, here_url)
719
763
def test_local_abspath(self):
720
764
here = osutils.abspath('.')
721
765
t = transport.get_transport(here)
722
self.assertEquals(t.local_abspath(''), here)
766
self.assertEqual(t.local_abspath(''), here)
769
class TestLocalTransportMutation(tests.TestCaseInTempDir):
771
def test_local_transport_mkdir(self):
772
here = osutils.abspath('.')
773
t = transport.get_transport(here)
775
self.assertTrue(os.path.exists('test'))
777
def test_local_transport_mkdir_permission_denied(self):
778
# See https://bugs.launchpad.net/bzr/+bug/606537
779
here = osutils.abspath('.')
780
t = transport.get_transport(here)
781
def fake_chmod(path, mode):
782
e = OSError('permission denied')
783
e.errno = errno.EPERM
785
self.overrideAttr(os, 'chmod', fake_chmod)
787
t.mkdir('test2', mode=0o707)
788
self.assertTrue(os.path.exists('test'))
789
self.assertTrue(os.path.exists('test2'))
792
class TestLocalTransportWriteStream(tests.TestCaseWithTransport):
794
def test_local_fdatasync_calls_fdatasync(self):
795
"""Check fdatasync on a stream tries to flush the data to the OS.
797
We can't easily observe the external effect but we can at least see
801
fdatasync = getattr(os, 'fdatasync', sentinel)
802
if fdatasync is sentinel:
803
raise tests.TestNotApplicable('fdatasync not supported')
804
t = self.get_transport('.')
805
calls = self.recordCalls(os, 'fdatasync')
806
w = t.open_write_stream('out')
809
with open('out', 'rb') as f:
810
# Should have been flushed.
811
self.assertEqual(f.read(), b'foo')
812
self.assertEqual(len(calls), 1, calls)
814
def test_missing_directory(self):
815
t = self.get_transport('.')
816
self.assertRaises(errors.NoSuchFile, t.open_write_stream, 'dir/foo')
725
819
class TestWin32LocalTransport(tests.TestCase):
727
821
def test_unc_clone_to_root(self):
822
self.requireFeature(features.win32_feature)
728
823
# Win32 UNC path like \\HOST\path
729
824
# clone to root should stop at least at \\HOST part
731
826
t = local.EmulatedWin32LocalTransport('file://HOST/path/to/some/dir/')
733
828
t = t.clone('..')
734
self.assertEquals(t.base, 'file://HOST/')
829
self.assertEqual(t.base, 'file://HOST/')
735
830
# make sure we reach the root
736
831
t = t.clone('..')
737
self.assertEquals(t.base, 'file://HOST/')
832
self.assertEqual(t.base, 'file://HOST/')
740
835
class TestConnectedTransport(tests.TestCase):
743
838
def test_parse_url(self):
744
839
t = transport.ConnectedTransport(
745
840
'http://simple.example.com/home/source')
746
self.assertEquals(t._host, 'simple.example.com')
747
self.assertEquals(t._port, None)
748
self.assertEquals(t._path, '/home/source/')
749
self.failUnless(t._user is None)
750
self.failUnless(t._password is None)
841
self.assertEqual(t._parsed_url.host, 'simple.example.com')
842
self.assertEqual(t._parsed_url.port, None)
843
self.assertEqual(t._parsed_url.path, '/home/source/')
844
self.assertTrue(t._parsed_url.user is None)
845
self.assertTrue(t._parsed_url.password is None)
752
self.assertEquals(t.base, 'http://simple.example.com/home/source/')
847
self.assertEqual(t.base, 'http://simple.example.com/home/source/')
754
849
def test_parse_url_with_at_in_user(self):
756
851
t = transport.ConnectedTransport('ftp://user@host.com@www.host.com/')
757
self.assertEquals(t._user, 'user@host.com')
852
self.assertEqual(t._parsed_url.user, 'user@host.com')
759
854
def test_parse_quoted_url(self):
760
855
t = transport.ConnectedTransport(
761
856
'http://ro%62ey:h%40t@ex%41mple.com:2222/path')
762
self.assertEquals(t._host, 'exAmple.com')
763
self.assertEquals(t._port, 2222)
764
self.assertEquals(t._user, 'robey')
765
self.assertEquals(t._password, 'h@t')
766
self.assertEquals(t._path, '/path/')
857
self.assertEqual(t._parsed_url.host, 'exAmple.com')
858
self.assertEqual(t._parsed_url.port, 2222)
859
self.assertEqual(t._parsed_url.user, 'robey')
860
self.assertEqual(t._parsed_url.password, 'h@t')
861
self.assertEqual(t._parsed_url.path, '/path/')
768
863
# Base should not keep track of the password
769
self.assertEquals(t.base, 'http://robey@exAmple.com:2222/path/')
864
self.assertEqual(t.base, 'http://ro%62ey@ex%41mple.com:2222/path/')
771
866
def test_parse_invalid_url(self):
772
self.assertRaises(errors.InvalidURL,
867
self.assertRaises(urlutils.InvalidURL,
773
868
transport.ConnectedTransport,
774
869
'sftp://lily.org:~janneke/public/bzr/gub')
776
871
def test_relpath(self):
777
872
t = transport.ConnectedTransport('sftp://user@host.com/abs/path')
779
self.assertEquals(t.relpath('sftp://user@host.com/abs/path/sub'), 'sub')
874
self.assertEqual(t.relpath('sftp://user@host.com/abs/path/sub'),
780
876
self.assertRaises(errors.PathNotChild, t.relpath,
781
877
'http://user@host.com/abs/path/sub')
782
878
self.assertRaises(errors.PathNotChild, t.relpath,
787
883
'sftp://user@host.com:33/abs/path/sub')
788
884
# Make sure it works when we don't supply a username
789
885
t = transport.ConnectedTransport('sftp://host.com/abs/path')
790
self.assertEquals(t.relpath('sftp://host.com/abs/path/sub'), 'sub')
886
self.assertEqual(t.relpath('sftp://host.com/abs/path/sub'), 'sub')
792
888
# Make sure it works when parts of the path will be url encoded
793
889
t = transport.ConnectedTransport('sftp://host.com/dev/%path')
794
self.assertEquals(t.relpath('sftp://host.com/dev/%path/sub'), 'sub')
890
self.assertEqual(t.relpath('sftp://host.com/dev/%path/sub'), 'sub')
796
892
def test_connection_sharing_propagate_credentials(self):
797
893
t = transport.ConnectedTransport('ftp://user@host.com/abs/path')
798
self.assertEquals('user', t._user)
799
self.assertEquals('host.com', t._host)
894
self.assertEqual('user', t._parsed_url.user)
895
self.assertEqual('host.com', t._parsed_url.host)
800
896
self.assertIs(None, t._get_connection())
801
self.assertIs(None, t._password)
897
self.assertIs(None, t._parsed_url.password)
802
898
c = t.clone('subdir')
803
899
self.assertIs(None, c._get_connection())
804
self.assertIs(None, t._password)
900
self.assertIs(None, t._parsed_url.password)
806
902
# Simulate the user entering a password
807
903
password = 'secret'
827
923
def test_reuse_same_transport(self):
828
924
possible_transports = []
829
t1 = transport.get_transport('http://foo/',
925
t1 = transport.get_transport_from_url('http://foo/',
830
926
possible_transports=possible_transports)
831
927
self.assertEqual([t1], possible_transports)
832
t2 = transport.get_transport('http://foo/',
928
t2 = transport.get_transport_from_url('http://foo/',
833
929
possible_transports=[t1])
834
930
self.assertIs(t1, t2)
836
932
# Also check that final '/' are handled correctly
837
t3 = transport.get_transport('http://foo/path/')
838
t4 = transport.get_transport('http://foo/path',
933
t3 = transport.get_transport_from_url('http://foo/path/')
934
t4 = transport.get_transport_from_url('http://foo/path',
839
935
possible_transports=[t3])
840
936
self.assertIs(t3, t4)
842
t5 = transport.get_transport('http://foo/path')
843
t6 = transport.get_transport('http://foo/path/',
938
t5 = transport.get_transport_from_url('http://foo/path')
939
t6 = transport.get_transport_from_url('http://foo/path/',
844
940
possible_transports=[t5])
845
941
self.assertIs(t5, t6)
847
943
def test_don_t_reuse_different_transport(self):
848
t1 = transport.get_transport('http://foo/path')
849
t2 = transport.get_transport('http://bar/path',
944
t1 = transport.get_transport_from_url('http://foo/path')
945
t2 = transport.get_transport_from_url('http://bar/path',
850
946
possible_transports=[t1])
851
947
self.assertIsNot(t1, t2)
854
950
class TestTransportTrace(tests.TestCase):
857
t = transport.get_transport('trace+memory://')
858
self.assertIsInstance(t, bzrlib.transport.trace.TransportTraceDecorator)
952
def test_decorator(self):
953
t = transport.get_transport_from_url('trace+memory://')
954
self.assertIsInstance(
955
t, breezy.transport.trace.TransportTraceDecorator)
860
957
def test_clone_preserves_activity(self):
861
t = transport.get_transport('trace+memory://')
958
t = transport.get_transport_from_url('trace+memory://')
862
959
t2 = t.clone('.')
863
960
self.assertTrue(t is not t2)
864
961
self.assertTrue(t._activity is t2._activity)
989
1092
# And the rest are threads
990
1093
for t in started[1:]:
1097
class TestUnhtml(tests.TestCase):
1099
"""Tests for unhtml_roughly"""
1101
def test_truncation(self):
1102
fake_html = "<p>something!\n" * 1000
1103
result = http.unhtml_roughly(fake_html)
1104
self.assertEqual(len(result), 1000)
1105
self.assertStartsWith(result, " something!")
1108
class SomeDirectory(object):
1110
def look_up(self, name, url):
1114
class TestLocationToUrl(tests.TestCase):
1116
def get_base_location(self):
1117
path = osutils.abspath('/foo/bar')
1118
if path.startswith('/'):
1119
url = 'file://%s' % (path,)
1121
# On Windows, abspaths start with the drive letter, so we have to
1122
# add in the extra '/'
1123
url = 'file:///%s' % (path,)
1126
def test_regular_url(self):
1127
self.assertEqual("file://foo", location_to_url("file://foo"))
1129
def test_directory(self):
1130
directories.register("bar:", SomeDirectory, "Dummy directory")
1131
self.addCleanup(directories.remove, "bar:")
1132
self.assertEqual("http://bar", location_to_url("bar:"))
1134
def test_unicode_url(self):
1135
self.assertRaises(urlutils.InvalidURL, location_to_url,
1136
"http://fo/\xc3\xaf".decode("utf-8"))
1138
def test_unicode_path(self):
1139
path, url = self.get_base_location()
1140
location = path + "\xc3\xaf".decode("utf-8")
1142
self.assertEqual(url, location_to_url(location))
1144
def test_path(self):
1145
path, url = self.get_base_location()
1146
self.assertEqual(url, location_to_url(path))
1148
def test_relative_file_url(self):
1149
self.assertEqual(urlutils.local_path_to_url(".") + "/bar",
1150
location_to_url("file:bar"))
1152
def test_absolute_file_url(self):
1153
self.assertEqual("file:///bar", location_to_url("file:/bar"))