~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branchbuilder.py

  • Committer: John Arbash Meinel
  • Date: 2008-07-22 17:07:41 UTC
  • mto: (3514.4.6 merge_lca_multi)
  • mto: This revision was merged to the branch mainline in revision 3590.
  • Revision ID: john@arbash-meinel.com-20080722170741-yy0w48dac09xp1lz
test that we can add more files into an existing build

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
class TestBranchBuilder(tests.TestCaseWithMemoryTransport):
28
28
    
29
 
    def assertTreeShape(self, entries, tree):
 
29
    def assertTreeShape(self, expected_shape, tree):
30
30
        """Check that the tree shape matches expectations."""
 
31
        tree.lock_read()
 
32
        try:
 
33
            entries = [(path, ie.file_id, ie.kind)
 
34
                       for path, ie in tree.iter_entries_by_dir()]
 
35
        finally:
 
36
            tree.unlock()
 
37
        self.assertEqual(expected_shape, entries)
31
38
 
32
39
    def test_create(self):
33
40
        """Test the constructor api."""
86
93
        rev_tree = branch.repository.revision_tree(rev_id1)
87
94
        rev_tree.lock_read()
88
95
        self.addCleanup(rev_tree.unlock)
89
 
        entries = [(path, ie.file_id, ie.kind)
90
 
                   for path, ie in rev_tree.iter_entries_by_dir()]
91
 
        self.assertEqual([(u'', 'a-root-id', 'directory'),
92
 
                          (u'a', 'a-id', 'file')], entries)
 
96
        self.assertTreeShape([(u'', 'a-root-id', 'directory'),
 
97
                              (u'a', 'a-id', 'file')], rev_tree)
93
98
        self.assertEqual('contents', rev_tree.get_file_text('a-id'))
 
99
 
 
100
    def test_build_snapshot_add_content(self):
 
101
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
102
        rev_id1 = builder.build_snapshot(None, 'A-id',
 
103
            [('add', ('', 'a-root-id', 'directory', None)),
 
104
             ('add', ('a', 'a-id', 'file', 'contents'))])
 
105
        self.assertEqual('A-id', rev_id1)
 
106
        rev_id2 = builder.build_snapshot(None, 'B-id',
 
107
            [('add', ('b', 'b-id', 'file', 'content_b'))])
 
108
        self.assertEqual('B-id', rev_id2)
 
109
        branch = builder.get_branch()
 
110
        self.assertEqual((2, rev_id2), branch.last_revision_info())
 
111
        rev_tree = branch.repository.revision_tree(rev_id2)
 
112
        rev_tree.lock_read()
 
113
        self.addCleanup(rev_tree.unlock)
 
114
        self.assertTreeShape([(u'', 'a-root-id', 'directory'),
 
115
                              (u'a', 'a-id', 'file'),
 
116
                              (u'b', 'b-id', 'file')], rev_tree)
 
117
        self.assertEqual('content_b', rev_tree.get_file_text('b-id'))