/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.15 by John Arbash Meinel
Merge bzr.dev 5597 to resolve NEWS, aka bzr-2.3.txt
1
# Copyright (C) 2006-2009, 2011 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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
19
from breezy import errors, tests, workingtree
6842.1.2 by Jelmer Vernooij
Fix imports.
20
from breezy.mutabletree import BadReferenceTarget
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
21
from breezy.tests.per_workingtree import TestCaseWithWorkingTree
2100.3.8 by Aaron Bentley
Add add_reference
22
2255.6.3 by Aaron Bentley
tweak tests
23
2100.3.8 by Aaron Bentley
Add add_reference
24
class TestBasisInventory(TestCaseWithWorkingTree):
25
26
    def make_trees(self):
27
        tree = self.make_branch_and_tree('tree')
28
        self.build_tree(['tree/file1'])
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
29
        tree.add('file1')
2100.3.8 by Aaron Bentley
Add add_reference
30
        sub_tree = self.make_branch_and_tree('tree/sub-tree')
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
31
        sub_tree.commit('commit')
2100.3.8 by Aaron Bentley
Add add_reference
32
        return tree, sub_tree
33
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
34
    def _references_unsupported(self, tree):
5582.10.4 by Jelmer Vernooij
Fix a bunch of tests.
35
        if not tree.supports_tree_reference():
5786.1.2 by John Arbash Meinel
Change a test a bit.
36
            raise tests.TestNotApplicable(
37
                'Tree format does not support references')
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
38
        else:
39
            self.fail('%r does not support references but should'
40
                % (tree, ))
41
2100.3.27 by Aaron Bentley
Enable nested commits
42
    def make_nested_trees(self):
43
        tree, sub_tree = self.make_trees()
44
        try:
45
            tree.add_reference(sub_tree)
46
        except errors.UnsupportedOperation:
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
47
            self._references_unsupported(tree)
2100.3.27 by Aaron Bentley
Enable nested commits
48
        return tree, sub_tree
49
2100.3.8 by Aaron Bentley
Add add_reference
50
    def test_add_reference(self):
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
51
        tree, sub_tree = self.make_nested_trees()
52
        sub_tree_root_id = sub_tree.get_root_id()
2255.6.9 by Aaron Bentley
Fix test locking for dirstate
53
        tree.lock_write()
54
        try:
6926.2.2 by Jelmer Vernooij
More fixes.
55
            if tree.supports_setting_file_ids():
56
                self.assertEqual(tree.path2id('sub-tree'), sub_tree_root_id)
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
57
            self.assertEqual(tree.kind('sub-tree'), 'tree-reference')
2255.6.9 by Aaron Bentley
Fix test locking for dirstate
58
            tree.commit('commit reference')
59
            basis = tree.basis_tree()
60
            basis.lock_read()
61
            try:
6809.4.1 by Jelmer Vernooij
Swap file_id and path arguments for get_reference_revision and get_nested_tree.
62
                sub_tree = tree.get_nested_tree('sub-tree', sub_tree_root_id)
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
63
                self.assertEqual(
64
                        sub_tree.last_revision(),
6809.4.1 by Jelmer Vernooij
Swap file_id and path arguments for get_reference_revision and get_nested_tree.
65
                        tree.get_reference_revision('sub-tree', sub_tree_root_id))
2255.6.9 by Aaron Bentley
Fix test locking for dirstate
66
            finally:
67
                basis.unlock()
68
        finally:
69
            tree.unlock()
2100.3.8 by Aaron Bentley
Add add_reference
70
71
    def test_add_reference_same_root(self):
72
        tree = self.make_branch_and_tree('tree')
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
73
        if not tree.supports_setting_file_ids():
6798 by Jelmer Vernooij
Merge lp:~jelmer/brz/set-root-id.
74
            self.skipTest('format does not support setting file ids')
2100.3.8 by Aaron Bentley
Add add_reference
75
        self.build_tree(['tree/file1'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
76
        tree.add('file1')
6855.4.1 by Jelmer Vernooij
Yet more bees.
77
        tree.set_root_id(b'root-id')
2100.3.8 by Aaron Bentley
Add add_reference
78
        sub_tree = self.make_branch_and_tree('tree/sub-tree')
6855.4.1 by Jelmer Vernooij
Yet more bees.
79
        sub_tree.set_root_id(b'root-id')
2100.3.8 by Aaron Bentley
Add add_reference
80
        try:
6842.1.2 by Jelmer Vernooij
Fix imports.
81
            self.assertRaises(BadReferenceTarget, tree.add_reference,
2100.3.8 by Aaron Bentley
Add add_reference
82
                              sub_tree)
83
        except errors.UnsupportedOperation:
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
84
            self._references_unsupported(tree)
2100.3.8 by Aaron Bentley
Add add_reference
85
86
    def test_root_present(self):
87
        """Subtree root is present, though not the working tree root"""
88
        tree, sub_tree = self.make_trees()
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
89
        if not tree.supports_setting_file_ids():
6798 by Jelmer Vernooij
Merge lp:~jelmer/brz/set-root-id.
90
            self.skipTest('format does not support setting file ids')
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
91
        sub_tree.set_root_id(tree.path2id('file1'))
2100.3.8 by Aaron Bentley
Add add_reference
92
        try:
6842.1.2 by Jelmer Vernooij
Fix imports.
93
            self.assertRaises(BadReferenceTarget, tree.add_reference,
2100.3.8 by Aaron Bentley
Add add_reference
94
                              sub_tree)
95
        except errors.UnsupportedOperation:
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
96
            self._references_unsupported(tree)
2100.3.8 by Aaron Bentley
Add add_reference
97
98
    def test_add_non_subtree(self):
99
        tree, sub_tree = self.make_trees()
100
        os.rename('tree/sub-tree', 'sibling')
101
        sibling = workingtree.WorkingTree.open('sibling')
102
        try:
6842.1.2 by Jelmer Vernooij
Fix imports.
103
            self.assertRaises(BadReferenceTarget, tree.add_reference,
2100.3.8 by Aaron Bentley
Add add_reference
104
                              sibling)
105
        except errors.UnsupportedOperation:
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
106
            self._references_unsupported(tree)
2100.3.8 by Aaron Bentley
Add add_reference
107
2100.3.27 by Aaron Bentley
Enable nested commits
108
    def test_get_nested_tree(self):
109
        tree, sub_tree = self.make_nested_trees()
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
110
        sub_tree_root_id = sub_tree.get_root_id()
2255.6.9 by Aaron Bentley
Fix test locking for dirstate
111
        tree.lock_read()
112
        try:
6809.4.1 by Jelmer Vernooij
Swap file_id and path arguments for get_reference_revision and get_nested_tree.
113
            sub_tree2 = tree.get_nested_tree('sub-tree', sub_tree_root_id)
114
            self.assertEqual(sub_tree.basedir, sub_tree2.basedir)
115
            sub_tree2 = tree.get_nested_tree('sub-tree')
116
            self.assertEqual(sub_tree.basedir, sub_tree2.basedir)
2255.6.9 by Aaron Bentley
Fix test locking for dirstate
117
        finally:
118
            tree.unlock()