~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_versionedfile.py

  • Committer: Robert Collins
  • Date: 2006-03-13 11:03:44 UTC
  • mto: (1615.1.2 bzr.mbp.integration)
  • mto: This revision was merged to the branch mainline in revision 1616.
  • Revision ID: robertc@robertcollins.net-20060313110344-f82a10b55cba1f99
Switch to delta based content copying in the generic versioned file copier.

Show diffs side-by-side

added added

removed removed

Lines of Context:
104
104
        f = self.reopen_file()
105
105
        verify_file(f)
106
106
 
107
 
    def test_get_delta_lines(self):
 
107
    def test_get_delta(self):
108
108
        f = self.get_file()
109
109
        self.assertRaises(errors.RevisionNotPresent, f.get_delta, 'base')
110
110
        # add texts that should trip the knit maximum delta chain threshold
154
154
            text = text + ['line\n']
155
155
            f.add_lines(new_version, [next_parent], text)
156
156
            next_parent = new_version
157
 
        expected_delta = (None, '6bfa09d82ce3e898ad4641ae13dd4fdb9cf0d76b', [(0, 0, 1, [('base', 'line\n')])])
 
157
        f.add_lines('noeol', ['base'], ['line'])
 
158
        expected_delta = (None, '6bfa09d82ce3e898ad4641ae13dd4fdb9cf0d76b', False, 
 
159
                          [(0, 0, 1, [('base', 'line\n')])])
158
160
        self.assertEqual(expected_delta, f.get_delta('base'))
159
161
        next_parent = 'base'
160
162
        next_name = 'chain1-'
161
163
        for depth in range(26):
162
164
            new_version = text_name + '%s' % depth
163
 
            expected_delta = (next_parent, sha1s[depth], [(depth + 1, depth + 1, 1, [(new_version, 'line\n')])])
 
165
            expected_delta = (next_parent, sha1s[depth], 
 
166
                              False,
 
167
                              [(depth + 1, depth + 1, 1, [(new_version, 'line\n')])])
164
168
            self.assertEqual(expected_delta, f.get_delta(new_version))
165
169
            next_parent = new_version
166
170
        next_parent = 'base'
167
171
        next_name = 'chain2-'
168
172
        for depth in range(26):
169
173
            new_version = text_name + '%s' % depth
170
 
            expected_delta = (next_parent, sha1s[depth], [(depth + 1, depth + 1, 1, [(new_version, 'line\n')])])
 
174
            expected_delta = (next_parent, sha1s[depth], False,
 
175
                              [(depth + 1, depth + 1, 1, [(new_version, 'line\n')])])
171
176
            self.assertEqual(expected_delta, f.get_delta(new_version))
172
177
            next_parent = new_version
 
178
        # smoke test for eol support
 
179
        expected_delta = ('base', '264f39cab871e4cfd65b3a002f7255888bb5ed97', True, [])
 
180
        self.assertEqual(['line'], f.get_lines('noeol'))
 
181
        self.assertEqual(expected_delta, f.get_delta('noeol'))
 
182
 
 
183
    def test_add_delta(self):
 
184
        # tests for the add-delta facility.
 
185
        # at this point, optimising for speed, we assume no checks when deltas are inserted.
 
186
        # this may need to be revisited.
 
187
        source = self.get_file('source')
 
188
        source.add_lines('base', [], ['line\n'])
 
189
        next_parent = 'base'
 
190
        text_name = 'chain1-'
 
191
        text = ['line\n']
 
192
        for depth in range(26):
 
193
            new_version = text_name + '%s' % depth
 
194
            text = text + ['line\n']
 
195
            source.add_lines(new_version, [next_parent], text)
 
196
            next_parent = new_version
 
197
        next_parent = 'base'
 
198
        text_name = 'chain2-'
 
199
        text = ['line\n']
 
200
        for depth in range(26):
 
201
            new_version = text_name + '%s' % depth
 
202
            text = text + ['line\n']
 
203
            source.add_lines(new_version, [next_parent], text)
 
204
            next_parent = new_version
 
205
        source.add_lines('noeol', ['base'], ['line'])
 
206
        
 
207
        target = self.get_file('target')
 
208
        for version in source.versions():
 
209
            parent, sha1, noeol, delta = source.get_delta(version)
 
210
            target.add_delta(version,
 
211
                             source.get_parents(version),
 
212
                             parent,
 
213
                             sha1,
 
214
                             noeol,
 
215
                             delta)
 
216
        self.assertRaises(RevisionAlreadyPresent,
 
217
                          target.add_delta, 'base', [], None, '', False, [])
 
218
        for version in source.versions():
 
219
            self.assertEqual(source.get_lines(version),
 
220
                             target.get_lines(version))
173
221
 
174
222
    def test_ancestry(self):
175
223
        f = self.get_file()
202
250
    def test_mutate_after_finish(self):
203
251
        f = self.get_file()
204
252
        f.transaction_finished()
 
253
        self.assertRaises(errors.OutSideTransaction, f.add_delta, '', [], '', '', False, [])
205
254
        self.assertRaises(errors.OutSideTransaction, f.add_lines, '', [], [])
206
255
        self.assertRaises(errors.OutSideTransaction, f.add_lines_with_ghosts, '', [], [])
207
256
        self.assertRaises(errors.OutSideTransaction, f.fix_parents, '', [])
492
541
        factory = self.get_factory()
493
542
        vf = factory('id', transport, 0777, create=True, access_mode='w')
494
543
        vf = factory('id', transport, access_mode='r')
 
544
        self.assertRaises(errors.ReadOnlyError, vf.add_delta, '', [], '', '', False, [])
495
545
        self.assertRaises(errors.ReadOnlyError, vf.add_lines, 'base', [], [])
496
546
        self.assertRaises(errors.ReadOnlyError,
497
547
                          vf.add_lines_with_ghosts,