/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_versionedfile.py

  • Committer: Robert Collins
  • Date: 2007-09-03 23:19:00 UTC
  • mfrom: (2791 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2792.
  • Revision ID: robertc@robertcollins.net-20070903231900-j3or8vkiixxpskzm
Fix some inconsistent NEWS indents.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
                           RevisionAlreadyPresent,
35
35
                           WeaveParentMismatch
36
36
                           )
37
 
from bzrlib.knit import KnitVersionedFile, \
38
 
     KnitAnnotateFactory, KnitPlainFactory
 
37
from bzrlib.knit import (
 
38
    KnitVersionedFile,
 
39
    KnitAnnotateFactory,
 
40
    KnitPlainFactory,
 
41
    )
39
42
from bzrlib.tests import TestCaseWithMemoryTransport, TestSkipped
40
43
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
41
44
from bzrlib.trace import mutter
81
84
    def test_adds_with_parent_texts(self):
82
85
        f = self.get_file()
83
86
        parent_texts = {}
84
 
        parent_texts['r0'] = f.add_lines('r0', [], ['a\n', 'b\n'])
 
87
        _, _, parent_texts['r0'] = f.add_lines('r0', [], ['a\n', 'b\n'])
85
88
        try:
86
 
            parent_texts['r1'] = f.add_lines_with_ghosts('r1',
87
 
                                                         ['r0', 'ghost'], 
88
 
                                                         ['b\n', 'c\n'],
89
 
                                                         parent_texts=parent_texts)
 
89
            _, _, parent_texts['r1'] = f.add_lines_with_ghosts('r1',
 
90
                ['r0', 'ghost'], ['b\n', 'c\n'], parent_texts=parent_texts)
90
91
        except NotImplementedError:
91
92
            # if the format doesn't support ghosts, just add normally.
92
 
            parent_texts['r1'] = f.add_lines('r1',
93
 
                                             ['r0'], 
94
 
                                             ['b\n', 'c\n'],
95
 
                                             parent_texts=parent_texts)
 
93
            _, _, parent_texts['r1'] = f.add_lines('r1',
 
94
                ['r0'], ['b\n', 'c\n'], parent_texts=parent_texts)
96
95
        f.add_lines('r2', ['r1'], ['c\n', 'd\n'], parent_texts=parent_texts)
97
96
        self.assertNotEqual(None, parent_texts['r0'])
98
97
        self.assertNotEqual(None, parent_texts['r1'])
168
167
        self.assertRaises(errors.ReservedId,
169
168
            vf.add_delta, 'a:', [], None, 'sha1', False, ((0, 0, 0, []),))
170
169
 
 
170
    def test_add_lines_return_value(self):
 
171
        # add_lines should return the sha1 and the text size.
 
172
        vf = self.get_file()
 
173
        empty_text = ('a', [])
 
174
        sample_text_nl = ('b', ["foo\n", "bar\n"])
 
175
        sample_text_no_nl = ('c', ["foo\n", "bar"])
 
176
        # check results for the three cases:
 
177
        for version, lines in (empty_text, sample_text_nl, sample_text_no_nl):
 
178
            # the first two elements are the same for all versioned files:
 
179
            # - the digest and the size of the text. For some versioned files
 
180
            #   additional data is returned in additional tuple elements.
 
181
            result = vf.add_lines(version, [], lines)
 
182
            self.assertEqual(3, len(result))
 
183
            self.assertEqual((osutils.sha_strings(lines), sum(map(len, lines))),
 
184
                result[0:2])
 
185
        # parents should not affect the result:
 
186
        lines = sample_text_nl[1]
 
187
        self.assertEqual((osutils.sha_strings(lines), sum(map(len, lines))),
 
188
            vf.add_lines('d', ['b', 'c'], lines)[0:2])
 
189
 
171
190
    def test_get_reserved(self):
172
191
        vf = self.get_file()
173
192
        self.assertRaises(errors.ReservedId, vf.get_delta, 'b:')
881
900
class TestKnit(TestCaseWithMemoryTransport, VersionedFileTestMixIn):
882
901
 
883
902
    def get_file(self, name='foo'):
884
 
        return KnitVersionedFile(name, get_transport(self.get_url('.')),
885
 
                                 delta=True, create=True)
 
903
        return self.get_factory()(name, get_transport(self.get_url('.')),
 
904
                                  delta=True, create=True)
886
905
 
887
906
    def get_factory(self):
888
907
        return KnitVersionedFile
894
913
        return knit
895
914
 
896
915
    def reopen_file(self, name='foo', create=False):
897
 
        return KnitVersionedFile(name, get_transport(self.get_url('.')),
 
916
        return self.get_factory()(name, get_transport(self.get_url('.')),
898
917
            delta=True,
899
918
            create=create)
900
919
 
909
928
                          get_transport(self.get_url('.')))
910
929
 
911
930
 
 
931
class TestPlaintextKnit(TestKnit):
 
932
    """Test a knit with no cached annotations"""
 
933
 
 
934
    def _factory(self, name, transport, file_mode=None, access_mode=None,
 
935
                 delta=True, create=False):
 
936
        return KnitVersionedFile(name, transport, file_mode, access_mode,
 
937
                                 KnitPlainFactory(), delta=delta,
 
938
                                 create=create)
 
939
 
 
940
    def get_factory(self):
 
941
        return self._factory
 
942
 
 
943
 
912
944
class InterString(versionedfile.InterVersionedFile):
913
945
    """An inter-versionedfile optimised code path for strings.
914
946