/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:
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
55
            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.
56
            self.assertEqual(tree.kind('sub-tree'), 'tree-reference')
2255.6.9 by Aaron Bentley
Fix test locking for dirstate
57
            tree.commit('commit reference')
58
            basis = tree.basis_tree()
59
            basis.lock_read()
60
            try:
6809.4.1 by Jelmer Vernooij
Swap file_id and path arguments for get_reference_revision and get_nested_tree.
61
                sub_tree = tree.get_nested_tree('sub-tree', sub_tree_root_id)
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
62
                self.assertEqual(
63
                        sub_tree.last_revision(),
6809.4.1 by Jelmer Vernooij
Swap file_id and path arguments for get_reference_revision and get_nested_tree.
64
                        tree.get_reference_revision('sub-tree', sub_tree_root_id))
2255.6.9 by Aaron Bentley
Fix test locking for dirstate
65
            finally:
66
                basis.unlock()
67
        finally:
68
            tree.unlock()
2100.3.8 by Aaron Bentley
Add add_reference
69
70
    def test_add_reference_same_root(self):
71
        tree = self.make_branch_and_tree('tree')
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
72
        if not tree.supports_setting_file_ids():
6798 by Jelmer Vernooij
Merge lp:~jelmer/brz/set-root-id.
73
            self.skipTest('format does not support setting file ids')
2100.3.8 by Aaron Bentley
Add add_reference
74
        self.build_tree(['tree/file1'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
75
        tree.add('file1')
2100.3.8 by Aaron Bentley
Add add_reference
76
        tree.set_root_id('root-id')
77
        sub_tree = self.make_branch_and_tree('tree/sub-tree')
78
        sub_tree.set_root_id('root-id')
79
        try:
6842.1.2 by Jelmer Vernooij
Fix imports.
80
            self.assertRaises(BadReferenceTarget, tree.add_reference,
2100.3.8 by Aaron Bentley
Add add_reference
81
                              sub_tree)
82
        except errors.UnsupportedOperation:
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
83
            self._references_unsupported(tree)
2100.3.8 by Aaron Bentley
Add add_reference
84
85
    def test_root_present(self):
86
        """Subtree root is present, though not the working tree root"""
87
        tree, sub_tree = self.make_trees()
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
88
        if not tree.supports_setting_file_ids():
6798 by Jelmer Vernooij
Merge lp:~jelmer/brz/set-root-id.
89
            self.skipTest('format does not support setting file ids')
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
90
        sub_tree.set_root_id(tree.path2id('file1'))
2100.3.8 by Aaron Bentley
Add add_reference
91
        try:
6842.1.2 by Jelmer Vernooij
Fix imports.
92
            self.assertRaises(BadReferenceTarget, tree.add_reference,
2100.3.8 by Aaron Bentley
Add add_reference
93
                              sub_tree)
94
        except errors.UnsupportedOperation:
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
95
            self._references_unsupported(tree)
2100.3.8 by Aaron Bentley
Add add_reference
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:
6842.1.2 by Jelmer Vernooij
Fix imports.
102
            self.assertRaises(BadReferenceTarget, tree.add_reference,
2100.3.8 by Aaron Bentley
Add add_reference
103
                              sibling)
104
        except errors.UnsupportedOperation:
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
105
            self._references_unsupported(tree)
2100.3.8 by Aaron Bentley
Add add_reference
106
2100.3.27 by Aaron Bentley
Enable nested commits
107
    def test_get_nested_tree(self):
108
        tree, sub_tree = self.make_nested_trees()
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
109
        sub_tree_root_id = sub_tree.get_root_id()
2255.6.9 by Aaron Bentley
Fix test locking for dirstate
110
        tree.lock_read()
111
        try:
6809.4.1 by Jelmer Vernooij
Swap file_id and path arguments for get_reference_revision and get_nested_tree.
112
            sub_tree2 = tree.get_nested_tree('sub-tree', sub_tree_root_id)
113
            self.assertEqual(sub_tree.basedir, sub_tree2.basedir)
114
            sub_tree2 = tree.get_nested_tree('sub-tree')
115
            self.assertEqual(sub_tree.basedir, sub_tree2.basedir)
2255.6.9 by Aaron Bentley
Fix test locking for dirstate
116
        finally:
117
            tree.unlock()