48
53
class TestTransport(tests.TestCase):
49
54
"""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
56
def test__get_set_protocol_handlers(self):
55
57
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)
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())
63
63
def test_get_transport_modules(self):
64
64
handlers = transport._get_protocol_handlers()
65
self.addCleanup(transport._set_protocol_handlers, handlers)
65
66
# don't pollute the current handlers
66
67
transport._clear_protocol_handlers()
67
69
class SampleHandler(object):
68
70
"""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)
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())
86
85
def test_transport_dependency(self):
87
86
"""Transport with missing dependency causes no error"""
88
87
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')
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)
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')
109
104
def test_transport_fallback(self):
110
105
"""Transport with missing dependency causes no error"""
111
106
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)
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))
124
117
def test_ssh_hints(self):
125
118
"""Transport ssh:// should raise an error pointing out bzr+ssh://"""
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".',
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".',
136
130
self.fail('Did not raise UnsupportedProtocol')
195
178
def test_coalesce_overlapped(self):
196
179
self.assertRaises(ValueError,
197
self.check, [(0, 15, [(0, 10), (5, 10)])],
180
self.check, [(0, 15, [(0, 10), (5, 10)])],
200
183
def test_coalesce_limit(self):
201
184
self.check([(10, 50, [(0, 10), (10, 10), (20, 10),
202
185
(30, 10), (40, 10)]),
203
186
(60, 50, [(0, 10), (10, 10), (20, 10),
204
187
(30, 10), (40, 10)]),
205
], [(10, 10), (20, 10), (30, 10), (40, 10),
206
(50, 10), (60, 10), (70, 10), (80, 10),
207
(90, 10), (100, 10)],
188
], [(10, 10), (20, 10), (30, 10), (40, 10),
189
(50, 10), (60, 10), (70, 10), (80, 10),
190
(90, 10), (100, 10)],
210
193
def test_coalesce_no_limit(self):
211
194
self.check([(10, 100, [(0, 10), (10, 10), (20, 10),
212
195
(30, 10), (40, 10), (50, 10),
213
196
(60, 10), (70, 10), (80, 10),
215
], [(10, 10), (20, 10), (30, 10), (40, 10),
216
(50, 10), (60, 10), (70, 10), (80, 10),
217
(90, 10), (100, 10)])
198
], [(10, 10), (20, 10), (30, 10), (40, 10),
199
(50, 10), (60, 10), (70, 10), (80, 10),
200
(90, 10), (100, 10)])
219
202
def test_coalesce_fudge(self):
220
203
self.check([(10, 30, [(0, 10), (20, 10)]),
221
(100, 10, [(0, 10),]),
222
], [(10, 10), (30, 10), (100, 10)],
204
(100, 10, [(0, 10)]),
205
], [(10, 10), (30, 10), (100, 10)],
225
208
def test_coalesce_max_size(self):
226
209
self.check([(10, 20, [(0, 10), (10, 10)]),
227
210
(30, 50, [(0, 50)]),
228
211
# If one range is above max_size, it gets its own coalesced
230
(100, 80, [(0, 80),]),],
213
(100, 80, [(0, 80)]), ],
231
214
[(10, 10), (20, 10), (30, 50), (100, 80)],
235
217
def test_coalesce_no_max_size(self):
236
self.check([(10, 170, [(0, 10), (10, 10), (20, 50), (70, 100)]),],
218
self.check([(10, 170, [(0, 10), (10, 10), (20, 50), (70, 100)])],
237
219
[(10, 10), (20, 10), (30, 50), (80, 100)],
240
222
def test_coalesce_default_limit(self):
241
223
# 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)]),
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)
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)
251
235
class TestMemoryServer(tests.TestCase):
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):
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"))
698
745
class TestLocalTransports(tests.TestCase):
700
747
def test_get_transport_from_abspath(self):
701
748
here = osutils.abspath('.')
702
749
t = transport.get_transport(here)
703
750
self.assertIsInstance(t, local.LocalTransport)
704
self.assertEquals(t.base, urlutils.local_path_to_url(here) + '/')
751
self.assertEqual(t.base, urlutils.local_path_to_url(here) + '/')
706
753
def test_get_transport_from_relpath(self):
707
here = osutils.abspath('.')
708
754
t = transport.get_transport('.')
709
755
self.assertIsInstance(t, local.LocalTransport)
710
self.assertEquals(t.base, urlutils.local_path_to_url('.') + '/')
756
self.assertEqual(t.base, urlutils.local_path_to_url('.') + '/')
712
758
def test_get_transport_from_local_url(self):
713
759
here = osutils.abspath('.')
714
760
here_url = urlutils.local_path_to_url(here) + '/'
715
761
t = transport.get_transport(here_url)
716
762
self.assertIsInstance(t, local.LocalTransport)
717
self.assertEquals(t.base, here_url)
763
self.assertEqual(t.base, here_url)
719
765
def test_local_abspath(self):
720
766
here = osutils.abspath('.')
721
767
t = transport.get_transport(here)
722
self.assertEquals(t.local_abspath(''), 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')
725
822
class TestWin32LocalTransport(tests.TestCase):
727
824
def test_unc_clone_to_root(self):
825
self.requireFeature(features.win32_feature)
728
826
# Win32 UNC path like \\HOST\path
729
827
# clone to root should stop at least at \\HOST part
731
829
t = local.EmulatedWin32LocalTransport('file://HOST/path/to/some/dir/')
733
831
t = t.clone('..')
734
self.assertEquals(t.base, 'file://HOST/')
832
self.assertEqual(t.base, 'file://HOST/')
735
833
# make sure we reach the root
736
834
t = t.clone('..')
737
self.assertEquals(t.base, 'file://HOST/')
835
self.assertEqual(t.base, 'file://HOST/')
740
838
class TestConnectedTransport(tests.TestCase):
743
841
def test_parse_url(self):
744
842
t = transport.ConnectedTransport(
745
843
'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)
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)
752
self.assertEquals(t.base, 'http://simple.example.com/home/source/')
850
self.assertEqual(t.base, 'http://simple.example.com/home/source/')
754
852
def test_parse_url_with_at_in_user(self):
756
854
t = transport.ConnectedTransport('ftp://user@host.com@www.host.com/')
757
self.assertEquals(t._user, 'user@host.com')
855
self.assertEqual(t._parsed_url.user, 'user@host.com')
759
857
def test_parse_quoted_url(self):
760
858
t = transport.ConnectedTransport(
761
859
'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/')
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/')
768
866
# Base should not keep track of the password
769
self.assertEquals(t.base, 'http://robey@exAmple.com:2222/path/')
867
self.assertEqual(t.base, 'http://ro%62ey@ex%41mple.com:2222/path/')
771
869
def test_parse_invalid_url(self):
772
self.assertRaises(errors.InvalidURL,
870
self.assertRaises(urlutils.InvalidURL,
773
871
transport.ConnectedTransport,
774
872
'sftp://lily.org:~janneke/public/bzr/gub')
776
874
def test_relpath(self):
777
875
t = transport.ConnectedTransport('sftp://user@host.com/abs/path')
779
self.assertEquals(t.relpath('sftp://user@host.com/abs/path/sub'), 'sub')
877
self.assertEqual(t.relpath('sftp://user@host.com/abs/path/sub'),
780
879
self.assertRaises(errors.PathNotChild, t.relpath,
781
880
'http://user@host.com/abs/path/sub')
782
881
self.assertRaises(errors.PathNotChild, t.relpath,
787
886
'sftp://user@host.com:33/abs/path/sub')
788
887
# Make sure it works when we don't supply a username
789
888
t = transport.ConnectedTransport('sftp://host.com/abs/path')
790
self.assertEquals(t.relpath('sftp://host.com/abs/path/sub'), 'sub')
889
self.assertEqual(t.relpath('sftp://host.com/abs/path/sub'), 'sub')
792
891
# Make sure it works when parts of the path will be url encoded
793
892
t = transport.ConnectedTransport('sftp://host.com/dev/%path')
794
self.assertEquals(t.relpath('sftp://host.com/dev/%path/sub'), 'sub')
893
self.assertEqual(t.relpath('sftp://host.com/dev/%path/sub'), 'sub')
796
895
def test_connection_sharing_propagate_credentials(self):
797
896
t = transport.ConnectedTransport('ftp://user@host.com/abs/path')
798
self.assertEquals('user', t._user)
799
self.assertEquals('host.com', t._host)
897
self.assertEqual('user', t._parsed_url.user)
898
self.assertEqual('host.com', t._parsed_url.host)
800
899
self.assertIs(None, t._get_connection())
801
self.assertIs(None, t._password)
900
self.assertIs(None, t._parsed_url.password)
802
901
c = t.clone('subdir')
803
902
self.assertIs(None, c._get_connection())
804
self.assertIs(None, t._password)
903
self.assertIs(None, t._parsed_url.password)
806
905
# Simulate the user entering a password
807
906
password = 'secret'
827
926
def test_reuse_same_transport(self):
828
927
possible_transports = []
829
t1 = transport.get_transport('http://foo/',
830
possible_transports=possible_transports)
928
t1 = transport.get_transport_from_url(
929
'http://foo/', possible_transports=possible_transports)
831
930
self.assertEqual([t1], possible_transports)
832
t2 = transport.get_transport('http://foo/',
833
possible_transports=[t1])
931
t2 = transport.get_transport_from_url('http://foo/',
932
possible_transports=[t1])
834
933
self.assertIs(t1, t2)
836
935
# Also check that final '/' are handled correctly
837
t3 = transport.get_transport('http://foo/path/')
838
t4 = transport.get_transport('http://foo/path',
839
possible_transports=[t3])
936
t3 = transport.get_transport_from_url('http://foo/path/')
937
t4 = transport.get_transport_from_url('http://foo/path',
938
possible_transports=[t3])
840
939
self.assertIs(t3, t4)
842
t5 = transport.get_transport('http://foo/path')
843
t6 = transport.get_transport('http://foo/path/',
844
possible_transports=[t5])
941
t5 = transport.get_transport_from_url('http://foo/path')
942
t6 = transport.get_transport_from_url('http://foo/path/',
943
possible_transports=[t5])
845
944
self.assertIs(t5, t6)
847
946
def test_don_t_reuse_different_transport(self):
848
t1 = transport.get_transport('http://foo/path')
849
t2 = transport.get_transport('http://bar/path',
850
possible_transports=[t1])
947
t1 = transport.get_transport_from_url('http://foo/path')
948
t2 = transport.get_transport_from_url('http://bar/path',
949
possible_transports=[t1])
851
950
self.assertIsNot(t1, t2)
854
953
class TestTransportTrace(tests.TestCase):
857
t = transport.get_transport('trace+memory://')
858
self.assertIsInstance(t, bzrlib.transport.trace.TransportTraceDecorator)
955
def test_decorator(self):
956
t = transport.get_transport_from_url('trace+memory://')
957
self.assertIsInstance(
958
t, breezy.transport.trace.TransportTraceDecorator)
860
960
def test_clone_preserves_activity(self):
861
t = transport.get_transport('trace+memory://')
961
t = transport.get_transport_from_url('trace+memory://')
862
962
t2 = t.clone('.')
863
963
self.assertTrue(t is not t2)
864
964
self.assertTrue(t._activity is t2._activity)