168
168
def test_clone(self):
169
169
transport = MemoryTransport()
170
170
self.assertTrue(isinstance(transport, MemoryTransport))
171
self.assertEqual("memory:///", transport.clone("/").base)
172
173
def test_abspath(self):
173
174
transport = MemoryTransport()
174
175
self.assertEqual("memory:///relpath", transport.abspath('relpath'))
177
def test_abspath_of_root(self):
178
transport = MemoryTransport()
179
self.assertEqual("memory:///", transport.base)
180
self.assertEqual("memory:///", transport.abspath('/'))
176
182
def test_relpath(self):
177
183
transport = MemoryTransport()
179
185
def test_append_and_get(self):
180
186
transport = MemoryTransport()
181
transport.append('path', StringIO('content'))
187
transport.append_bytes('path', 'content')
182
188
self.assertEqual(transport.get('path').read(), 'content')
183
transport.append('path', StringIO('content'))
189
transport.append_file('path', StringIO('content'))
184
190
self.assertEqual(transport.get('path').read(), 'contentcontent')
186
192
def test_put_and_get(self):
187
193
transport = MemoryTransport()
188
transport.put('path', StringIO('content'))
194
transport.put_file('path', StringIO('content'))
189
195
self.assertEqual(transport.get('path').read(), 'content')
190
transport.put('path', StringIO('content'))
196
transport.put_bytes('path', 'content')
191
197
self.assertEqual(transport.get('path').read(), 'content')
193
199
def test_append_without_dir_fails(self):
194
200
transport = MemoryTransport()
195
201
self.assertRaises(NoSuchFile,
196
transport.append, 'dir/path', StringIO('content'))
202
transport.append_bytes, 'dir/path', 'content')
198
204
def test_put_without_dir_fails(self):
199
205
transport = MemoryTransport()
200
206
self.assertRaises(NoSuchFile,
201
transport.put, 'dir/path', StringIO('content'))
207
transport.put_file, 'dir/path', StringIO('content'))
203
209
def test_get_missing(self):
204
210
transport = MemoryTransport()
211
217
def test_has_present(self):
212
218
transport = MemoryTransport()
213
transport.append('foo', StringIO('content'))
219
transport.append_bytes('foo', 'content')
214
220
self.assertEquals(True, transport.has('foo'))
216
222
def test_mkdir(self):
217
223
transport = MemoryTransport()
218
224
transport.mkdir('dir')
219
transport.append('dir/path', StringIO('content'))
225
transport.append_bytes('dir/path', 'content')
220
226
self.assertEqual(transport.get('dir/path').read(), 'content')
222
228
def test_mkdir_missing_parent(self):
238
244
def test_iter_files_recursive(self):
239
245
transport = MemoryTransport()
240
246
transport.mkdir('dir')
241
transport.put('dir/foo', StringIO('content'))
242
transport.put('dir/bar', StringIO('content'))
243
transport.put('bar', StringIO('content'))
247
transport.put_bytes('dir/foo', 'content')
248
transport.put_bytes('dir/bar', 'content')
249
transport.put_bytes('bar', 'content')
244
250
paths = set(transport.iter_files_recursive())
245
251
self.assertEqual(set(['dir/foo', 'dir/bar', 'bar']), paths)
247
253
def test_stat(self):
248
254
transport = MemoryTransport()
249
transport.put('foo', StringIO('content'))
250
transport.put('bar', StringIO('phowar'))
255
transport.put_bytes('foo', 'content')
256
transport.put_bytes('bar', 'phowar')
251
257
self.assertEqual(7, transport.stat('foo').st_size)
252
258
self.assertEqual(6, transport.stat('bar').st_size)