~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_inv.py

Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from bzrlib.branch import Branch
23
23
from bzrlib.diff import internal_diff
24
24
from bzrlib.inventory import (Inventory, ROOT_ID, InventoryFile,
25
 
    InventoryDirectory, InventoryEntry)
 
25
    InventoryDirectory, InventoryEntry, TreeReference)
26
26
from bzrlib.osutils import (has_symlinks, rename, pathjoin, is_inside_any, 
27
27
    is_inside_or_parent_of_any)
28
28
from bzrlib.tests import TestCase, TestCaseWithTransport
184
184
            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
185
185
                specific_file_ids=('bye-id',))])
186
186
 
187
 
    def test_version(self):
188
 
        """Inventory remembers the text's version."""
 
187
    def test_add_recursive(self):
 
188
        parent = InventoryDirectory('src-id', 'src', ROOT_ID)
 
189
        child = InventoryFile('hello-id', 'hello.c', 'src-id')
 
190
        parent.children[child.file_id] = child
189
191
        inv = Inventory()
190
 
        ie = inv.add_path('foo.txt', 'file')
191
 
        ## XXX
 
192
        inv.add(parent)
 
193
        self.assertEqual('src/hello.c', inv.id2path('hello-id'))
192
194
 
193
195
 
194
196
class TestInventoryEntry(TestCase):
304
306
        self.file_1 = self.inv_1['fileid']
305
307
        self.file_1b = self.inv_1['binfileid']
306
308
        self.tree_2 = self.wt
 
309
        self.tree_2.lock_read()
 
310
        self.addCleanup(self.tree_2.unlock)
307
311
        self.inv_2 = self.tree_2.read_working_inventory()
308
312
        self.file_2 = self.inv_2['fileid']
309
313
        self.file_2b = self.inv_2['binfileid']
411
415
        self.tree_1 = self.branch.repository.revision_tree('1')
412
416
        self.inv_1 = self.branch.repository.get_inventory('1')
413
417
        self.file_1 = self.inv_1['fileid']
 
418
        self.wt.lock_write()
 
419
        self.addCleanup(self.wt.unlock)
414
420
        self.file_active = self.wt.inventory['fileid']
415
421
        self.builder = self.branch.get_commit_builder([], timestamp=time.time(), revision_id='2')
416
422
 
465
471
    def test_snapshot_changed(self):
466
472
        # This tests that a commit with one different parent results in a new
467
473
        # revision id in the entry.
468
 
        self.file_active.name='newname'
469
 
        rename('subdir/file', 'subdir/newname')
 
474
        self.wt.rename_one('subdir/file', 'subdir/newname')
 
475
        self.file_active = self.wt.inventory['fileid']
470
476
        self.file_active.snapshot('2', 'subdir/newname', {'1':self.file_1}, 
471
477
                                  self.wt, self.builder)
472
478
        # expected outcome - file_1 has a revision id of '2'
500
506
        self.wt.add_parent_tree_id('B')
501
507
        self.wt.commit('merge in B', rev_id='D')
502
508
        self.inv_D = self.branch.repository.get_inventory('D')
 
509
        self.wt.lock_read()
 
510
        self.addCleanup(self.wt.unlock)
503
511
        self.file_active = self.wt.inventory['fileid']
504
512
        self.weave = self.branch.repository.weave_store.get_weave('fileid',
505
513
            self.branch.repository.get_transaction())
600
608
 
601
609
    def test_dangling_id(self):
602
610
        wt = self.make_branch_and_tree('b1')
 
611
        wt.lock_tree_write()
 
612
        self.addCleanup(wt.unlock)
603
613
        self.assertEqual(len(wt.inventory), 1)
604
614
        open('b1/a', 'wb').write('a test\n')
605
615
        wt.add('a')
606
616
        self.assertEqual(len(wt.inventory), 2)
 
617
        wt.flush() # workaround revert doing wt._write_inventory for now.
607
618
        os.unlink('b1/a')
608
619
        wt.revert([])
609
620
        self.assertEqual(len(wt.inventory), 1)
623
634
        inv.root = None
624
635
        self.assertFalse(inv.is_root('TREE_ROOT'))
625
636
        self.assertFalse(inv.is_root('booga'))
 
637
 
 
638
 
 
639
class TestTreeReference(TestCase):
 
640
    
 
641
    def test_create(self):
 
642
        inv = Inventory('tree-root-123')
 
643
        inv.add(TreeReference('nested-id', 'nested', parent_id='tree-root-123',
 
644
                              revision='rev', reference_revision='rev2'))