~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

  • Committer: Martin Pool
  • Date: 2006-03-09 07:59:36 UTC
  • mfrom: (1601 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1602.
  • Revision ID: mbp@sourcefrog.net-20060309075936-c13ae6445966956e
[merge] from bzr.dev

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
 
from bzrlib.transactions import PassThroughTransaction
30
30
 
31
31
 
32
32
class KnitTests(TestCaseInTempDir):
258
258
        self.assertEquals(lines, ['z\n', 'c\n'])
259
259
 
260
260
        origins = k1.annotate('text-c')
261
 
        self.assertEquals(origins[0], ('text-c', 'z\n')) 
262
 
        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)
 
311
        
 
312
    def test_iter_lines_reads_in_order(self):
 
313
        t = MemoryTransport()
 
314
        instrumented_t = TransportLogger(t)
 
315
        k1 = KnitVersionedFile('id', instrumented_t, create=True, delta=True)
 
316
        self.assertEqual([('id.kndx',)], instrumented_t._calls)
 
317
        # add texts with no required ordering
 
318
        k1.add_lines('base', [], ['text\n'])
 
319
        k1.add_lines('base2', [], ['text2\n'])
 
320
        k1.clear_cache()
 
321
        instrumented_t._calls = []
 
322
        # request a last-first iteration
 
323
        results = list(k1.iter_lines_added_or_present_in_versions(['base2', 'base']))
 
324
        self.assertEqual([('id.knit', [(0, 87), (87, 89)])], instrumented_t._calls)
 
325
        self.assertEqual(['text\n', 'text2\n'], results)
263
326
 
264
327
    def test_create_empty_annotated(self):
265
328
        k1 = self.make_test_knit(True)