165
165
access = self.get_access()
166
166
memos = access.add_raw_records([10], '1234567890')
167
167
self.assertEqual(['1234567890'], list(access.get_raw_records(memos)))
169
def test_add_several_raw_records(self):
170
"""add_raw_records with many records and read some back."""
171
access = self.get_access()
172
memos = access.add_raw_records([10, 2, 5], '12345678901234567')
173
self.assertEqual(['1234567890', '12', '34567'],
174
list(access.get_raw_records(memos)))
175
self.assertEqual(['1234567890'],
176
list(access.get_raw_records(memos[0:1])))
177
self.assertEqual(['12'],
178
list(access.get_raw_records(memos[1:2])))
179
self.assertEqual(['34567'],
180
list(access.get_raw_records(memos[2:3])))
181
self.assertEqual(['1234567890', '34567'],
182
list(access.get_raw_records(memos[0:1] + memos[2:3])))
169
184
def test_create(self):
170
185
"""create() should make a file on disk."""
171
186
access = self.get_access()
177
192
access = self.get_access()
178
193
access.open_file()
180
# what is the key interface elements - what code do I want to write:
182
# here is a raw record. please write it somewhere and return the readv I should
183
# make to get it back.
184
# here are many records -> returns many readvs
185
# here is a readv I was given earlier, please return the raw data
188
196
class TestKnitKnitAccess(TestCaseWithMemoryTransport, KnitRecordAccessTestsMixin):
189
197
"""Tests for the .kndx implementation."""
209
217
def get_access(self):
218
return self._get_access()[0]
220
def _get_access(self, packname='packfile', index='FOO'):
210
221
transport = self.get_transport()
211
222
def write_data(bytes):
212
transport.append_bytes('packfile', bytes)
223
transport.append_bytes(packname, bytes)
213
224
writer = pack.ContainerWriter(write_data)
216
indices = {"FOO":(transport, 'packfile')}
217
access = _PackAccess(indices, writer=(writer, 'FOO'))
226
indices = {index:(transport, packname)}
227
access = _PackAccess(indices, writer=(writer, index))
228
return access, writer
221
# - add several records
222
# - read from several packs
223
# - add data readonly?
230
def test_read_from_several_packs(self):
231
access, writer = self._get_access()
233
memos.extend(access.add_raw_records([10], '1234567890'))
235
access, writer = self._get_access('pack2', 'FOOBAR')
236
memos.extend(access.add_raw_records([5], '12345'))
238
access, writer = self._get_access('pack3', 'BAZ')
239
memos.extend(access.add_raw_records([5], 'alpha'))
241
transport = self.get_transport()
242
access = _PackAccess({"FOO":(transport, 'packfile'),
243
"FOOBAR":(transport, 'pack2'),
244
"BAZ":(transport, 'pack3')})
245
self.assertEqual(['1234567890', '12345', 'alpha'],
246
list(access.get_raw_records(memos)))
247
self.assertEqual(['1234567890'],
248
list(access.get_raw_records(memos[0:1])))
249
self.assertEqual(['12345'],
250
list(access.get_raw_records(memos[1:2])))
251
self.assertEqual(['alpha'],
252
list(access.get_raw_records(memos[2:3])))
253
self.assertEqual(['1234567890', 'alpha'],
254
list(access.get_raw_records(memos[0:1] + memos[2:3])))
226
257
class LowLevelKnitDataTests(TestCase):