95
99
self.addCleanup(tree.unlock)
96
100
path = tree.id2path('sub-root')
97
self.assertEqual('sub-1', tree.get_reference_revision('sub-root', path))
101
self.assertEqual('sub-1',
102
tree.get_reference_revision('sub-root', path))
99
104
def test_iter_references(self):
100
105
tree = self.create_nested()
102
107
self.addCleanup(tree.unlock)
103
entry = tree.inventory['sub-root']
108
entry = tree.root_inventory['sub-root']
104
109
self.assertEqual([(u'subtree', 'sub-root')],
105
110
list(tree.iter_references()))
153
158
work_tree = self.make_branch_and_tree('wt')
154
159
tree = self.get_tree_no_parents_abc_content_2(work_tree)
157
# Test lookup without path works
158
lines = tree.get_file('a-id').readlines()
159
self.assertEqual(['foobar\n'], lines)
160
# Test lookup with path works
161
lines = tree.get_file('a-id', path='a').readlines()
162
self.assertEqual(['foobar\n'], lines)
161
self.addCleanup(tree.unlock)
162
# Test lookup without path works
163
file_without_path = tree.get_file('a-id')
165
lines = file_without_path.readlines()
166
self.assertEqual(['foobar\n'], lines)
168
file_without_path.close()
169
# Test lookup with path works
170
file_with_path = tree.get_file('a-id', path='a')
172
lines = file_with_path.readlines()
173
self.assertEqual(['foobar\n'], lines)
175
file_with_path.close()
166
177
def test_get_file_text(self):
167
178
work_tree = self.make_branch_and_tree('wt')
252
class TestIterChildEntries(TestCaseWithTree):
254
def test_iteration_order(self):
255
work_tree = self.make_branch_and_tree('.')
256
self.build_tree(['a/', 'a/b/', 'a/b/c', 'a/d/', 'a/d/e', 'f/', 'f/g'])
257
work_tree.add(['a', 'a/b', 'a/b/c', 'a/d', 'a/d/e', 'f', 'f/g'])
258
tree = self._convert_tree(work_tree)
259
output = [e.name for e in
260
tree.iter_child_entries(tree.get_root_id())]
261
self.assertEqual(set(['a', 'f']), set(output))
262
output = [e.name for e in
263
tree.iter_child_entries(tree.path2id('a'))]
264
self.assertEqual(set(['b', 'd']), set(output))
266
def test_does_not_exist(self):
267
work_tree = self.make_branch_and_tree('.')
268
self.build_tree(['a/'])
270
tree = self._convert_tree(work_tree)
271
self.assertRaises(errors.NoSuchId, lambda:
272
list(tree.iter_child_entries('unknown')))
241
275
class TestHasId(TestCaseWithTree):
243
277
def test_has_id(self):
257
291
tree = self._convert_tree(work_tree)
259
293
self.addCleanup(tree.unlock)
260
self.assertTrue('file-id' in tree)
261
self.assertFalse('dir-id' in tree)
295
self.applyDeprecated(
296
deprecated_in((2, 4, 0)),
297
tree.__contains__, 'file-id'))
299
self.applyDeprecated(
300
deprecated_in((2, 4, 0)),
301
tree.__contains__, 'dir-id'))
264
304
class TestExtras(TestCaseWithTree):
292
332
self.addCleanup(tree.unlock)
293
333
expected = osutils.sha_strings('file content')
294
334
self.assertEqual(expected, tree.get_file_sha1('file-id'))
337
class TestGetFileVerifier(TestCaseWithTree):
339
def test_get_file_verifier(self):
340
work_tree = self.make_branch_and_tree('tree')
341
self.build_tree_contents([
342
('tree/file1', 'file content'),
343
('tree/file2', 'file content')])
344
work_tree.add(['file1', 'file2'], ['file-id-1', 'file-id-2'])
345
tree = self._convert_tree(work_tree)
347
self.addCleanup(tree.unlock)
348
(kind, data) = tree.get_file_verifier('file-id-1')
350
tree.get_file_verifier('file-id-1'),
351
tree.get_file_verifier('file-id-2'))
353
expected = osutils.sha_strings('file content')
354
self.assertEqual(expected, data)
357
class TestHasVersionedDirectories(TestCaseWithTree):
359
def test_has_versioned_directories(self):
360
work_tree = self.make_branch_and_tree('tree')
361
tree = self._convert_tree(work_tree)
362
self.assertSubset([tree.has_versioned_directories()], (True, False))