~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_repository.py

  • Committer: Andrew Bennetts
  • Date: 2007-08-30 05:54:15 UTC
  • mto: (2535.4.4 streaming-smart-fetch)
  • mto: This revision was merged to the branch mainline in revision 2906.
  • Revision ID: andrew.bennetts@canonical.com-20070830055415-rqqvz71feo5akhcz
Remove get_stream_as_bytes from KnitVersionedFile's API, make it a function in knitrepo.py instead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
from bzrlib.repository import RepositoryFormat
35
35
from bzrlib.smart import server
36
36
from bzrlib.tests import TestCase, TestCaseWithTransport
 
37
from bzrlib.tests import test_knit
37
38
from bzrlib.transport import get_transport
38
39
from bzrlib.transport.memory import MemoryServer
 
40
from bzrlib.util import bencode
39
41
from bzrlib import (
40
42
    bzrdir,
41
43
    errors,
339
341
        self.check_knits(t)
340
342
 
341
343
 
 
344
class KnitRepositoryStreamTests(test_knit.KnitTests):
 
345
    """Tests for knitrepo._get_stream_as_bytes."""
 
346
 
 
347
    def test_get_stream_as_bytes(self):
 
348
        # Make a simple knit
 
349
        k1 = self.make_test_knit()
 
350
        k1.add_lines('text-a', [], test_knit.split_lines(test_knit.TEXT_1))
 
351
        
 
352
        # Serialise it, check the output.
 
353
        bytes = knitrepo._get_stream_as_bytes(k1, ['text-a'])
 
354
        data = bencode.bdecode(bytes)
 
355
        format, record = data
 
356
        self.assertEqual('knit-plain', format)
 
357
        self.assertEqual(['text-a', ['fulltext'], []], record[:3])
 
358
        self.assertRecordContentEqual(k1, 'text-a', record[3])
 
359
 
 
360
    def test_get_stream_as_bytes_all(self):
 
361
        """Get a serialised data stream for all the records in a knit.
 
362
 
 
363
        Much like test_get_stream_all, except for get_stream_as_bytes.
 
364
        """
 
365
        k1 = self.make_test_knit()
 
366
        # Insert the same data as BasicKnitTests.test_knit_join, as they seem
 
367
        # to cover a range of cases (no parents, one parent, multiple parents).
 
368
        test_data = [
 
369
            ('text-a', [], test_knit.TEXT_1),
 
370
            ('text-b', ['text-a'], test_knit.TEXT_1),
 
371
            ('text-c', [], test_knit.TEXT_1),
 
372
            ('text-d', ['text-c'], test_knit.TEXT_1),
 
373
            ('text-m', ['text-b', 'text-d'], test_knit.TEXT_1),
 
374
           ]
 
375
        expected_data_list = [
 
376
            # version, options, parents
 
377
            ('text-a', ['fulltext'], []),
 
378
            ('text-b', ['line-delta'], ['text-a']),
 
379
            ('text-c', ['fulltext'], []),
 
380
            ('text-d', ['line-delta'], ['text-c']),
 
381
            ('text-m', ['line-delta'], ['text-b', 'text-d']),
 
382
            ]
 
383
        for version_id, parents, lines in test_data:
 
384
            k1.add_lines(version_id, parents, test_knit.split_lines(lines))
 
385
 
 
386
        bytes = knitrepo._get_stream_as_bytes(
 
387
            k1, ['text-a', 'text-b', 'text-c', 'text-d', 'text-m'])
 
388
 
 
389
        data = bencode.bdecode(bytes)
 
390
        format = data.pop(0)
 
391
        self.assertEqual('knit-plain', format)
 
392
 
 
393
        for expected, actual in zip(expected_data_list, data):
 
394
            expected_version = expected[0]
 
395
            expected_options = expected[1]
 
396
            expected_parents = expected[2]
 
397
            version, options, parents, bytes = actual
 
398
            self.assertEqual(expected_version, version)
 
399
            self.assertEqual(expected_options, options)
 
400
            self.assertEqual(expected_parents, parents)
 
401
            self.assertRecordContentEqual(k1, version, bytes)
 
402
 
 
403
 
342
404
class DummyRepository(object):
343
405
    """A dummy repository for testing."""
344
406