~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testinv.py

  • Committer: Robert Collins
  • Date: 2005-10-06 00:52:53 UTC
  • Revision ID: robertc@robertcollins.net-20051006005253-415c38ad22094f13
define some expected behaviour for inventory_entry.snapshot

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import os
19
19
 
20
20
from bzrlib.branch import Branch
 
21
import bzrlib.errors as errors
21
22
from bzrlib.diff import internal_diff
22
23
from bzrlib.inventory import Inventory, ROOT_ID
23
24
import bzrlib.inventory as inventory
24
 
from bzrlib.osutils import has_symlinks
 
25
from bzrlib.osutils import has_symlinks, rename
25
26
from bzrlib.selftest import TestCase, TestCaseInTempDir
26
27
 
27
28
 
65
66
        ## XXX
66
67
 
67
68
 
68
 
class TestInventoryEntry(TestCaseInTempDir):
 
69
class TestInventoryEntry(TestCase):
69
70
 
70
71
    def test_file_kind_character(self):
71
72
        file = inventory.InventoryFile('123', 'hello.c', ROOT_ID)
219
220
                          output)
220
221
        self.assertEqual(output.getvalue(),
221
222
                         "=== target changed 'target1' => 'target2'\n")
 
223
 
 
224
 
 
225
class TestSnapshot(TestCaseInTempDir):
 
226
 
 
227
    def setUp(self):
 
228
        # for full testing we'll need a branch
 
229
        # with a subdir to test parent changes.
 
230
        # and a file, link and dir under that.
 
231
        # but right now I only need one attribute
 
232
        # to change, and then test merge patterns
 
233
        # with fake parent entries.
 
234
        super(TestSnapshot, self).setUp()
 
235
        self.branch = Branch.initialize('.')
 
236
        self.build_tree(['subdir/', 'subdir/file'])
 
237
        self.branch.add(['subdir', 'subdir/file'], ['dirid', 'fileid'])
 
238
        if has_symlinks():
 
239
            pass
 
240
        self.branch.commit('message_1', rev_id = '1')
 
241
        self.tree_1 = self.branch.revision_tree('1')
 
242
        self.inv_1 = self.branch.get_inventory('1')
 
243
        self.file_1 = self.inv_1['fileid']
 
244
        self.work_tree = self.branch.working_tree()
 
245
        self.file_active = self.work_tree.inventory['fileid']
 
246
 
 
247
    def test_snapshot_new_revision(self):
 
248
        # This tests that a simple commit with no parents makes a new
 
249
        # revision value in the inventory entry
 
250
        self.file_active.snapshot('2', 'subdir/file', {}, self.work_tree, 
 
251
                                  self.branch.weave_store)
 
252
        # expected outcome - file_1 has a revision id of '2', and we can get
 
253
        # its text of 'file contents' out of the weave.
 
254
        self.assertEqual(self.file_1.revision, '1')
 
255
        self.assertEqual(self.file_active.revision, '2')
 
256
        # this should be a separate test probably, but lets check it once..
 
257
        lines = self.branch.weave_store.get_lines('fileid','2')
 
258
        self.assertEqual(lines, ['contents of subdir/file\n'])
 
259
 
 
260
    def test_snapshot_unchanged(self):
 
261
        #This tests that a simple commit does not make a new entry for
 
262
        # an unchanged inventory entry
 
263
        self.file_active.snapshot('2', 'subdir/file', {'1':self.file_1},
 
264
                                  self.work_tree, self.branch.weave_store)
 
265
        self.assertEqual(self.file_1.revision, '1')
 
266
        self.assertEqual(self.file_active.revision, '1')
 
267
        self.assertRaises(errors.WeaveError,
 
268
                          self.branch.weave_store.get_lines, 'fileid', '2')
 
269
 
 
270
    def test_snapshot_merge_identical_different_revid(self):
 
271
        # This tests that a commit with two identical parents, one of which has
 
272
        # a different revision id, results in a new revision id in the entry.
 
273
        other_ie = inventory.InventoryFile('fileid', 'newname', self.file_1.parent_id)
 
274
        other_ie = inventory.InventoryFile('fileid', 'file', self.file_1.parent_id)
 
275
        other_ie.revision = '1'
 
276
        other_ie.text_sha1 = self.file_1.text_sha1
 
277
        other_ie.text_size = self.file_1.text_size
 
278
        self.assertEqual(self.file_1, other_ie)
 
279
        other_ie.revision = 'other'
 
280
        self.assertNotEqual(self.file_1, other_ie)
 
281
        self.branch.weave_store.add_identical_text('fileid', '1', 'other', ['1'])
 
282
        self.file_active.snapshot('2', 'subdir/file', 
 
283
                                  {'1':self.file_1, 'other':other_ie},
 
284
                                  self.work_tree, self.branch.weave_store)
 
285
        self.assertEqual(self.file_active.revision, '2')
 
286
 
 
287
    def test_snapshot_changed(self):
 
288
        # This tests that a commit with one different parent results in a new
 
289
        # revision id in the entry.
 
290
        self.file_active.name='newname'
 
291
        rename('subdir/file', 'subdir/newname')
 
292
        self.file_active.snapshot('2', 'subdir/newname', {'1':self.file_1}, 
 
293
                                  self.work_tree, 
 
294
                                  self.branch.weave_store)
 
295
        # expected outcome - file_1 has a revision id of '2'
 
296
        self.assertEqual(self.file_active.revision, '2')