~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_versionedfile.py

  • Committer: Robert Collins
  • Date: 2007-09-03 02:58:58 UTC
  • mto: (2592.3.122 repository)
  • mto: This revision was merged to the branch mainline in revision 2791.
  • Revision ID: robertc@robertcollins.net-20070903025858-k2pxq3qz6ulhhtgq
 * The ``add_lines`` methods on ``VersionedFile`` implementations has changed
   its return value to include the sha1 and length of the inserted text. This
   allows the avoidance of double-sha1 calculations during commit.
   (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
    def test_adds_with_parent_texts(self):
82
82
        f = self.get_file()
83
83
        parent_texts = {}
84
 
        parent_texts['r0'] = f.add_lines('r0', [], ['a\n', 'b\n'])
 
84
        _, _, parent_texts['r0'] = f.add_lines('r0', [], ['a\n', 'b\n'])
85
85
        try:
86
 
            parent_texts['r1'] = f.add_lines_with_ghosts('r1',
87
 
                                                         ['r0', 'ghost'], 
88
 
                                                         ['b\n', 'c\n'],
89
 
                                                         parent_texts=parent_texts)
 
86
            _, _, parent_texts['r1'] = f.add_lines_with_ghosts('r1',
 
87
                ['r0', 'ghost'], ['b\n', 'c\n'], parent_texts=parent_texts)
90
88
        except NotImplementedError:
91
89
            # 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)
 
90
            _, _, parent_texts['r1'] = f.add_lines('r1',
 
91
                ['r0'], ['b\n', 'c\n'], parent_texts=parent_texts)
96
92
        f.add_lines('r2', ['r1'], ['c\n', 'd\n'], parent_texts=parent_texts)
97
93
        self.assertNotEqual(None, parent_texts['r0'])
98
94
        self.assertNotEqual(None, parent_texts['r1'])
168
164
        self.assertRaises(errors.ReservedId,
169
165
            vf.add_delta, 'a:', [], None, 'sha1', False, ((0, 0, 0, []),))
170
166
 
 
167
    def test_add_lines_return_value(self):
 
168
        # add_lines should return the sha1 and the text size.
 
169
        vf = self.get_file()
 
170
        empty_text = ('a', [])
 
171
        sample_text_nl = ('b', ["foo\n", "bar\n"])
 
172
        sample_text_no_nl = ('c', ["foo\n", "bar"])
 
173
        # check results for the three cases:
 
174
        for version, lines in (empty_text, sample_text_nl, sample_text_no_nl):
 
175
            # the first two elements are the same for all versioned files:
 
176
            # - the digest and the size of the text. For some versioned files
 
177
            #   additional data is returned in additional tuple elements.
 
178
            result = vf.add_lines(version, [], lines)
 
179
            self.assertEqual(3, len(result))
 
180
            self.assertEqual((osutils.sha_strings(lines), sum(map(len, lines))),
 
181
                result[0:2])
 
182
        # parents should not affect the result:
 
183
        lines = sample_text_nl[1]
 
184
        self.assertEqual((osutils.sha_strings(lines), sum(map(len, lines))),
 
185
            vf.add_lines('d', ['b', 'c'], lines)[0:2])
 
186
 
171
187
    def test_get_reserved(self):
172
188
        vf = self.get_file()
173
189
        self.assertRaises(errors.ReservedId, vf.get_delta, 'b:')