101
105
_set_protocol_handlers(saved_handlers)
107
def test__combine_paths(self):
109
self.assertEqual('/home/sarah/project/foo',
110
t._combine_paths('/home/sarah', 'project/foo'))
111
self.assertEqual('/etc',
112
t._combine_paths('/home/sarah', '../../etc'))
113
self.assertEqual('/etc',
114
t._combine_paths('/home/sarah', '../../../etc'))
115
self.assertEqual('/etc',
116
t._combine_paths('/home/sarah', '/etc'))
104
119
class TestCoalesceOffsets(TestCase):
168
183
def test_clone(self):
169
184
transport = MemoryTransport()
170
185
self.assertTrue(isinstance(transport, MemoryTransport))
186
self.assertEqual("memory:///", transport.clone("/").base)
172
188
def test_abspath(self):
173
189
transport = MemoryTransport()
174
190
self.assertEqual("memory:///relpath", transport.abspath('relpath'))
176
def test_relpath(self):
177
transport = MemoryTransport()
192
def test_abspath_of_root(self):
193
transport = MemoryTransport()
194
self.assertEqual("memory:///", transport.base)
195
self.assertEqual("memory:///", transport.abspath('/'))
197
def test_abspath_of_relpath_starting_at_root(self):
198
transport = MemoryTransport()
199
self.assertEqual("memory:///foo", transport.abspath('/foo'))
179
201
def test_append_and_get(self):
180
202
transport = MemoryTransport()
181
transport.append('path', StringIO('content'))
203
transport.append_bytes('path', 'content')
182
204
self.assertEqual(transport.get('path').read(), 'content')
183
transport.append('path', StringIO('content'))
205
transport.append_file('path', StringIO('content'))
184
206
self.assertEqual(transport.get('path').read(), 'contentcontent')
186
208
def test_put_and_get(self):
187
209
transport = MemoryTransport()
188
transport.put('path', StringIO('content'))
210
transport.put_file('path', StringIO('content'))
189
211
self.assertEqual(transport.get('path').read(), 'content')
190
transport.put('path', StringIO('content'))
212
transport.put_bytes('path', 'content')
191
213
self.assertEqual(transport.get('path').read(), 'content')
193
215
def test_append_without_dir_fails(self):
194
216
transport = MemoryTransport()
195
217
self.assertRaises(NoSuchFile,
196
transport.append, 'dir/path', StringIO('content'))
218
transport.append_bytes, 'dir/path', 'content')
198
220
def test_put_without_dir_fails(self):
199
221
transport = MemoryTransport()
200
222
self.assertRaises(NoSuchFile,
201
transport.put, 'dir/path', StringIO('content'))
223
transport.put_file, 'dir/path', StringIO('content'))
203
225
def test_get_missing(self):
204
226
transport = MemoryTransport()
211
233
def test_has_present(self):
212
234
transport = MemoryTransport()
213
transport.append('foo', StringIO('content'))
235
transport.append_bytes('foo', 'content')
214
236
self.assertEquals(True, transport.has('foo'))
216
238
def test_mkdir(self):
217
239
transport = MemoryTransport()
218
240
transport.mkdir('dir')
219
transport.append('dir/path', StringIO('content'))
241
transport.append_bytes('dir/path', 'content')
220
242
self.assertEqual(transport.get('dir/path').read(), 'content')
222
244
def test_mkdir_missing_parent(self):
238
260
def test_iter_files_recursive(self):
239
261
transport = MemoryTransport()
240
262
transport.mkdir('dir')
241
transport.put('dir/foo', StringIO('content'))
242
transport.put('dir/bar', StringIO('content'))
243
transport.put('bar', StringIO('content'))
263
transport.put_bytes('dir/foo', 'content')
264
transport.put_bytes('dir/bar', 'content')
265
transport.put_bytes('bar', 'content')
244
266
paths = set(transport.iter_files_recursive())
245
267
self.assertEqual(set(['dir/foo', 'dir/bar', 'bar']), paths)
247
269
def test_stat(self):
248
270
transport = MemoryTransport()
249
transport.put('foo', StringIO('content'))
250
transport.put('bar', StringIO('phowar'))
271
transport.put_bytes('foo', 'content')
272
transport.put_bytes('bar', 'phowar')
251
273
self.assertEqual(7, transport.stat('foo').st_size)
252
274
self.assertEqual(6, transport.stat('bar').st_size)
319
341
server = fakenfs.FakeNFSServer()
322
# the server should be a relpath localhost server
323
self.assertEqual(server.get_url(), 'fakenfs+.')
344
# the url should be decorated appropriately
345
self.assertStartsWith(server.get_url(), 'fakenfs+')
324
346
# and we should be able to get a transport for it
325
347
transport = get_transport(server.get_url())
326
348
# which must be a FakeNFSTransportDecorator instance.
409
431
base_url = self._server.get_url()
410
432
# try getting the transport via the regular interface:
411
433
t = get_transport(base_url)
412
if not isinstance(t, self.transport_class):
434
if not isinstance(t, self.transport_class):
413
435
# we did not get the correct transport class type. Override the
414
436
# regular connection behaviour by direct construction.
415
437
t = self.transport_class(base_url)
441
class TestLocalTransports(TestCase):
443
def test_get_transport_from_abspath(self):
444
here = os.path.abspath('.')
445
t = get_transport(here)
446
self.assertIsInstance(t, LocalTransport)
447
self.assertEquals(t.base, urlutils.local_path_to_url(here) + '/')
449
def test_get_transport_from_relpath(self):
450
here = os.path.abspath('.')
451
t = get_transport('.')
452
self.assertIsInstance(t, LocalTransport)
453
self.assertEquals(t.base, urlutils.local_path_to_url('.') + '/')
455
def test_get_transport_from_local_url(self):
456
here = os.path.abspath('.')
457
here_url = urlutils.local_path_to_url(here) + '/'
458
t = get_transport(here_url)
459
self.assertIsInstance(t, LocalTransport)
460
self.assertEquals(t.base, here_url)