64
65
self.tree.lock_read()
65
66
self.addCleanup(self.tree.unlock)
66
67
self.file_active = get_entry(self.tree, 'fileid')
67
self.weave = self.branch.repository.weave_store.get_weave('fileid',
68
self.branch.repository.get_transaction())
70
69
# TODO: test two inventories with the same file revision
73
class TestInventory(TestCaseWithTree):
72
class TestInventoryWithSymlinks(per_tree.TestCaseWithTree):
74
_test_needs_features = [tests.SymlinkFeature]
77
per_tree.TestCaseWithTree.setUp(self)
76
78
self.tree = self.get_tree_with_subdirs_and_all_content_types()
77
79
self.tree.lock_read()
78
80
self.addCleanup(self.tree.unlock)
80
82
def test_symlink_target(self):
81
self.requireFeature(SymlinkFeature)
83
83
if isinstance(self.tree, (MutableTree, _PreviewTree)):
85
85
'symlinks not accurately represented in working trees and'
88
88
self.assertEqual(entry.symlink_target, 'link-target')
90
90
def test_symlink_target_tree(self):
91
self.requireFeature(SymlinkFeature)
93
91
self.assertEqual('link-target',
94
92
self.tree.get_symlink_target('symlink'))
96
94
def test_kind_symlink(self):
97
self.requireFeature(SymlinkFeature)
99
95
self.assertEqual('symlink', self.tree.kind('symlink'))
100
96
self.assertIs(None, self.tree.get_file_size('symlink'))
102
98
def test_symlink(self):
103
self.requireFeature(SymlinkFeature)
105
99
entry = get_entry(self.tree, self.tree.path2id('symlink'))
106
100
self.assertEqual(entry.kind, 'symlink')
107
101
self.assertEqual(None, entry.text_size)
104
class TestInventory(per_tree.TestCaseWithTree):
106
def test_paths2ids_recursive(self):
107
work_tree = self.make_branch_and_tree('tree')
108
self.build_tree(['tree/dir/', 'tree/dir/file'])
109
work_tree.add(['dir', 'dir/file'], ['dir-id', 'file-id'])
110
tree = self._convert_tree(work_tree)
112
self.addCleanup(tree.unlock)
113
self.assertEqual(set(['dir-id', 'file-id']), tree.paths2ids(['dir']))
115
def test_paths2ids_forget_old(self):
116
work_tree = self.make_branch_and_tree('tree')
117
self.build_tree(['tree/file'])
118
work_tree.add('file', 'first-id')
119
work_tree.commit('commit old state')
120
work_tree.remove('file')
121
tree = self._convert_tree(work_tree)
123
self.addCleanup(tree.unlock)
124
self.assertEqual(set([]), tree.paths2ids(['file'],
125
require_versioned=False))
127
def _make_canonical_test_tree(self, commit=True):
128
# make a tree used by all the 'canonical' tests below.
129
work_tree = self.make_branch_and_tree('tree')
130
self.build_tree(['tree/dir/', 'tree/dir/file'])
131
work_tree.add(['dir', 'dir/file'])
133
work_tree.commit('commit 1')
136
def test_canonical_path(self):
137
work_tree = self._make_canonical_test_tree()
138
self.assertEqual('dir/file',
139
work_tree.get_canonical_inventory_path('Dir/File'))
141
def test_canonical_path_before_commit(self):
142
work_tree = self._make_canonical_test_tree(False)
143
# note: not committed.
144
self.assertEqual('dir/file',
145
work_tree.get_canonical_inventory_path('Dir/File'))
147
def test_canonical_path_dir(self):
148
# check it works when asked for just the directory portion.
149
work_tree = self._make_canonical_test_tree()
150
self.assertEqual('dir', work_tree.get_canonical_inventory_path('Dir'))
152
def test_canonical_path_root(self):
153
work_tree = self._make_canonical_test_tree()
154
self.assertEqual('', work_tree.get_canonical_inventory_path(''))
155
self.assertEqual('/', work_tree.get_canonical_inventory_path('/'))
157
def test_canonical_path_invalid_all(self):
158
work_tree = self._make_canonical_test_tree()
159
self.assertEqual('foo/bar',
160
work_tree.get_canonical_inventory_path('foo/bar'))
162
def test_canonical_invalid_child(self):
163
work_tree = self._make_canonical_test_tree()
164
self.assertEqual('dir/None',
165
work_tree.get_canonical_inventory_path('Dir/None'))