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
31
from bzrlib.tests import (
36
36
def get_entry(tree, file_id):
37
37
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
40
class TestInventoryWithSymlinks(per_tree.TestCaseWithTree):
77
_test_needs_features = [tests.SymlinkFeature]
42
_test_needs_features = [features.SymlinkFeature]
80
per_tree.TestCaseWithTree.setUp(self)
45
super(TestInventoryWithSymlinks, self).setUp()
81
46
self.tree = self.get_tree_with_subdirs_and_all_content_types()
82
47
self.tree.lock_read()
83
48
self.addCleanup(self.tree.unlock)
141
106
def test_canonical_path(self):
142
107
work_tree = self._make_canonical_test_tree()
108
if not isinstance(work_tree, InventoryTree):
109
raise tests.TestNotApplicable(
110
"test not applicable on non-inventory tests")
143
111
self.assertEqual('dir/file',
144
112
work_tree.get_canonical_inventory_path('Dir/File'))
146
114
def test_canonical_path_before_commit(self):
147
115
work_tree = self._make_canonical_test_tree(False)
148
# note: not committed.
116
if not isinstance(work_tree, InventoryTree):
117
raise tests.TestNotApplicable(
118
"test not applicable on non-inventory tests") # note: not committed.
149
119
self.assertEqual('dir/file',
150
120
work_tree.get_canonical_inventory_path('Dir/File'))
152
122
def test_canonical_path_dir(self):
153
123
# check it works when asked for just the directory portion.
154
124
work_tree = self._make_canonical_test_tree()
125
if not isinstance(work_tree, InventoryTree):
126
raise tests.TestNotApplicable(
127
"test not applicable on non-inventory tests")
155
128
self.assertEqual('dir', work_tree.get_canonical_inventory_path('Dir'))
157
130
def test_canonical_path_root(self):
158
131
work_tree = self._make_canonical_test_tree()
132
if not isinstance(work_tree, InventoryTree):
133
raise tests.TestNotApplicable(
134
"test not applicable on non-inventory tests")
159
135
self.assertEqual('', work_tree.get_canonical_inventory_path(''))
160
136
self.assertEqual('/', work_tree.get_canonical_inventory_path('/'))
162
138
def test_canonical_path_invalid_all(self):
163
139
work_tree = self._make_canonical_test_tree()
140
if not isinstance(work_tree, InventoryTree):
141
raise tests.TestNotApplicable(
142
"test not applicable on non-inventory tests")
164
143
self.assertEqual('foo/bar',
165
144
work_tree.get_canonical_inventory_path('foo/bar'))
167
146
def test_canonical_invalid_child(self):
168
147
work_tree = self._make_canonical_test_tree()
148
if not isinstance(work_tree, InventoryTree):
149
raise tests.TestNotApplicable(
150
"test not applicable on non-inventory tests")
169
151
self.assertEqual('dir/None',
170
152
work_tree.get_canonical_inventory_path('Dir/None'))
174
156
# some of the trees we want to use can only exist on a disk, not in
175
157
# memory - therefore we can only test this if the filesystem is
176
158
# case-sensitive.
177
self.requireFeature(tests.case_sensitive_filesystem_feature)
159
self.requireFeature(features.case_sensitive_filesystem_feature)
178
160
work_tree = self.make_branch_and_tree('.')
179
161
self.build_tree(['test/', 'test/file', 'Test'])
180
162
work_tree.add(['test/', 'test/file', 'Test'])
182
164
test_tree = self._convert_tree(work_tree)
165
if not isinstance(test_tree, InventoryTree):
166
raise tests.TestNotApplicable(
167
"test not applicable on non-inventory tests")
183
168
test_tree.lock_read()
184
169
self.addCleanup(test_tree.unlock)