391
391
self.assertEqual('', get_bytes(99))
394
class TestReadvReader(tests.TestCaseWithTransport):
396
def test_read_skipping_records(self):
397
pack_data = StringIO()
398
writer = pack.ContainerWriter(pack_data.write)
401
memos.append(writer.add_bytes_record('abc', names=[]))
402
memos.append(writer.add_bytes_record('def', names=['name1']))
403
memos.append(writer.add_bytes_record('ghi', names=['name2']))
404
memos.append(writer.add_bytes_record('jkl', names=[]))
406
transport = self.get_transport()
408
transport.put_file('mypack', pack_data)
409
requested_records = [memos[0], memos[2]]
410
reader = pack.make_readv_reader(transport, 'mypack', requested_records)
412
for names, reader_func in reader.iter_records():
413
result.append((names, reader_func(None)))
414
self.assertEqual([([], 'abc'), (['name2'], 'ghi')], result)
417
class TestReadvFile(tests.TestCaseWithTransport):
419
def test_read_bytes(self):
420
# this tests byte reading - solo, all in a hunk at once
421
transport = self.get_transport()
422
transport.put_bytes('sample', '0123456789')
423
f = pack.ReadVFile(transport.readv('sample', [(0,1), (1,2), (4,1), (6,2)]))
425
results.append(f.read(1))
426
results.append(f.read(2))
427
results.append(f.read(1))
428
results.append(f.read(1))
429
results.append(f.read(1))
430
self.assertEqual(['0', '12', '4', '6', '7'], results)
432
def test_readline(self):
433
# this tests readline as the ContainerReader needs it -
434
# just within a record, never across.
435
transport = self.get_transport()
436
transport.put_bytes('sample', '0\n2\n4\n')
437
f = pack.ReadVFile(transport.readv('sample', [(0,2), (2,4)]))
439
results.append(f.readline())
440
results.append(f.readline())
441
results.append(f.readline())
442
self.assertEqual(['0\n', '2\n', '4\n'], results)
444
def test_readline_and_read(self):
445
# this tests read, then readline, then read again
446
transport = self.get_transport()
447
transport.put_bytes('sample', '0\n2\n4\n')
448
f = pack.ReadVFile(transport.readv('sample', [(0,6)]))
450
results.append(f.read(1))
451
results.append(f.readline())
452
results.append(f.read(4))
453
self.assertEqual(['0', '\n', '2\n4\n'], results)