13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
"""Tests for interface conformance of inventories of trees."""
20
20
from cStringIO import StringIO
23
from bzrlib.diff import internal_diff
26
from bzrlib.tests import (
24
30
from bzrlib.mutabletree import MutableTree
25
from bzrlib.osutils import has_symlinks
26
31
from bzrlib.tests import SymlinkFeature, TestSkipped
27
from bzrlib.tests.tree_implementations import TestCaseWithTree
28
32
from bzrlib.transform import _PreviewTree
29
33
from bzrlib.uncommit import uncommit
68
72
# TODO: test two inventories with the same file revision
71
class TestInventory(TestCaseWithTree):
75
class TestInventoryWithSymlinks(per_tree.TestCaseWithTree):
77
_test_needs_features = [tests.SymlinkFeature]
80
per_tree.TestCaseWithTree.setUp(self)
74
81
self.tree = self.get_tree_with_subdirs_and_all_content_types()
75
82
self.tree.lock_read()
76
83
self.addCleanup(self.tree.unlock)
78
85
def test_symlink_target(self):
79
self.requireFeature(SymlinkFeature)
81
86
if isinstance(self.tree, (MutableTree, _PreviewTree)):
83
88
'symlinks not accurately represented in working trees and'
86
91
self.assertEqual(entry.symlink_target, 'link-target')
88
93
def test_symlink_target_tree(self):
89
self.requireFeature(SymlinkFeature)
91
94
self.assertEqual('link-target',
92
95
self.tree.get_symlink_target('symlink'))
94
97
def test_kind_symlink(self):
95
self.requireFeature(SymlinkFeature)
97
98
self.assertEqual('symlink', self.tree.kind('symlink'))
98
99
self.assertIs(None, self.tree.get_file_size('symlink'))
100
101
def test_symlink(self):
101
self.requireFeature(SymlinkFeature)
103
102
entry = get_entry(self.tree, self.tree.path2id('symlink'))
104
103
self.assertEqual(entry.kind, 'symlink')
105
104
self.assertEqual(None, entry.text_size)
107
class TestInventory(per_tree.TestCaseWithTree):
107
109
def test_paths2ids_recursive(self):
108
110
work_tree = self.make_branch_and_tree('tree')
109
111
self.build_tree(['tree/dir/', 'tree/dir/file'])
124
126
self.addCleanup(tree.unlock)
125
127
self.assertEqual(set([]), tree.paths2ids(['file'],
126
128
require_versioned=False))
130
def _make_canonical_test_tree(self, commit=True):
131
# make a tree used by all the 'canonical' tests below.
132
work_tree = self.make_branch_and_tree('tree')
133
self.build_tree(['tree/dir/', 'tree/dir/file'])
134
work_tree.add(['dir', 'dir/file'])
136
work_tree.commit('commit 1')
137
# XXX: this isn't actually guaranteed to return the class we want to
138
# test -- mbp 2010-02-12
141
def test_canonical_path(self):
142
work_tree = self._make_canonical_test_tree()
143
self.assertEqual('dir/file',
144
work_tree.get_canonical_inventory_path('Dir/File'))
146
def test_canonical_path_before_commit(self):
147
work_tree = self._make_canonical_test_tree(False)
148
# note: not committed.
149
self.assertEqual('dir/file',
150
work_tree.get_canonical_inventory_path('Dir/File'))
152
def test_canonical_path_dir(self):
153
# check it works when asked for just the directory portion.
154
work_tree = self._make_canonical_test_tree()
155
self.assertEqual('dir', work_tree.get_canonical_inventory_path('Dir'))
157
def test_canonical_path_root(self):
158
work_tree = self._make_canonical_test_tree()
159
self.assertEqual('', work_tree.get_canonical_inventory_path(''))
160
self.assertEqual('/', work_tree.get_canonical_inventory_path('/'))
162
def test_canonical_path_invalid_all(self):
163
work_tree = self._make_canonical_test_tree()
164
self.assertEqual('foo/bar',
165
work_tree.get_canonical_inventory_path('foo/bar'))
167
def test_canonical_invalid_child(self):
168
work_tree = self._make_canonical_test_tree()
169
self.assertEqual('dir/None',
170
work_tree.get_canonical_inventory_path('Dir/None'))
172
def test_canonical_tree_name_mismatch(self):
173
# see <https://bugs.edge.launchpad.net/bzr/+bug/368931>
174
# some of the trees we want to use can only exist on a disk, not in
175
# memory - therefore we can only test this if the filesystem is
177
self.requireFeature(tests.case_sensitive_filesystem_feature)
178
work_tree = self.make_branch_and_tree('.')
179
self.build_tree(['test/', 'test/file', 'Test'])
180
work_tree.add(['test/', 'test/file', 'Test'])
182
test_tree = self._convert_tree(work_tree)
183
test_tree.lock_read()
184
self.addCleanup(test_tree.unlock)
186
self.assertEqual(['test', 'test/file', 'Test', 'test/foo', 'Test/foo'],
187
test_tree.get_canonical_inventory_paths(
188
['test', 'test/file', 'Test', 'test/foo', 'Test/foo']))