73
73
transport._clear_protocol_handlers()
74
74
transport.register_transport_proto('foo')
75
75
transport.register_lazy_transport('foo',
76
'breezy.tests.test_transport',
77
'TestTransport.SampleHandler')
76
'breezy.tests.test_transport',
77
'TestTransport.SampleHandler')
78
78
transport.register_transport_proto('bar')
79
79
transport.register_lazy_transport('bar',
80
'breezy.tests.test_transport',
81
'TestTransport.SampleHandler')
80
'breezy.tests.test_transport',
81
'TestTransport.SampleHandler')
82
82
self.assertEqual([SampleHandler.__module__,
83
'breezy.transport.chroot',
84
'breezy.transport.pathfilter'],
85
transport._get_transport_modules())
83
'breezy.transport.chroot',
84
'breezy.transport.pathfilter'],
85
transport._get_transport_modules())
87
87
def test_transport_dependency(self):
88
88
"""Transport with missing dependency causes no error"""
180
180
def test_coalesce_overlapped(self):
181
181
self.assertRaises(ValueError,
182
self.check, [(0, 15, [(0, 10), (5, 10)])],
182
self.check, [(0, 15, [(0, 10), (5, 10)])],
185
185
def test_coalesce_limit(self):
186
186
self.check([(10, 50, [(0, 10), (10, 10), (20, 10),
187
187
(30, 10), (40, 10)]),
188
188
(60, 50, [(0, 10), (10, 10), (20, 10),
189
189
(30, 10), (40, 10)]),
190
], [(10, 10), (20, 10), (30, 10), (40, 10),
191
(50, 10), (60, 10), (70, 10), (80, 10),
192
(90, 10), (100, 10)],
190
], [(10, 10), (20, 10), (30, 10), (40, 10),
191
(50, 10), (60, 10), (70, 10), (80, 10),
192
(90, 10), (100, 10)],
195
195
def test_coalesce_no_limit(self):
196
196
self.check([(10, 100, [(0, 10), (10, 10), (20, 10),
197
197
(30, 10), (40, 10), (50, 10),
198
198
(60, 10), (70, 10), (80, 10),
200
], [(10, 10), (20, 10), (30, 10), (40, 10),
201
(50, 10), (60, 10), (70, 10), (80, 10),
202
(90, 10), (100, 10)])
200
], [(10, 10), (20, 10), (30, 10), (40, 10),
201
(50, 10), (60, 10), (70, 10), (80, 10),
202
(90, 10), (100, 10)])
204
204
def test_coalesce_fudge(self):
205
205
self.check([(10, 30, [(0, 10), (20, 10)]),
206
206
(100, 10, [(0, 10)]),
207
], [(10, 10), (30, 10), (100, 10)],
207
], [(10, 10), (30, 10), (100, 10)],
210
210
def test_coalesce_max_size(self):
212
212
(30, 50, [(0, 50)]),
213
213
# If one range is above max_size, it gets its own coalesced
215
(100, 80, [(0, 80)]),],
215
(100, 80, [(0, 80)]), ],
216
216
[(10, 10), (20, 10), (30, 50), (100, 80)],
219
219
def test_coalesce_no_max_size(self):
220
220
self.check([(10, 170, [(0, 10), (10, 10), (20, 50), (70, 100)])],
221
221
[(10, 10), (20, 10), (30, 50), (80, 100)],
224
224
def test_coalesce_default_limit(self):
225
225
# By default we use a 100MB max size.
226
226
ten_mb = 10 * 1024 * 1024
227
227
self.check([(0, 10 * ten_mb, [(i * ten_mb, ten_mb) for i in range(10)]),
228
(10*ten_mb, ten_mb, [(0, ten_mb)])],
229
[(i*ten_mb, ten_mb) for i in range(11)])
228
(10 * ten_mb, ten_mb, [(0, ten_mb)])],
229
[(i * ten_mb, ten_mb) for i in range(11)])
230
230
self.check([(0, 11 * ten_mb, [(i * ten_mb, ten_mb) for i in range(11)])],
231
231
[(i * ten_mb, ten_mb) for i in range(11)],
232
max_size=1*1024*1024*1024)
232
max_size=1 * 1024 * 1024 * 1024)
235
235
class TestMemoryServer(tests.TestCase):
457
457
"""Check all expected transport hook points are set up"""
458
458
hookpoint = transport.TransportHooks()
459
459
self.assertTrue("post_connect" in hookpoint,
460
"post_connect not in %s" % (hookpoint,))
460
"post_connect not in %s" % (hookpoint,))
462
462
def test_post_connect(self):
463
463
"""Ensure the post_connect hook is called when _set_transport is"""
465
465
transport.Transport.hooks.install_named_hook("post_connect",
467
467
t = self._get_connected_transport()
468
468
self.assertLength(0, calls)
469
469
t._set_connection("connection", "auth")
708
708
t = transport.get_transport_from_path(self.test_dir)
709
709
self.assertIsInstance(t, local.LocalTransport)
710
710
self.assertEqual(t.base.rstrip("/"),
711
urlutils.local_path_to_url(self.test_dir))
711
urlutils.local_path_to_url(self.test_dir))
713
713
def test_with_url(self):
714
714
t = transport.get_transport_from_path("file:")
715
715
self.assertIsInstance(t, local.LocalTransport)
716
716
self.assertEqual(t.base.rstrip("/"),
717
urlutils.local_path_to_url(os.path.join(self.test_dir, "file:")))
717
urlutils.local_path_to_url(os.path.join(self.test_dir, "file:")))
720
720
class TestTransportFromUrl(tests.TestCaseInTempDir):
722
722
def test_with_path(self):
723
723
self.assertRaises(urlutils.InvalidURL, transport.get_transport_from_url,
726
726
def test_with_url(self):
727
727
url = urlutils.local_path_to_url(self.test_dir)
923
924
def test_reuse_same_transport(self):
924
925
possible_transports = []
925
926
t1 = transport.get_transport_from_url('http://foo/',
926
possible_transports=possible_transports)
927
possible_transports=possible_transports)
927
928
self.assertEqual([t1], possible_transports)
928
929
t2 = transport.get_transport_from_url('http://foo/',
929
possible_transports=[t1])
930
possible_transports=[t1])
930
931
self.assertIs(t1, t2)
932
933
# Also check that final '/' are handled correctly
933
934
t3 = transport.get_transport_from_url('http://foo/path/')
934
935
t4 = transport.get_transport_from_url('http://foo/path',
935
possible_transports=[t3])
936
possible_transports=[t3])
936
937
self.assertIs(t3, t4)
938
939
t5 = transport.get_transport_from_url('http://foo/path')
939
940
t6 = transport.get_transport_from_url('http://foo/path/',
940
possible_transports=[t5])
941
possible_transports=[t5])
941
942
self.assertIs(t5, t6)
943
944
def test_don_t_reuse_different_transport(self):
944
945
t1 = transport.get_transport_from_url('http://foo/path')
945
946
t2 = transport.get_transport_from_url('http://bar/path',
946
possible_transports=[t1])
947
possible_transports=[t1])
947
948
self.assertIsNot(t1, t2)