/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2255.2.158 by Martin Pool
Most of the integration of dirstate and subtree
1
# Copyright (C) 2006, 2007 Canonical Ltd
2100.3.8 by Aaron Bentley
Add add_reference
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2100.3.8 by Aaron Bentley
Add add_reference
16
17
import os
18
2255.6.3 by Aaron Bentley
tweak tests
19
from bzrlib import errors, tests, workingtree, workingtree_4
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
20
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
2100.3.8 by Aaron Bentley
Add add_reference
21
5582.10.1 by Jelmer Vernooij
Move weave formats into bzrlib.plugins.weave_fmt.
22
from bzrlib.plugins.weave_fmt.workingtree import WorkingTree2
23
24
25
TREES_NOT_SUPPORTING_REFERENCES = (WorkingTree2,
2255.6.3 by Aaron Bentley
tweak tests
26
                                   workingtree.WorkingTree3,
27
                                   workingtree_4.WorkingTree4)
28
29
2100.3.8 by Aaron Bentley
Add add_reference
30
class TestBasisInventory(TestCaseWithWorkingTree):
31
32
    def make_trees(self):
33
        tree = self.make_branch_and_tree('tree')
34
        tree.set_root_id('root-id')
35
        self.build_tree(['tree/file1'])
36
        tree.add('file1', 'file1-id')
37
        sub_tree = self.make_branch_and_tree('tree/sub-tree')
38
        sub_tree.set_root_id('sub-tree-root-id')
2100.3.19 by Aaron Bentley
Ensure commit preserves reference revision
39
        sub_tree.commit('commit', rev_id='sub_1')
2100.3.8 by Aaron Bentley
Add add_reference
40
        return tree, sub_tree
41
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
42
    def _references_unsupported(self, tree):
43
        if tree.__class__ in TREES_NOT_SUPPORTING_REFERENCES:
44
            raise tests.TestSkipped('Tree format does not support references')
45
        else:
46
            self.fail('%r does not support references but should'
47
                % (tree, ))
48
2100.3.27 by Aaron Bentley
Enable nested commits
49
    def make_nested_trees(self):
50
        tree, sub_tree = self.make_trees()
51
        try:
52
            tree.add_reference(sub_tree)
53
        except errors.UnsupportedOperation:
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
54
            self._references_unsupported(tree)
2100.3.27 by Aaron Bentley
Enable nested commits
55
        return tree, sub_tree
56
2100.3.8 by Aaron Bentley
Add add_reference
57
    def test_add_reference(self):
2100.3.27 by Aaron Bentley
Enable nested commits
58
        self.make_nested_trees()
2100.3.10 by Aaron Bentley
Ensure added references are serialized properly, beef up Workingtreee3
59
        tree = workingtree.WorkingTree.open('tree')
2255.6.9 by Aaron Bentley
Fix test locking for dirstate
60
        tree.lock_write()
61
        try:
62
            self.assertEqual(tree.path2id('sub-tree'), 'sub-tree-root-id')
63
            self.assertEqual(tree.inventory['sub-tree-root-id'].kind,
64
                             'tree-reference')
65
            tree.commit('commit reference')
66
            basis = tree.basis_tree()
67
            basis.lock_read()
68
            try:
2255.2.228 by Robert Collins
Make all test_add_reference tests pass again.
69
                sub_tree = tree.get_nested_tree('sub-tree-root-id')
2255.6.9 by Aaron Bentley
Fix test locking for dirstate
70
                self.assertEqual(sub_tree.last_revision(),
2255.2.228 by Robert Collins
Make all test_add_reference tests pass again.
71
                    tree.get_reference_revision('sub-tree-root-id'))
2255.6.9 by Aaron Bentley
Fix test locking for dirstate
72
            finally:
73
                basis.unlock()
74
        finally:
75
            tree.unlock()
2100.3.8 by Aaron Bentley
Add add_reference
76
77
    def test_add_reference_same_root(self):
78
        tree = self.make_branch_and_tree('tree')
79
        self.build_tree(['tree/file1'])
80
        tree.add('file1', 'file1-id')
81
        tree.set_root_id('root-id')
82
        sub_tree = self.make_branch_and_tree('tree/sub-tree')
83
        sub_tree.set_root_id('root-id')
84
        try:
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
85
            self.assertRaises(errors.BadReferenceTarget, tree.add_reference,
2100.3.8 by Aaron Bentley
Add add_reference
86
                              sub_tree)
87
        except errors.UnsupportedOperation:
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
88
            self._references_unsupported(tree)
2100.3.8 by Aaron Bentley
Add add_reference
89
90
    def test_root_present(self):
91
        """Subtree root is present, though not the working tree root"""
92
        tree, sub_tree = self.make_trees()
93
        sub_tree.set_root_id('file1-id')
94
        try:
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
95
            self.assertRaises(errors.BadReferenceTarget, tree.add_reference,
2100.3.8 by Aaron Bentley
Add add_reference
96
                              sub_tree)
97
        except errors.UnsupportedOperation:
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
98
            self._references_unsupported(tree)
2100.3.8 by Aaron Bentley
Add add_reference
99
100
    def test_add_non_subtree(self):
101
        tree, sub_tree = self.make_trees()
102
        os.rename('tree/sub-tree', 'sibling')
103
        sibling = workingtree.WorkingTree.open('sibling')
104
        try:
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
105
            self.assertRaises(errors.BadReferenceTarget, tree.add_reference,
2100.3.8 by Aaron Bentley
Add add_reference
106
                              sibling)
107
        except errors.UnsupportedOperation:
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
108
            self._references_unsupported(tree)
2100.3.8 by Aaron Bentley
Add add_reference
109
2100.3.27 by Aaron Bentley
Enable nested commits
110
    def test_get_nested_tree(self):
111
        tree, sub_tree = self.make_nested_trees()
2255.6.9 by Aaron Bentley
Fix test locking for dirstate
112
        tree.lock_read()
113
        try:
2255.2.228 by Robert Collins
Make all test_add_reference tests pass again.
114
            sub_tree2 = tree.get_nested_tree('sub-tree-root-id')
2255.6.9 by Aaron Bentley
Fix test locking for dirstate
115
            self.assertEqual(sub_tree.basedir, sub_tree2.basedir)
2255.2.228 by Robert Collins
Make all test_add_reference tests pass again.
116
            sub_tree2 = tree.get_nested_tree('sub-tree-root-id', 'sub-tree')
2255.6.9 by Aaron Bentley
Fix test locking for dirstate
117
        finally:
118
            tree.unlock()