17
17
"""Tests for interface conformance of inventories of trees."""
20
from cStringIO import StringIO
23
20
from bzrlib import (
26
23
from bzrlib.tests import (
30
26
from bzrlib.mutabletree import MutableTree
31
from bzrlib.tests import SymlinkFeature, TestSkipped
27
from bzrlib.tests import TestSkipped
28
from bzrlib.tree import InventoryTree
32
29
from bzrlib.transform import _PreviewTree
33
30
from bzrlib.uncommit import uncommit
37
34
return tree.iter_entries_by_dir([file_id]).next()[1]
40
class TestPreviousHeads(per_tree.TestCaseWithTree):
43
# we want several inventories, that respectively
44
# give use the following scenarios:
45
# A) fileid not in any inventory (A),
46
# B) fileid present in one inventory (B) and (A,B)
47
# C) fileid present in two inventories, and they
48
# are not mutual descendents (B, C)
49
# D) fileid present in two inventories and one is
50
# a descendent of the other. (B, D)
51
super(TestPreviousHeads, self).setUp()
52
self.wt = self.make_branch_and_tree('.')
53
self.branch = self.wt.branch
54
self.build_tree(['file'])
55
self.wt.commit('new branch', allow_pointless=True, rev_id='A')
56
self.inv_A = self.branch.repository.get_inventory('A')
57
self.wt.add(['file'], ['fileid'])
58
self.wt.commit('add file', rev_id='B')
59
self.inv_B = self.branch.repository.get_inventory('B')
60
uncommit(self.branch, tree=self.wt)
61
self.assertEqual(self.branch.revision_history(), ['A'])
62
self.wt.commit('another add of file', rev_id='C')
63
self.inv_C = self.branch.repository.get_inventory('C')
64
self.wt.add_parent_tree_id('B')
65
self.wt.commit('merge in B', rev_id='D')
66
self.inv_D = self.branch.repository.get_inventory('D')
67
self.tree = self.workingtree_to_test_tree(self.wt)
69
self.addCleanup(self.tree.unlock)
70
self.file_active = get_entry(self.tree, 'fileid')
72
# TODO: test two inventories with the same file revision
75
37
class TestInventoryWithSymlinks(per_tree.TestCaseWithTree):
77
39
_test_needs_features = [tests.SymlinkFeature]
141
103
def test_canonical_path(self):
142
104
work_tree = self._make_canonical_test_tree()
105
if not isinstance(work_tree, InventoryTree):
106
raise tests.TestNotApplicable(
107
"test not applicable on non-inventory tests")
143
108
self.assertEqual('dir/file',
144
109
work_tree.get_canonical_inventory_path('Dir/File'))
146
111
def test_canonical_path_before_commit(self):
147
112
work_tree = self._make_canonical_test_tree(False)
148
# note: not committed.
113
if not isinstance(work_tree, InventoryTree):
114
raise tests.TestNotApplicable(
115
"test not applicable on non-inventory tests") # note: not committed.
149
116
self.assertEqual('dir/file',
150
117
work_tree.get_canonical_inventory_path('Dir/File'))
152
119
def test_canonical_path_dir(self):
153
120
# check it works when asked for just the directory portion.
154
121
work_tree = self._make_canonical_test_tree()
122
if not isinstance(work_tree, InventoryTree):
123
raise tests.TestNotApplicable(
124
"test not applicable on non-inventory tests")
155
125
self.assertEqual('dir', work_tree.get_canonical_inventory_path('Dir'))
157
127
def test_canonical_path_root(self):
158
128
work_tree = self._make_canonical_test_tree()
129
if not isinstance(work_tree, InventoryTree):
130
raise tests.TestNotApplicable(
131
"test not applicable on non-inventory tests")
159
132
self.assertEqual('', work_tree.get_canonical_inventory_path(''))
160
133
self.assertEqual('/', work_tree.get_canonical_inventory_path('/'))
162
135
def test_canonical_path_invalid_all(self):
163
136
work_tree = self._make_canonical_test_tree()
137
if not isinstance(work_tree, InventoryTree):
138
raise tests.TestNotApplicable(
139
"test not applicable on non-inventory tests")
164
140
self.assertEqual('foo/bar',
165
141
work_tree.get_canonical_inventory_path('foo/bar'))
167
143
def test_canonical_invalid_child(self):
168
144
work_tree = self._make_canonical_test_tree()
145
if not isinstance(work_tree, InventoryTree):
146
raise tests.TestNotApplicable(
147
"test not applicable on non-inventory tests")
169
148
self.assertEqual('dir/None',
170
149
work_tree.get_canonical_inventory_path('Dir/None'))
180
159
work_tree.add(['test/', 'test/file', 'Test'])
182
161
test_tree = self._convert_tree(work_tree)
162
if not isinstance(test_tree, InventoryTree):
163
raise tests.TestNotApplicable(
164
"test not applicable on non-inventory tests")
183
165
test_tree.lock_read()
184
166
self.addCleanup(test_tree.unlock)