~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Alexander Belchenko
  • Date: 2006-07-30 16:43:12 UTC
  • mto: (1711.2.111 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1906.
  • Revision ID: bialix@ukr.net-20060730164312-b025fd3ff0cee59e
rename  gpl.txt => COPYING.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
import os
18
 
 
19
 
from bzrlib import errors, tests, workingtree, workingtree_4
20
 
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
21
 
 
22
 
TREES_NOT_SUPPORTING_REFERENCES = (workingtree.WorkingTree2,
23
 
                                   workingtree.WorkingTree3,
24
 
                                   workingtree_4.WorkingTree4)
25
 
 
26
 
 
27
 
class TestBasisInventory(TestCaseWithWorkingTree):
28
 
 
29
 
    def make_trees(self):
30
 
        tree = self.make_branch_and_tree('tree')
31
 
        tree.set_root_id('root-id')
32
 
        self.build_tree(['tree/file1'])
33
 
        tree.add('file1', 'file1-id')
34
 
        sub_tree = self.make_branch_and_tree('tree/sub-tree')
35
 
        sub_tree.set_root_id('sub-tree-root-id')
36
 
        sub_tree.commit('commit', rev_id='sub_1')
37
 
        return tree, sub_tree
38
 
 
39
 
    def _references_unsupported(self, tree):
40
 
        if tree.__class__ in TREES_NOT_SUPPORTING_REFERENCES:
41
 
            raise tests.TestSkipped('Tree format does not support references')
42
 
        else:
43
 
            self.fail('%r does not support references but should'
44
 
                % (tree, ))
45
 
 
46
 
    def make_nested_trees(self):
47
 
        tree, sub_tree = self.make_trees()
48
 
        try:
49
 
            tree.add_reference(sub_tree)
50
 
        except errors.UnsupportedOperation:
51
 
            self._references_unsupported(tree)
52
 
        return tree, sub_tree
53
 
 
54
 
    def test_add_reference(self):
55
 
        self.make_nested_trees()
56
 
        tree = workingtree.WorkingTree.open('tree')
57
 
        tree.lock_write()
58
 
        try:
59
 
            self.assertEqual(tree.path2id('sub-tree'), 'sub-tree-root-id')
60
 
            self.assertEqual(tree.inventory['sub-tree-root-id'].kind,
61
 
                             'tree-reference')
62
 
            tree.commit('commit reference')
63
 
            basis = tree.basis_tree()
64
 
            basis.lock_read()
65
 
            try:
66
 
                sub_tree = tree.get_nested_tree('sub-tree-root-id')
67
 
                self.assertEqual(sub_tree.last_revision(),
68
 
                    tree.get_reference_revision('sub-tree-root-id'))
69
 
            finally:
70
 
                basis.unlock()
71
 
        finally:
72
 
            tree.unlock()
73
 
 
74
 
    def test_add_reference_same_root(self):
75
 
        tree = self.make_branch_and_tree('tree')
76
 
        self.build_tree(['tree/file1'])
77
 
        tree.add('file1', 'file1-id')
78
 
        tree.set_root_id('root-id')
79
 
        sub_tree = self.make_branch_and_tree('tree/sub-tree')
80
 
        sub_tree.set_root_id('root-id')
81
 
        try:
82
 
            self.assertRaises(errors.BadReferenceTarget, tree.add_reference,
83
 
                              sub_tree)
84
 
        except errors.UnsupportedOperation:
85
 
            self._references_unsupported(tree)
86
 
 
87
 
    def test_root_present(self):
88
 
        """Subtree root is present, though not the working tree root"""
89
 
        tree, sub_tree = self.make_trees()
90
 
        sub_tree.set_root_id('file1-id')
91
 
        try:
92
 
            self.assertRaises(errors.BadReferenceTarget, tree.add_reference,
93
 
                              sub_tree)
94
 
        except errors.UnsupportedOperation:
95
 
            self._references_unsupported(tree)
96
 
 
97
 
    def test_add_non_subtree(self):
98
 
        tree, sub_tree = self.make_trees()
99
 
        os.rename('tree/sub-tree', 'sibling')
100
 
        sibling = workingtree.WorkingTree.open('sibling')
101
 
        try:
102
 
            self.assertRaises(errors.BadReferenceTarget, tree.add_reference,
103
 
                              sibling)
104
 
        except errors.UnsupportedOperation:
105
 
            self._references_unsupported(tree)
106
 
 
107
 
    def test_get_nested_tree(self):
108
 
        tree, sub_tree = self.make_nested_trees()
109
 
        tree.lock_read()
110
 
        try:
111
 
            sub_tree2 = tree.get_nested_tree('sub-tree-root-id')
112
 
            self.assertEqual(sub_tree.basedir, sub_tree2.basedir)
113
 
            sub_tree2 = tree.get_nested_tree('sub-tree-root-id', 'sub-tree')
114
 
        finally:
115
 
            tree.unlock()