/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2255.2.195 by Robert Collins
Fix set_reference_revision on dirstate format trees.
1
# Copyright (C) 2007 Canonical Ltd
2
# Authors:  Robert Collins <robert.collins@canonical.com>
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2255.2.195 by Robert Collins
Fix set_reference_revision on dirstate format trees.
17
18
5786.1.2 by John Arbash Meinel
Change a test a bit.
19
from bzrlib import (
20
    inventory,
21
    )
4100.2.1 by Aaron Bentley
Disable autodetection of tree references
22
from bzrlib.tests import TestNotApplicable
2255.2.195 by Robert Collins
Fix set_reference_revision on dirstate format trees.
23
from bzrlib.transform import TreeTransform
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
24
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
2255.2.195 by Robert Collins
Fix set_reference_revision on dirstate format trees.
25
26
27
class TestNestedSupport(TestCaseWithWorkingTree):
28
4100.2.1 by Aaron Bentley
Disable autodetection of tree references
29
    def make_branch_and_tree(self, path):
30
        tree = TestCaseWithWorkingTree.make_branch_and_tree(self, path)
31
        if not tree.supports_tree_reference():
32
            raise TestNotApplicable('Tree references not supported')
33
        return tree
34
2255.2.195 by Robert Collins
Fix set_reference_revision on dirstate format trees.
35
    def test_set_get_tree_reference(self):
36
        """This tests that setting a tree reference is persistent."""
37
        tree = self.make_branch_and_tree('.')
38
        transform = TreeTransform(tree)
39
        trans_id = transform.new_directory('reference', transform.root,
40
            'subtree-id')
41
        transform.set_tree_reference('subtree-revision', trans_id)
42
        transform.apply()
43
        tree = tree.bzrdir.open_workingtree()
44
        tree.lock_read()
45
        self.addCleanup(tree.unlock)
46
        self.assertEqual('subtree-revision',
5807.1.8 by Jelmer Vernooij
Fix some tests.
47
            tree.inventory['subtree-id'].reference_revision)
1551.10.26 by Aaron Bentley
Allow extract when tree is locked
48
49
    def test_extract_while_locked(self):
50
        tree = self.make_branch_and_tree('.')
51
        tree.lock_write()
52
        self.addCleanup(tree.unlock)
53
        self.build_tree(['subtree/'])
54
        tree.add(['subtree'], ['subtree-id'])
55
        subtree = tree.extract('subtree-id')
4100.2.1 by Aaron Bentley
Disable autodetection of tree references
56
4100.2.3 by Aaron Bentley
Avoid autodetecting tree references in _comparison_data.
57
    def prepare_with_subtree(self):
4100.2.1 by Aaron Bentley
Disable autodetection of tree references
58
        tree = self.make_branch_and_tree('.')
59
        tree.lock_write()
4100.2.3 by Aaron Bentley
Avoid autodetecting tree references in _comparison_data.
60
        self.addCleanup(tree.unlock)
4100.2.1 by Aaron Bentley
Disable autodetection of tree references
61
        subtree = self.make_branch_and_tree('subtree')
62
        tree.add(['subtree'], ['subtree-id'])
4100.2.3 by Aaron Bentley
Avoid autodetecting tree references in _comparison_data.
63
        return tree
64
65
    def test_kind_does_not_autodetect_subtree(self):
66
        tree = self.prepare_with_subtree()
4100.2.1 by Aaron Bentley
Disable autodetection of tree references
67
        self.assertEqual('directory', tree.kind('subtree-id'))
4100.2.3 by Aaron Bentley
Avoid autodetecting tree references in _comparison_data.
68
69
    def test_comparison_data_does_not_autodetect_subtree(self):
70
        tree = self.prepare_with_subtree()
5786.1.2 by John Arbash Meinel
Change a test a bit.
71
        ie = inventory.InventoryDirectory('subtree-id', 'subtree',
72
                                          tree.path2id(''))
4100.2.3 by Aaron Bentley
Avoid autodetecting tree references in _comparison_data.
73
        self.assertEqual('directory',
5786.1.2 by John Arbash Meinel
Change a test a bit.
74
                         tree._comparison_data(ie, 'subtree')[0])
75
5786.1.6 by John Arbash Meinel
Clean up some of the old tests that I had updated.
76
    def test_inventory_does_not_autodetect_subtree(self):
5786.1.2 by John Arbash Meinel
Change a test a bit.
77
        tree = self.prepare_with_subtree()
78
        ie = tree.inventory['subtree-id']
5786.1.6 by John Arbash Meinel
Clean up some of the old tests that I had updated.
79
        self.assertEqual('directory', ie.kind)
5786.1.2 by John Arbash Meinel
Change a test a bit.
80
81
    def test_iter_entries_by_dir_autodetects_subtree(self):
82
        tree = self.prepare_with_subtree()
83
        path, ie = tree.iter_entries_by_dir(['subtree-id']).next()
84
        self.assertEqual('tree-reference', ie.kind)