/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'
7143.15.2 by Jelmer Vernooij
Run autopep8.
40
                      % (tree, ))
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
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()
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
53
        with tree.lock_write():
6926.2.2 by Jelmer Vernooij
More fixes.
54
            if tree.supports_setting_file_ids():
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()
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
59
            with basis.lock_read():
60
                sub_tree = tree.get_nested_tree('sub-tree')
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
61
                self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
62
                    sub_tree.last_revision(),
7143.15.15 by Jelmer Vernooij
Merge trunk.
63
                    tree.get_reference_revision('sub-tree'))
2100.3.8 by Aaron Bentley
Add add_reference
64
65
    def test_add_reference_same_root(self):
66
        tree = self.make_branch_and_tree('tree')
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
67
        if not tree.supports_setting_file_ids():
6798 by Jelmer Vernooij
Merge lp:~jelmer/brz/set-root-id.
68
            self.skipTest('format does not support setting file ids')
2100.3.8 by Aaron Bentley
Add add_reference
69
        self.build_tree(['tree/file1'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
70
        tree.add('file1')
6855.4.1 by Jelmer Vernooij
Yet more bees.
71
        tree.set_root_id(b'root-id')
2100.3.8 by Aaron Bentley
Add add_reference
72
        sub_tree = self.make_branch_and_tree('tree/sub-tree')
6855.4.1 by Jelmer Vernooij
Yet more bees.
73
        sub_tree.set_root_id(b'root-id')
2100.3.8 by Aaron Bentley
Add add_reference
74
        try:
6842.1.2 by Jelmer Vernooij
Fix imports.
75
            self.assertRaises(BadReferenceTarget, tree.add_reference,
2100.3.8 by Aaron Bentley
Add add_reference
76
                              sub_tree)
77
        except errors.UnsupportedOperation:
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
78
            self._references_unsupported(tree)
2100.3.8 by Aaron Bentley
Add add_reference
79
80
    def test_root_present(self):
81
        """Subtree root is present, though not the working tree root"""
82
        tree, sub_tree = self.make_trees()
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
83
        if not tree.supports_setting_file_ids():
6798 by Jelmer Vernooij
Merge lp:~jelmer/brz/set-root-id.
84
            self.skipTest('format does not support setting file ids')
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
85
        sub_tree.set_root_id(tree.path2id('file1'))
2100.3.8 by Aaron Bentley
Add add_reference
86
        try:
6842.1.2 by Jelmer Vernooij
Fix imports.
87
            self.assertRaises(BadReferenceTarget, tree.add_reference,
2100.3.8 by Aaron Bentley
Add add_reference
88
                              sub_tree)
89
        except errors.UnsupportedOperation:
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
90
            self._references_unsupported(tree)
2100.3.8 by Aaron Bentley
Add add_reference
91
92
    def test_add_non_subtree(self):
93
        tree, sub_tree = self.make_trees()
94
        os.rename('tree/sub-tree', 'sibling')
95
        sibling = workingtree.WorkingTree.open('sibling')
96
        try:
6842.1.2 by Jelmer Vernooij
Fix imports.
97
            self.assertRaises(BadReferenceTarget, tree.add_reference,
2100.3.8 by Aaron Bentley
Add add_reference
98
                              sibling)
99
        except errors.UnsupportedOperation:
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
100
            self._references_unsupported(tree)
2100.3.8 by Aaron Bentley
Add add_reference
101
2100.3.27 by Aaron Bentley
Enable nested commits
102
    def test_get_nested_tree(self):
103
        tree, sub_tree = self.make_nested_trees()
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
104
        sub_tree_root_id = sub_tree.get_root_id()
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
105
        with tree.lock_read():
6809.4.1 by Jelmer Vernooij
Swap file_id and path arguments for get_reference_revision and get_nested_tree.
106
            sub_tree2 = tree.get_nested_tree('sub-tree')
107
            self.assertEqual(sub_tree.basedir, sub_tree2.basedir)