~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/workingtree_implementations/test_add_reference.py

  • Committer: Aaron Bentley
  • Date: 2006-12-11 03:11:05 UTC
  • mto: (2255.6.1 dirstate)
  • mto: This revision was merged to the branch mainline in revision 2322.
  • Revision ID: aaron.bentley@utoronto.ca-20061211031105-xne52056x5ozz8yc
Add add_reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 Canonical Ltd
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
 
 
17
import os
 
18
 
 
19
from bzrlib import errors, tests, workingtree
 
20
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
 
21
 
 
22
class TestBasisInventory(TestCaseWithWorkingTree):
 
23
 
 
24
    def make_trees(self):
 
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')
 
31
        return tree, sub_tree
 
32
 
 
33
    def test_add_reference(self):
 
34
        tree, sub_tree = self.make_trees()
 
35
        try:
 
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, 
 
43
                         'tree-reference')
 
44
 
 
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')
 
52
        try:
 
53
            self.assertRaises(errors.BadReferenceTarget, tree.add_reference, 
 
54
                              sub_tree)
 
55
        except errors.UnsupportedOperation:
 
56
            assert tree.__class__ in (workingtree.WorkingTree2, 
 
57
                                      workingtree.WorkingTree3)
 
58
            raise tests.TestSkipped('Tree format does not support references')
 
59
 
 
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')
 
64
        try:
 
65
            self.assertRaises(errors.BadReferenceTarget, tree.add_reference, 
 
66
                              sub_tree)
 
67
        except errors.UnsupportedOperation:
 
68
            assert tree.__class__ in (workingtree.WorkingTree2, 
 
69
                                      workingtree.WorkingTree3)
 
70
            raise tests.TestSkipped('Tree format does not support references')
 
71
 
 
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')
 
76
        try:
 
77
            self.assertRaises(errors.BadReferenceTarget, tree.add_reference, 
 
78
                              sibling)
 
79
        except errors.UnsupportedOperation:
 
80
            assert tree.__class__ in (workingtree.WorkingTree2, 
 
81
                                      workingtree.WorkingTree3)
 
82
            raise tests.TestSkipped('Tree format does not support references')
 
83