67
60
_get_transport_modules())
69
62
_set_protocol_handlers(handlers)
71
def test_transport_dependency(self):
72
"""Transport with missing dependency causes no error"""
73
saved_handlers = _get_protocol_handlers()
75
register_lazy_transport('foo', 'bzrlib.tests.test_transport',
76
'BadTransportHandler')
77
t = get_transport('foo://fooserver/foo')
78
# because we failed to load the transport
79
self.assertTrue(isinstance(t, LocalTransport))
81
# restore original values
82
_set_protocol_handlers(saved_handlers)
84
def test_transport_fallback(self):
85
"""Transport with missing dependency causes no error"""
86
saved_handlers = _get_protocol_handlers()
88
_set_protocol_handlers({})
89
register_lazy_transport('foo', 'bzrlib.tests.test_transport',
90
'BackupTransportHandler')
91
register_lazy_transport('foo', 'bzrlib.tests.test_transport',
92
'BadTransportHandler')
93
t = get_transport('foo://fooserver/foo')
94
self.assertTrue(isinstance(t, BackupTransportHandler))
96
_set_protocol_handlers(saved_handlers)
99
class TestMemoryTransport(TestCase):
101
def test_get_transport(self):
104
def test_clone(self):
105
transport = MemoryTransport()
106
self.assertTrue(isinstance(transport, MemoryTransport))
108
def test_abspath(self):
109
transport = MemoryTransport()
110
self.assertEqual("memory:/relpath", transport.abspath('relpath'))
112
def test_relpath(self):
113
transport = MemoryTransport()
115
def test_append_and_get(self):
116
transport = MemoryTransport()
117
transport.append('path', StringIO('content'))
118
self.assertEqual(transport.get('path').read(), 'content')
119
transport.append('path', StringIO('content'))
120
self.assertEqual(transport.get('path').read(), 'contentcontent')
122
def test_put_and_get(self):
123
transport = MemoryTransport()
124
transport.put('path', StringIO('content'))
125
self.assertEqual(transport.get('path').read(), 'content')
126
transport.put('path', StringIO('content'))
127
self.assertEqual(transport.get('path').read(), 'content')
129
def test_append_without_dir_fails(self):
130
transport = MemoryTransport()
131
self.assertRaises(NoSuchFile,
132
transport.append, 'dir/path', StringIO('content'))
134
def test_put_without_dir_fails(self):
135
transport = MemoryTransport()
136
self.assertRaises(NoSuchFile,
137
transport.put, 'dir/path', StringIO('content'))
139
def test_get_missing(self):
140
transport = MemoryTransport()
141
self.assertRaises(NoSuchFile, transport.get, 'foo')
143
def test_has_missing(self):
144
transport = MemoryTransport()
145
self.assertEquals(False, transport.has('foo'))
147
def test_has_present(self):
148
transport = MemoryTransport()
149
transport.append('foo', StringIO('content'))
150
self.assertEquals(True, transport.has('foo'))
152
def test_mkdir(self):
153
transport = MemoryTransport()
154
transport.mkdir('dir')
155
transport.append('dir/path', StringIO('content'))
156
self.assertEqual(transport.get('dir/path').read(), 'content')
158
def test_mkdir_missing_parent(self):
159
transport = MemoryTransport()
160
self.assertRaises(NoSuchFile,
161
transport.mkdir, 'dir/dir')
163
def test_mkdir_twice(self):
164
transport = MemoryTransport()
165
transport.mkdir('dir')
166
self.assertRaises(FileExists, transport.mkdir, 'dir')
65
class MemoryTransportTest(TestCase):
66
"""Memory transport specific tests."""
168
68
def test_parameters(self):
169
transport = MemoryTransport()
69
import bzrlib.transport.memory as memory
70
transport = memory.MemoryTransport()
170
71
self.assertEqual(True, transport.listable())
171
72
self.assertEqual(False, transport.should_cache())
172
73
self.assertEqual(False, transport.is_readonly())
174
def test_iter_files_recursive(self):
175
transport = MemoryTransport()
176
transport.mkdir('dir')
177
transport.put('dir/foo', StringIO('content'))
178
transport.put('dir/bar', StringIO('content'))
179
transport.put('bar', StringIO('content'))
180
paths = set(transport.iter_files_recursive())
181
self.assertEqual(set(['dir/foo', 'dir/bar', 'bar']), paths)
184
transport = MemoryTransport()
185
transport.put('foo', StringIO('content'))
186
transport.put('bar', StringIO('phowar'))
187
self.assertEqual(7, transport.stat('foo').st_size)
188
self.assertEqual(6, transport.stat('bar').st_size)
191
76
class ReadonlyDecoratorTransportTest(TestCase):
192
77
"""Readonly decoration specific tests."""
214
99
self.assertEqual(True, transport.is_readonly())
216
101
server.tearDown()
219
class FakeNFSDecoratorTests(TestCaseInTempDir):
220
"""NFS decorator specific tests."""
222
def get_nfs_transport(self, url):
223
import bzrlib.transport.fakenfs as fakenfs
224
# connect to url with nfs decoration
225
return fakenfs.FakeNFSTransportDecorator('fakenfs+' + url)
227
def test_local_parameters(self):
228
# the listable, should_cache and is_readonly parameters
229
# are not changed by the fakenfs decorator
230
transport = self.get_nfs_transport('.')
231
self.assertEqual(True, transport.listable())
232
self.assertEqual(False, transport.should_cache())
233
self.assertEqual(False, transport.is_readonly())
235
def test_http_parameters(self):
236
# the listable, should_cache and is_readonly parameters
237
# are not changed by the fakenfs decorator
238
from bzrlib.transport.http import HttpServer
239
# connect to . via http which is not listable
240
server = HttpServer()
243
transport = self.get_nfs_transport(server.get_url())
244
self.assertIsInstance(
245
transport, bzrlib.transport.fakenfs.FakeNFSTransportDecorator)
246
self.assertEqual(False, transport.listable())
247
self.assertEqual(True, transport.should_cache())
248
self.assertEqual(True, transport.is_readonly())
252
def test_fakenfs_server_default(self):
253
# a FakeNFSServer() should bring up a local relpath server for itself
254
import bzrlib.transport.fakenfs as fakenfs
255
server = fakenfs.FakeNFSServer()
258
# the server should be a relpath localhost server
259
self.assertEqual(server.get_url(), 'fakenfs+.')
260
# and we should be able to get a transport for it
261
transport = get_transport(server.get_url())
262
# which must be a FakeNFSTransportDecorator instance.
263
self.assertIsInstance(
264
transport, fakenfs.FakeNFSTransportDecorator)
268
def test_fakenfs_rename_semantics(self):
269
# a FakeNFS transport must mangle the way rename errors occur to
270
# look like NFS problems.
271
transport = self.get_nfs_transport('.')
272
self.build_tree(['from/', 'from/foo', 'to/', 'to/bar'],
274
self.assertRaises(bzrlib.errors.ResourceBusy,
275
transport.rename, 'from', 'to')
278
class FakeVFATDecoratorTests(TestCaseInTempDir):
279
"""Tests for simulation of VFAT restrictions"""
281
def get_vfat_transport(self, url):
282
"""Return vfat-backed transport for test directory"""
283
from bzrlib.transport.fakevfat import FakeVFATTransportDecorator
284
return FakeVFATTransportDecorator('vfat+' + url)
286
def test_transport_creation(self):
287
from bzrlib.transport.fakevfat import FakeVFATTransportDecorator
288
transport = self.get_vfat_transport('.')
289
self.assertIsInstance(transport, FakeVFATTransportDecorator)
291
def test_transport_mkdir(self):
292
transport = self.get_vfat_transport('.')
293
transport.mkdir('HELLO')
294
self.assertTrue(transport.has('hello'))
295
self.assertTrue(transport.has('Hello'))
297
def test_forbidden_chars(self):
298
transport = self.get_vfat_transport('.')
299
self.assertRaises(ValueError, transport.has, "<NU>")
302
class BadTransportHandler(Transport):
303
def __init__(self, base_url):
304
raise DependencyNotPresent('some_lib', 'testing missing dependency')
307
class BackupTransportHandler(Transport):
308
"""Test transport that works as a backup for the BadTransportHandler"""