/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

Make use of the transaction finalisation warning support to implement in-knit caching.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
from bzrlib.knit import KnitVersionedFile, KnitPlainFactory, KnitAnnotateFactory
25
25
from bzrlib.osutils import split_lines
26
26
from bzrlib.tests import TestCaseInTempDir
 
27
from bzrlib.transport import TransportLogger
27
28
from bzrlib.transport.local import LocalTransport
28
29
from bzrlib.transport.memory import MemoryTransport
29
30
 
257
258
        self.assertEquals(lines, ['z\n', 'c\n'])
258
259
 
259
260
        origins = k1.annotate('text-c')
260
 
        self.assertEquals(origins[0], ('text-c', 'z\n')) 
261
 
        self.assertEquals(origins[1], ('text-b', 'c\n')) 
 
261
        self.assertEquals(origins[0], ('text-c', 'z\n'))
 
262
        self.assertEquals(origins[1], ('text-b', 'c\n'))
 
263
 
 
264
    def test_extraction_reads_components_once(self):
 
265
        t = MemoryTransport()
 
266
        instrumented_t = TransportLogger(t)
 
267
        k1 = KnitVersionedFile('id', instrumented_t, create=True, delta=True)
 
268
        # should read the index
 
269
        self.assertEqual([('id.kndx',)], instrumented_t._calls)
 
270
        instrumented_t._calls = []
 
271
        # add a text       
 
272
        k1.add_lines('base', [], ['text\n'])
 
273
        # should not have read at all
 
274
        self.assertEqual([], instrumented_t._calls)
 
275
 
 
276
        # add a text
 
277
        k1.add_lines('sub', ['base'], ['text\n', 'text2\n'])
 
278
        # should not have read at all
 
279
        self.assertEqual([], instrumented_t._calls)
 
280
        
 
281
        # read a text
 
282
        k1.get_lines('sub')
 
283
        # should not have read at all
 
284
        self.assertEqual([], instrumented_t._calls)
 
285
 
 
286
        # clear the cache
 
287
        k1.clear_cache()
 
288
 
 
289
        # read a text
 
290
        k1.get_lines('base')
 
291
        # should have read a component
 
292
        # should not have read the first component only
 
293
        self.assertEqual([('id.knit', [(0, 87)])], instrumented_t._calls)
 
294
        instrumented_t._calls = []
 
295
        # read again
 
296
        k1.get_lines('base')
 
297
        # should not have read at all
 
298
        self.assertEqual([], instrumented_t._calls)
 
299
        # and now read the other component
 
300
        k1.get_lines('sub')
 
301
        # should have read the second component
 
302
        self.assertEqual([('id.knit', [(87, 92)])], instrumented_t._calls)
 
303
        instrumented_t._calls = []
 
304
 
 
305
        # clear the cache
 
306
        k1.clear_cache()
 
307
        # add a text cold 
 
308
        k1.add_lines('sub2', ['base'], ['text\n', 'text3\n'])
 
309
        # should read the first component only
 
310
        self.assertEqual([('id.knit', [(0, 87)])], instrumented_t._calls)
262
311
 
263
312
    def test_create_empty_annotated(self):
264
313
        k1 = self.make_test_knit(True)