27
27
class TestBranchBuilder(tests.TestCaseWithMemoryTransport):
29
def assertTreeShape(self, entries, tree):
29
def assertTreeShape(self, expected_shape, tree):
30
30
"""Check that the tree shape matches expectations."""
33
entries = [(path, ie.file_id, ie.kind)
34
for path, ie in tree.iter_entries_by_dir()]
37
self.assertEqual(expected_shape, entries)
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'))
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)
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'))