53
48
class TestTransport(tests.TestCase):
54
49
"""Test the non transport-concrete class functionality."""
51
# FIXME: These tests should use addCleanup() and/or overrideAttr() instead
52
# of try/finally -- vila 20100205
56
54
def test__get_set_protocol_handlers(self):
57
55
handlers = transport._get_protocol_handlers()
58
self.assertNotEqual([], handlers.keys())
59
transport._clear_protocol_handlers()
60
self.addCleanup(transport._set_protocol_handlers, handlers)
61
self.assertEqual([], transport._get_protocol_handlers().keys())
56
self.assertNotEqual([], handlers.keys( ))
58
transport._clear_protocol_handlers()
59
self.assertEqual([], transport._get_protocol_handlers().keys())
61
transport._set_protocol_handlers(handlers)
63
63
def test_get_transport_modules(self):
64
64
handlers = transport._get_protocol_handlers()
65
self.addCleanup(transport._set_protocol_handlers, handlers)
66
65
# don't pollute the current handlers
67
66
transport._clear_protocol_handlers()
69
67
class SampleHandler(object):
70
68
"""I exist, isnt that enough?"""
71
transport._clear_protocol_handlers()
72
transport.register_transport_proto('foo')
73
transport.register_lazy_transport('foo',
74
'breezy.tests.test_transport',
75
'TestTransport.SampleHandler')
76
transport.register_transport_proto('bar')
77
transport.register_lazy_transport('bar',
78
'breezy.tests.test_transport',
79
'TestTransport.SampleHandler')
80
self.assertEqual([SampleHandler.__module__,
81
'breezy.transport.chroot',
82
'breezy.transport.pathfilter'],
83
transport._get_transport_modules())
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)
85
86
def test_transport_dependency(self):
86
87
"""Transport with missing dependency causes no error"""
87
88
saved_handlers = transport._get_protocol_handlers()
88
self.addCleanup(transport._set_protocol_handlers, saved_handlers)
89
89
# don't pollute the current handlers
90
90
transport._clear_protocol_handlers()
91
transport.register_transport_proto('foo')
92
transport.register_lazy_transport(
93
'foo', 'breezy.tests.test_transport', 'BadTransportHandler')
95
transport.get_transport_from_url('foo://fooserver/foo')
96
except errors.UnsupportedProtocol as e:
97
self.assertEqual('Unsupported protocol'
98
' for url "foo://fooserver/foo":'
99
' Unable to import library "some_lib":'
100
' testing missing dependency', str(e))
102
self.fail('Did not raise UnsupportedProtocol')
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)
104
109
def test_transport_fallback(self):
105
110
"""Transport with missing dependency causes no error"""
106
111
saved_handlers = transport._get_protocol_handlers()
107
self.addCleanup(transport._set_protocol_handlers, saved_handlers)
108
transport._clear_protocol_handlers()
109
transport.register_transport_proto('foo')
110
transport.register_lazy_transport(
111
'foo', 'breezy.tests.test_transport', 'BackupTransportHandler')
112
transport.register_lazy_transport(
113
'foo', 'breezy.tests.test_transport', 'BadTransportHandler')
114
t = transport.get_transport_from_url('foo://fooserver/foo')
115
self.assertTrue(isinstance(t, BackupTransportHandler))
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)
117
124
def test_ssh_hints(self):
118
125
"""Transport ssh:// should raise an error pointing out bzr+ssh://"""
120
transport.get_transport_from_url('ssh://fooserver/foo')
121
except errors.UnsupportedProtocol as e:
123
'Unsupported protocol'
124
' for url "ssh://fooserver/foo":'
125
' Use bzr+ssh for Bazaar operations over SSH, '
126
'e.g. "bzr+ssh://fooserver/foo". Use git+ssh '
127
'for Git operations over SSH, e.g. "git+ssh://fooserver/foo".',
127
transport.get_transport('ssh://fooserver/foo')
128
except errors.UnsupportedProtocol, e:
130
self.assertEquals('Unsupported protocol'
131
' for url "ssh://fooserver/foo":'
132
' bzr supports bzr+ssh to operate over ssh,'
133
' use "bzr+ssh://fooserver/foo".',
130
136
self.fail('Did not raise UnsupportedProtocol')
178
195
def test_coalesce_overlapped(self):
179
196
self.assertRaises(ValueError,
180
self.check, [(0, 15, [(0, 10), (5, 10)])],
197
self.check, [(0, 15, [(0, 10), (5, 10)])],
183
200
def test_coalesce_limit(self):
184
201
self.check([(10, 50, [(0, 10), (10, 10), (20, 10),
185
202
(30, 10), (40, 10)]),
186
203
(60, 50, [(0, 10), (10, 10), (20, 10),
187
204
(30, 10), (40, 10)]),
188
], [(10, 10), (20, 10), (30, 10), (40, 10),
189
(50, 10), (60, 10), (70, 10), (80, 10),
190
(90, 10), (100, 10)],
205
], [(10, 10), (20, 10), (30, 10), (40, 10),
206
(50, 10), (60, 10), (70, 10), (80, 10),
207
(90, 10), (100, 10)],
193
210
def test_coalesce_no_limit(self):
194
211
self.check([(10, 100, [(0, 10), (10, 10), (20, 10),
195
212
(30, 10), (40, 10), (50, 10),
196
213
(60, 10), (70, 10), (80, 10),
198
], [(10, 10), (20, 10), (30, 10), (40, 10),
199
(50, 10), (60, 10), (70, 10), (80, 10),
200
(90, 10), (100, 10)])
215
], [(10, 10), (20, 10), (30, 10), (40, 10),
216
(50, 10), (60, 10), (70, 10), (80, 10),
217
(90, 10), (100, 10)])
202
219
def test_coalesce_fudge(self):
203
220
self.check([(10, 30, [(0, 10), (20, 10)]),
204
(100, 10, [(0, 10)]),
205
], [(10, 10), (30, 10), (100, 10)],
221
(100, 10, [(0, 10),]),
222
], [(10, 10), (30, 10), (100, 10)],
208
225
def test_coalesce_max_size(self):
209
226
self.check([(10, 20, [(0, 10), (10, 10)]),
210
227
(30, 50, [(0, 50)]),
211
228
# If one range is above max_size, it gets its own coalesced
213
(100, 80, [(0, 80)]), ],
230
(100, 80, [(0, 80),]),],
214
231
[(10, 10), (20, 10), (30, 50), (100, 80)],
217
235
def test_coalesce_no_max_size(self):
218
self.check([(10, 170, [(0, 10), (10, 10), (20, 50), (70, 100)])],
236
self.check([(10, 170, [(0, 10), (10, 10), (20, 50), (70, 100)]),],
219
237
[(10, 10), (20, 10), (30, 50), (80, 100)],
222
240
def test_coalesce_default_limit(self):
223
241
# By default we use a 100MB max size.
224
ten_mb = 10 * 1024 * 1024
226
[(0, 10 * ten_mb, [(i * ten_mb, ten_mb) for i in range(10)]),
227
(10 * ten_mb, ten_mb, [(0, ten_mb)])],
228
[(i * ten_mb, ten_mb) for i in range(11)])
230
[(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)],
232
max_size=1 * 1024 * 1024 * 1024)
242
ten_mb = 10*1024*1024
243
self.check([(0, 10*ten_mb, [(i*ten_mb, ten_mb) for i in range(10)]),
244
(10*ten_mb, ten_mb, [(0, ten_mb)])],
245
[(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)],
248
max_size=1*1024*1024*1024)
235
251
class TestMemoryServer(tests.TestCase):
273
289
def test_append_and_get(self):
274
290
t = memory.MemoryTransport()
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')
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')
281
296
def test_put_and_get(self):
282
297
t = memory.MemoryTransport()
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')
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')
288
303
def test_append_without_dir_fails(self):
289
304
t = memory.MemoryTransport()
290
305
self.assertRaises(errors.NoSuchFile,
291
t.append_bytes, 'dir/path', b'content')
306
t.append_bytes, 'dir/path', 'content')
293
308
def test_put_without_dir_fails(self):
294
309
t = memory.MemoryTransport()
295
310
self.assertRaises(errors.NoSuchFile,
296
t.put_file, 'dir/path', BytesIO(b'content'))
311
t.put_file, 'dir/path', StringIO('content'))
298
313
def test_get_missing(self):
299
314
transport = memory.MemoryTransport()
302
317
def test_has_missing(self):
303
318
t = memory.MemoryTransport()
304
self.assertEqual(False, t.has('foo'))
319
self.assertEquals(False, t.has('foo'))
306
321
def test_has_present(self):
307
322
t = memory.MemoryTransport()
308
t.append_bytes('foo', b'content')
309
self.assertEqual(True, t.has('foo'))
323
t.append_bytes('foo', 'content')
324
self.assertEquals(True, t.has('foo'))
311
326
def test_list_dir(self):
312
327
t = memory.MemoryTransport()
313
t.put_bytes('foo', b'content')
328
t.put_bytes('foo', 'content')
315
t.put_bytes('dir/subfoo', b'content')
316
t.put_bytes('dirlike', b'content')
330
t.put_bytes('dir/subfoo', 'content')
331
t.put_bytes('dirlike', 'content')
318
self.assertEqual(['dir', 'dirlike', 'foo'], sorted(t.list_dir('.')))
319
self.assertEqual(['subfoo'], sorted(t.list_dir('dir')))
333
self.assertEquals(['dir', 'dirlike', 'foo'], sorted(t.list_dir('.')))
334
self.assertEquals(['subfoo'], sorted(t.list_dir('dir')))
321
336
def test_mkdir(self):
322
337
t = memory.MemoryTransport()
324
t.append_bytes('dir/path', b'content')
325
with t.get('dir/path') as f:
326
self.assertEqual(f.read(), b'content')
339
t.append_bytes('dir/path', 'content')
340
self.assertEqual(t.get('dir/path').read(), 'content')
328
342
def test_mkdir_missing_parent(self):
329
343
t = memory.MemoryTransport()
342
356
def test_iter_files_recursive(self):
343
357
t = memory.MemoryTransport()
345
t.put_bytes('dir/foo', b'content')
346
t.put_bytes('dir/bar', b'content')
347
t.put_bytes('bar', b'content')
359
t.put_bytes('dir/foo', 'content')
360
t.put_bytes('dir/bar', 'content')
361
t.put_bytes('bar', 'content')
348
362
paths = set(t.iter_files_recursive())
349
self.assertEqual({'dir/foo', 'dir/bar', 'bar'}, paths)
363
self.assertEqual(set(['dir/foo', 'dir/bar', 'bar']), paths)
351
365
def test_stat(self):
352
366
t = memory.MemoryTransport()
353
t.put_bytes('foo', b'content')
354
t.put_bytes('bar', b'phowar')
367
t.put_bytes('foo', 'content')
368
t.put_bytes('bar', 'phowar')
355
369
self.assertEqual(7, t.stat('foo').st_size)
356
370
self.assertEqual(6, t.stat('bar').st_size)
443
458
backing_transport = memory.MemoryTransport()
444
459
server = chroot.ChrootServer(backing_transport)
445
460
server.start_server()
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])
462
self.assertEqual('chroot-%d:///' % id(server), server.get_url())
473
467
class PathFilteringDecoratorTransportTest(tests.TestCase):
707
class TestTransportFromPath(tests.TestCaseInTempDir):
709
def test_with_path(self):
710
t = transport.get_transport_from_path(self.test_dir)
711
self.assertIsInstance(t, local.LocalTransport)
712
self.assertEqual(t.base.rstrip("/"),
713
urlutils.local_path_to_url(self.test_dir))
715
def test_with_url(self):
716
t = transport.get_transport_from_path("file:")
717
self.assertIsInstance(t, local.LocalTransport)
720
urlutils.local_path_to_url(os.path.join(self.test_dir, "file:")))
723
class TestTransportFromUrl(tests.TestCaseInTempDir):
725
def test_with_path(self):
726
self.assertRaises(urlutils.InvalidURL, transport.get_transport_from_url,
729
def test_with_url(self):
730
url = urlutils.local_path_to_url(self.test_dir)
731
t = transport.get_transport_from_url(url)
732
self.assertIsInstance(t, local.LocalTransport)
733
self.assertEqual(t.base.rstrip("/"), url)
735
def test_with_url_and_segment_parameters(self):
736
url = urlutils.local_path_to_url(self.test_dir) + ",branch=foo"
737
t = transport.get_transport_from_url(url)
738
self.assertIsInstance(t, local.LocalTransport)
739
self.assertEqual(t.base.rstrip("/"), url)
740
with open(os.path.join(self.test_dir, "afile"), 'w') as f:
742
self.assertTrue(t.has("afile"))
745
698
class TestLocalTransports(tests.TestCase):
747
700
def test_get_transport_from_abspath(self):
748
701
here = osutils.abspath('.')
749
702
t = transport.get_transport(here)
750
703
self.assertIsInstance(t, local.LocalTransport)
751
self.assertEqual(t.base, urlutils.local_path_to_url(here) + '/')
704
self.assertEquals(t.base, urlutils.local_path_to_url(here) + '/')
753
706
def test_get_transport_from_relpath(self):
707
here = osutils.abspath('.')
754
708
t = transport.get_transport('.')
755
709
self.assertIsInstance(t, local.LocalTransport)
756
self.assertEqual(t.base, urlutils.local_path_to_url('.') + '/')
710
self.assertEquals(t.base, urlutils.local_path_to_url('.') + '/')
758
712
def test_get_transport_from_local_url(self):
759
713
here = osutils.abspath('.')
760
714
here_url = urlutils.local_path_to_url(here) + '/'
761
715
t = transport.get_transport(here_url)
762
716
self.assertIsInstance(t, local.LocalTransport)
763
self.assertEqual(t.base, here_url)
717
self.assertEquals(t.base, here_url)
765
719
def test_local_abspath(self):
766
720
here = osutils.abspath('.')
767
721
t = transport.get_transport(here)
768
self.assertEqual(t.local_abspath(''), here)
771
class TestLocalTransportMutation(tests.TestCaseInTempDir):
773
def test_local_transport_mkdir(self):
774
here = osutils.abspath('.')
775
t = transport.get_transport(here)
777
self.assertTrue(os.path.exists('test'))
779
def test_local_transport_mkdir_permission_denied(self):
780
# See https://bugs.launchpad.net/bzr/+bug/606537
781
here = osutils.abspath('.')
782
t = transport.get_transport(here)
784
def fake_chmod(path, mode):
785
e = OSError('permission denied')
786
e.errno = errno.EPERM
788
self.overrideAttr(os, 'chmod', fake_chmod)
790
t.mkdir('test2', mode=0o707)
791
self.assertTrue(os.path.exists('test'))
792
self.assertTrue(os.path.exists('test2'))
795
class TestLocalTransportWriteStream(tests.TestCaseWithTransport):
797
def test_local_fdatasync_calls_fdatasync(self):
798
"""Check fdatasync on a stream tries to flush the data to the OS.
800
We can't easily observe the external effect but we can at least see
804
fdatasync = getattr(os, 'fdatasync', sentinel)
805
if fdatasync is sentinel:
806
raise tests.TestNotApplicable('fdatasync not supported')
807
t = self.get_transport('.')
808
calls = self.recordCalls(os, 'fdatasync')
809
w = t.open_write_stream('out')
812
with open('out', 'rb') as f:
813
# Should have been flushed.
814
self.assertEqual(f.read(), b'foo')
815
self.assertEqual(len(calls), 1, calls)
817
def test_missing_directory(self):
818
t = self.get_transport('.')
819
self.assertRaises(errors.NoSuchFile, t.open_write_stream, 'dir/foo')
722
self.assertEquals(t.local_abspath(''), here)
822
725
class TestWin32LocalTransport(tests.TestCase):
824
727
def test_unc_clone_to_root(self):
825
self.requireFeature(features.win32_feature)
826
728
# Win32 UNC path like \\HOST\path
827
729
# clone to root should stop at least at \\HOST part
829
731
t = local.EmulatedWin32LocalTransport('file://HOST/path/to/some/dir/')
831
733
t = t.clone('..')
832
self.assertEqual(t.base, 'file://HOST/')
734
self.assertEquals(t.base, 'file://HOST/')
833
735
# make sure we reach the root
834
736
t = t.clone('..')
835
self.assertEqual(t.base, 'file://HOST/')
737
self.assertEquals(t.base, 'file://HOST/')
838
740
class TestConnectedTransport(tests.TestCase):
841
743
def test_parse_url(self):
842
744
t = transport.ConnectedTransport(
843
745
'http://simple.example.com/home/source')
844
self.assertEqual(t._parsed_url.host, 'simple.example.com')
845
self.assertEqual(t._parsed_url.port, None)
846
self.assertEqual(t._parsed_url.path, '/home/source/')
847
self.assertTrue(t._parsed_url.user is None)
848
self.assertTrue(t._parsed_url.password is None)
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)
850
self.assertEqual(t.base, 'http://simple.example.com/home/source/')
752
self.assertEquals(t.base, 'http://simple.example.com/home/source/')
852
754
def test_parse_url_with_at_in_user(self):
854
756
t = transport.ConnectedTransport('ftp://user@host.com@www.host.com/')
855
self.assertEqual(t._parsed_url.user, 'user@host.com')
757
self.assertEquals(t._user, 'user@host.com')
857
759
def test_parse_quoted_url(self):
858
760
t = transport.ConnectedTransport(
859
761
'http://ro%62ey:h%40t@ex%41mple.com:2222/path')
860
self.assertEqual(t._parsed_url.host, 'exAmple.com')
861
self.assertEqual(t._parsed_url.port, 2222)
862
self.assertEqual(t._parsed_url.user, 'robey')
863
self.assertEqual(t._parsed_url.password, 'h@t')
864
self.assertEqual(t._parsed_url.path, '/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/')
866
768
# Base should not keep track of the password
867
self.assertEqual(t.base, 'http://ro%62ey@ex%41mple.com:2222/path/')
769
self.assertEquals(t.base, 'http://robey@exAmple.com:2222/path/')
869
771
def test_parse_invalid_url(self):
870
self.assertRaises(urlutils.InvalidURL,
772
self.assertRaises(errors.InvalidURL,
871
773
transport.ConnectedTransport,
872
774
'sftp://lily.org:~janneke/public/bzr/gub')
874
776
def test_relpath(self):
875
777
t = transport.ConnectedTransport('sftp://user@host.com/abs/path')
877
self.assertEqual(t.relpath('sftp://user@host.com/abs/path/sub'),
779
self.assertEquals(t.relpath('sftp://user@host.com/abs/path/sub'), 'sub')
879
780
self.assertRaises(errors.PathNotChild, t.relpath,
880
781
'http://user@host.com/abs/path/sub')
881
782
self.assertRaises(errors.PathNotChild, t.relpath,
886
787
'sftp://user@host.com:33/abs/path/sub')
887
788
# Make sure it works when we don't supply a username
888
789
t = transport.ConnectedTransport('sftp://host.com/abs/path')
889
self.assertEqual(t.relpath('sftp://host.com/abs/path/sub'), 'sub')
790
self.assertEquals(t.relpath('sftp://host.com/abs/path/sub'), 'sub')
891
792
# Make sure it works when parts of the path will be url encoded
892
793
t = transport.ConnectedTransport('sftp://host.com/dev/%path')
893
self.assertEqual(t.relpath('sftp://host.com/dev/%path/sub'), 'sub')
794
self.assertEquals(t.relpath('sftp://host.com/dev/%path/sub'), 'sub')
895
796
def test_connection_sharing_propagate_credentials(self):
896
797
t = transport.ConnectedTransport('ftp://user@host.com/abs/path')
897
self.assertEqual('user', t._parsed_url.user)
898
self.assertEqual('host.com', t._parsed_url.host)
798
self.assertEquals('user', t._user)
799
self.assertEquals('host.com', t._host)
899
800
self.assertIs(None, t._get_connection())
900
self.assertIs(None, t._parsed_url.password)
801
self.assertIs(None, t._password)
901
802
c = t.clone('subdir')
902
803
self.assertIs(None, c._get_connection())
903
self.assertIs(None, t._parsed_url.password)
804
self.assertIs(None, t._password)
905
806
# Simulate the user entering a password
906
807
password = 'secret'
926
827
def test_reuse_same_transport(self):
927
828
possible_transports = []
928
t1 = transport.get_transport_from_url(
929
'http://foo/', possible_transports=possible_transports)
829
t1 = transport.get_transport('http://foo/',
830
possible_transports=possible_transports)
930
831
self.assertEqual([t1], possible_transports)
931
t2 = transport.get_transport_from_url('http://foo/',
932
possible_transports=[t1])
832
t2 = transport.get_transport('http://foo/',
833
possible_transports=[t1])
933
834
self.assertIs(t1, t2)
935
836
# Also check that final '/' are handled correctly
936
t3 = transport.get_transport_from_url('http://foo/path/')
937
t4 = transport.get_transport_from_url('http://foo/path',
938
possible_transports=[t3])
837
t3 = transport.get_transport('http://foo/path/')
838
t4 = transport.get_transport('http://foo/path',
839
possible_transports=[t3])
939
840
self.assertIs(t3, t4)
941
t5 = transport.get_transport_from_url('http://foo/path')
942
t6 = transport.get_transport_from_url('http://foo/path/',
943
possible_transports=[t5])
842
t5 = transport.get_transport('http://foo/path')
843
t6 = transport.get_transport('http://foo/path/',
844
possible_transports=[t5])
944
845
self.assertIs(t5, t6)
946
847
def test_don_t_reuse_different_transport(self):
947
t1 = transport.get_transport_from_url('http://foo/path')
948
t2 = transport.get_transport_from_url('http://bar/path',
949
possible_transports=[t1])
848
t1 = transport.get_transport('http://foo/path')
849
t2 = transport.get_transport('http://bar/path',
850
possible_transports=[t1])
950
851
self.assertIsNot(t1, t2)
953
854
class TestTransportTrace(tests.TestCase):
955
def test_decorator(self):
956
t = transport.get_transport_from_url('trace+memory://')
957
self.assertIsInstance(
958
t, breezy.transport.trace.TransportTraceDecorator)
857
t = transport.get_transport('trace+memory://')
858
self.assertIsInstance(t, bzrlib.transport.trace.TransportTraceDecorator)
960
860
def test_clone_preserves_activity(self):
961
t = transport.get_transport_from_url('trace+memory://')
861
t = transport.get_transport('trace+memory://')
962
862
t2 = t.clone('.')
963
863
self.assertTrue(t is not t2)
964
864
self.assertTrue(t._activity is t2._activity)