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