20
20
from cStringIO import StringIO
23
from bzrlib.diff import internal_diff
26
from bzrlib.tests import tree_implementations
24
27
from bzrlib.mutabletree import MutableTree
25
from bzrlib.osutils import has_symlinks
26
28
from bzrlib.tests import SymlinkFeature, TestSkipped
27
from bzrlib.tests.tree_implementations import TestCaseWithTree
28
29
from bzrlib.transform import _PreviewTree
29
30
from bzrlib.uncommit import uncommit
33
34
return tree.iter_entries_by_dir([file_id]).next()[1]
36
class TestPreviousHeads(TestCaseWithTree):
37
class TestPreviousHeads(tree_implementations.TestCaseWithTree):
39
40
# we want several inventories, that respectively
68
69
# TODO: test two inventories with the same file revision
71
class TestInventory(TestCaseWithTree):
72
class TestInventoryWithSymlinks(tree_implementations.TestCaseWithTree):
74
_test_needs_features = [tests.SymlinkFeature]
77
tree_implementations.TestCaseWithTree.setUp(self)
74
78
self.tree = self.get_tree_with_subdirs_and_all_content_types()
75
79
self.tree.lock_read()
76
80
self.addCleanup(self.tree.unlock)
78
82
def test_symlink_target(self):
79
self.requireFeature(SymlinkFeature)
81
83
if isinstance(self.tree, (MutableTree, _PreviewTree)):
83
85
'symlinks not accurately represented in working trees and'
86
88
self.assertEqual(entry.symlink_target, 'link-target')
88
90
def test_symlink_target_tree(self):
89
self.requireFeature(SymlinkFeature)
91
91
self.assertEqual('link-target',
92
92
self.tree.get_symlink_target('symlink'))
94
94
def test_kind_symlink(self):
95
self.requireFeature(SymlinkFeature)
97
95
self.assertEqual('symlink', self.tree.kind('symlink'))
98
96
self.assertIs(None, self.tree.get_file_size('symlink'))
100
98
def test_symlink(self):
101
self.requireFeature(SymlinkFeature)
103
99
entry = get_entry(self.tree, self.tree.path2id('symlink'))
104
100
self.assertEqual(entry.kind, 'symlink')
105
101
self.assertEqual(None, entry.text_size)
104
class TestInventory(tree_implementations.TestCaseWithTree):
107
106
def test_paths2ids_recursive(self):
108
107
work_tree = self.make_branch_and_tree('tree')
109
108
self.build_tree(['tree/dir/', 'tree/dir/file'])
137
136
def test_canonical_path(self):
138
137
work_tree = self._make_canonical_test_tree()
139
self.assertEqual(work_tree.get_canonical_inventory_path('Dir/File'), 'dir/file')
138
self.assertEqual('dir/file',
139
work_tree.get_canonical_inventory_path('Dir/File'))
141
141
def test_canonical_path_before_commit(self):
142
142
work_tree = self._make_canonical_test_tree(False)
143
143
# note: not committed.
144
self.assertEqual(work_tree.get_canonical_inventory_path('Dir/File'), 'dir/file')
144
self.assertEqual('dir/file',
145
work_tree.get_canonical_inventory_path('Dir/File'))
146
147
def test_canonical_path_dir(self):
147
148
# check it works when asked for just the directory portion.
148
149
work_tree = self._make_canonical_test_tree()
149
self.assertEqual(work_tree.get_canonical_inventory_path('Dir'), 'dir')
150
self.assertEqual('dir', work_tree.get_canonical_inventory_path('Dir'))
151
152
def test_canonical_path_root(self):
152
153
work_tree = self._make_canonical_test_tree()
153
self.assertEqual(work_tree.get_canonical_inventory_path(''), '')
154
self.assertEqual(work_tree.get_canonical_inventory_path('/'), '/')
154
self.assertEqual('', work_tree.get_canonical_inventory_path(''))
155
self.assertEqual('/', work_tree.get_canonical_inventory_path('/'))
156
157
def test_canonical_path_invalid_all(self):
157
158
work_tree = self._make_canonical_test_tree()
158
self.assertEqual(work_tree.get_canonical_inventory_path('foo/bar'), 'foo/bar')
159
self.assertEqual('foo/bar',
160
work_tree.get_canonical_inventory_path('foo/bar'))
160
162
def test_canonical_invalid_child(self):
161
163
work_tree = self._make_canonical_test_tree()
162
self.assertEqual(work_tree.get_canonical_inventory_path('Dir/None'), 'dir/None')
164
self.assertEqual('dir/None',
165
work_tree.get_canonical_inventory_path('Dir/None'))