1
# Copyright (C) 2006 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
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
19
from bzrlib import errors, tests, workingtree
20
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
22
class TestBasisInventory(TestCaseWithWorkingTree):
25
tree = self.make_branch_and_tree('tree')
26
tree.set_root_id('root-id')
27
self.build_tree(['tree/file1'])
28
tree.add('file1', 'file1-id')
29
sub_tree = self.make_branch_and_tree('tree/sub-tree')
30
sub_tree.set_root_id('sub-tree-root-id')
33
def test_add_reference(self):
34
tree, sub_tree = self.make_trees()
36
tree.add_reference(sub_tree)
37
except errors.UnsupportedOperation:
38
assert tree.__class__ in (workingtree.WorkingTree2,
39
workingtree.WorkingTree3)
40
raise tests.TestSkipped('Tree format does not support references')
41
self.assertEqual(tree.path2id('sub-tree'), 'sub-tree-root-id')
42
self.assertEqual(tree.inventory['sub-tree-root-id'].kind,
45
def test_add_reference_same_root(self):
46
tree = self.make_branch_and_tree('tree')
47
self.build_tree(['tree/file1'])
48
tree.add('file1', 'file1-id')
49
tree.set_root_id('root-id')
50
sub_tree = self.make_branch_and_tree('tree/sub-tree')
51
sub_tree.set_root_id('root-id')
53
self.assertRaises(errors.BadReferenceTarget, tree.add_reference,
55
except errors.UnsupportedOperation:
56
assert tree.__class__ in (workingtree.WorkingTree2,
57
workingtree.WorkingTree3)
58
raise tests.TestSkipped('Tree format does not support references')
60
def test_root_present(self):
61
"""Subtree root is present, though not the working tree root"""
62
tree, sub_tree = self.make_trees()
63
sub_tree.set_root_id('file1-id')
65
self.assertRaises(errors.BadReferenceTarget, tree.add_reference,
67
except errors.UnsupportedOperation:
68
assert tree.__class__ in (workingtree.WorkingTree2,
69
workingtree.WorkingTree3)
70
raise tests.TestSkipped('Tree format does not support references')
72
def test_add_non_subtree(self):
73
tree, sub_tree = self.make_trees()
74
os.rename('tree/sub-tree', 'sibling')
75
sibling = workingtree.WorkingTree.open('sibling')
77
self.assertRaises(errors.BadReferenceTarget, tree.add_reference,
79
except errors.UnsupportedOperation:
80
assert tree.__class__ in (workingtree.WorkingTree2,
81
workingtree.WorkingTree3)
82
raise tests.TestSkipped('Tree format does not support references')