87
96
tester.assertEqual(list(t.has_multi(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'])),
88
97
[True, True, True, True, True, False, True, False])
89
tester.assertEqual(open('a').read(), 'new\ncontents for\na\n')
90
tester.assertEqual(open('d').read(), 'contents\nfor d\n')
98
tester.check_file_contents('a', 'new\ncontents for\na\n')
99
tester.check_file_contents('d', 'contents\nfor d\n')
93
102
open('a', 'wb').write('diff\ncontents for\na\n')
164
173
tester.assertEquals(open(f).read(), open(os.path.join(dtmp_base, f)).read())
177
# Test append, and append_multi
179
_append('a', 'add\nsome\nmore\ncontents\n')
181
t.append('a', 'add\nsome\nmore\ncontents\n')
183
tester.check_file_contents('a',
184
'diff\ncontents for\na\nadd\nsome\nmore\ncontents\n')
187
_append('a', 'and\nthen\nsome\nmore\n')
188
_append('d', 'some\nmore\nfor\nd\n')
190
t.append_multi([('a', 'and\nthen\nsome\nmore\n'),
191
('d', 'some\nmore\nfor\nd\n')])
192
tester.check_file_contents('a',
193
'diff\ncontents for\na\n'
194
'add\nsome\nmore\ncontents\n'
195
'and\nthen\nsome\nmore\n')
196
tester.check_file_contents('d',
197
'another contents\nfor d\n'
198
'some\nmore\nfor\nd\n')
200
# Test that StringIO can be used as a file-like object with put
201
f1 = StringIO('this is a string\nand some more stuff\n')
203
open('f1', 'wb').write(f1.read())
209
tester.check_file_contents('f1',
210
'this is a string\nand some more stuff\n')
212
f2 = StringIO('here is some text\nand a bit more\n')
213
f3 = StringIO('some text for the\nthird file created\n')
216
open('f2', 'wb').write(f2.read())
217
open('f3', 'wb').write(f3.read())
219
t.put_multi([('f2', f2), ('f3', f3)])
223
tester.check_file_contents('f2', 'here is some text\nand a bit more\n')
224
tester.check_file_contents('f3', 'some text for the\nthird file created\n')
226
# Test that an actual file object can be used with put
227
f4 = open('f1', 'rb')
229
open('f4', 'wb').write(f4.read())
235
tester.check_file_contents('f4',
236
'this is a string\nand some more stuff\n')
238
f5 = open('f2', 'rb')
239
f6 = open('f3', 'rb')
241
open('f5', 'wb').write(f5.read())
242
open('f6', 'wb').write(f6.read())
244
t.put_multi([('f5', f5), ('f6', f6)])
248
tester.check_file_contents('f5', 'here is some text\nand a bit more\n')
249
tester.check_file_contents('f6', 'some text for the\nthird file created\n')
251
# Test that StringIO can be used as a file-like object with append
252
a1 = StringIO('appending to\none\n')
254
_append('f1', a1.read())
260
tester.check_file_contents('f1',
261
'this is a string\nand some more stuff\n'
262
'appending to\none\n')
264
a2 = StringIO('adding more\ntext to two\n')
265
a3 = StringIO('some garbage\nto put in three\n')
268
_append('f2', a2.read())
269
_append('f3', a3.read())
271
t.append_multi([('f2', a2), ('f3', a3)])
275
tester.check_file_contents('f2',
276
'here is some text\nand a bit more\n'
277
'adding more\ntext to two\n')
278
tester.check_file_contents('f3',
279
'some text for the\nthird file created\n'
280
'some garbage\nto put in three\n')
282
# Test that an actual file object can be used with put
283
a4 = open('f1', 'rb')
285
_append('f4', a4.read())
291
tester.check_file_contents('f4',
292
'this is a string\nand some more stuff\n'
293
'this is a string\nand some more stuff\n'
294
'appending to\none\n')
296
a5 = open('f2', 'rb')
297
a6 = open('f3', 'rb')
299
_append('f5', a5.read())
300
_append('f6', a6.read())
302
t.append_multi([('f5', a5), ('f6', a6)])
306
tester.check_file_contents('f5',
307
'here is some text\nand a bit more\n'
308
'here is some text\nand a bit more\n'
309
'adding more\ntext to two\n')
310
tester.check_file_contents('f6',
311
'some text for the\nthird file created\n'
312
'some text for the\nthird file created\n'
313
'some garbage\nto put in three\n')
167
315
# TODO: Make sure all entries support file-like objects as well as strings.
168
316
# TODO: Test get_partial()