~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

  • Committer: Robert Collins
  • Date: 2007-08-02 07:08:32 UTC
  • mto: (2592.5.3 pack-repository)
  • mto: This revision was merged to the branch mainline in revision 2933.
  • Revision ID: robertc@robertcollins.net-20070802070832-5m0oapk9ian9h5q1
More tests for bzrlib.knit._PackAccess.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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)))
168
 
    
 
168
 
 
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])))
 
183
 
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()
179
194
 
180
 
# what is the key interface elements - what code do I want to write:
181
 
# insertion:
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
186
 
 
187
195
 
188
196
class TestKnitKnitAccess(TestCaseWithMemoryTransport, KnitRecordAccessTestsMixin):
189
197
    """Tests for the .kndx implementation."""
207
215
        pass
208
216
 
209
217
    def get_access(self):
 
218
        return self._get_access()[0]
 
219
 
 
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)
214
225
        writer.begin()
215
 
        index = "FOO"
216
 
        indices = {"FOO":(transport, 'packfile')}
217
 
        access = _PackAccess(indices, writer=(writer, 'FOO'))
218
 
        return access
 
226
        indices = {index:(transport, packname)}
 
227
        access = _PackAccess(indices, writer=(writer, index))
 
228
        return access, writer
219
229
 
220
 
# missing tests:
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()
 
232
        memos = []
 
233
        memos.extend(access.add_raw_records([10], '1234567890'))
 
234
        writer.end()
 
235
        access, writer = self._get_access('pack2', 'FOOBAR')
 
236
        memos.extend(access.add_raw_records([5], '12345'))
 
237
        writer.end()
 
238
        access, writer = self._get_access('pack3', 'BAZ')
 
239
        memos.extend(access.add_raw_records([5], 'alpha'))
 
240
        writer.end()
 
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])))
224
255
 
225
256
 
226
257
class LowLevelKnitDataTests(TestCase):