/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5080.3.2 by Vincent Ladeuil
Reproduce bug #533547 where DirstateRevisionTree.kind query the wrong inventory entry.
1
# Copyright (C) 2006, 2007, 2009, 2010 Canonical Ltd
1908.11.2 by Robert Collins
Implement WorkingTree interface conformance tests for
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
1908.11.2 by Robert Collins
Implement WorkingTree interface conformance tests for
16
17
"""Tests for WorkingTree.revision_tree.
18
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
19
These tests are in addition to the tests from
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
20
per_tree.test_revision_tree which cover the behaviour expected from
1908.11.2 by Robert Collins
Implement WorkingTree interface conformance tests for
21
all Trees. WorkingTrees implement the revision_tree api to allow access to
22
cached data, but we don't require that all WorkingTrees have such a cache,
23
so these tests are testing that when there is a cache, it performs correctly.
24
"""
25
5080.3.2 by Vincent Ladeuil
Reproduce bug #533547 where DirstateRevisionTree.kind query the wrong inventory entry.
26
from bzrlib import (
27
    errors,
28
    tests,
29
    )
30
from bzrlib.tests import per_workingtree
31
32
33
class TestRevisionTree(per_workingtree.TestCaseWithWorkingTree):
1908.11.2 by Robert Collins
Implement WorkingTree interface conformance tests for
34
35
    def test_get_zeroth_basis_tree_via_revision_tree(self):
36
        tree = self.make_branch_and_tree('.')
37
        try:
38
            revision_tree = tree.revision_tree(tree.last_revision())
39
        except errors.NoSuchRevision:
40
            # its ok for a working tree to not cache trees, so just return.
41
            return
42
        basis_tree = tree.basis_tree()
43
        self.assertTreesEqual(revision_tree, basis_tree)
44
45
    def test_get_nonzeroth_basis_tree_via_revision_tree(self):
46
        tree = self.make_branch_and_tree('.')
47
        revision1 = tree.commit('first post')
48
        revision_tree = tree.revision_tree(revision1)
49
        basis_tree = tree.basis_tree()
50
        self.assertTreesEqual(revision_tree, basis_tree)
51
52
    def test_get_pending_merge_revision_tree(self):
53
        tree = self.make_branch_and_tree('tree1')
54
        tree.commit('first post')
55
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
56
        revision1 = tree2.commit('commit in branch', allow_pointless=True)
57
        tree.merge_from_branch(tree2.branch)
58
        try:
59
            cached_revision_tree = tree.revision_tree(revision1)
60
        except errors.NoSuchRevision:
61
            # its ok for a working tree to not cache trees, so just return.
62
            return
63
        real_revision_tree = tree2.basis_tree()
64
        self.assertTreesEqual(real_revision_tree, cached_revision_tree)
65
66
    def test_get_uncached_basis_via_revision_tree(self):
67
        # The basis_tree method returns an empty tree when you ask for the
68
        # basis if the basis is not cached, and it is a ghost. However the
69
        # revision_tree method should always raise when a request tree is not
70
        # cached, so we force this by setting a basis that is a ghost and
71
        # thus cannot be cached.
72
        tree = self.make_branch_and_tree('.')
73
        tree.set_parent_ids(['a-ghost'], allow_leftmost_as_ghost=True)
74
        self.assertRaises(errors.NoSuchRevision, tree.revision_tree, 'a-ghost')
2255.2.76 by Robert Collins
Add tests for revision trees with a different unique root to the current tree.
75
76
    def test_revision_tree_different_root_id(self):
77
        """A revision tree might have a very different root."""
78
        tree = self.make_branch_and_tree('tree1')
79
        tree.set_root_id('one')
80
        rev1 = tree.commit('first post')
81
        tree.set_root_id('two')
82
        try:
83
            cached_revision_tree = tree.revision_tree(rev1)
84
        except errors.NoSuchRevision:
85
            # its ok for a working tree to not cache trees, so just return.
86
            return
87
        repository_revision_tree = tree.branch.repository.revision_tree(rev1)
88
        self.assertTreesEqual(repository_revision_tree, cached_revision_tree)
5080.3.2 by Vincent Ladeuil
Reproduce bug #533547 where DirstateRevisionTree.kind query the wrong inventory entry.
89
90
91
class TestRevisionTreeKind(per_workingtree.TestCaseWithWorkingTree):
92
93
    def make_branch_with_merged_deletions(self, relpath='tree'):
94
        tree = self.make_branch_and_tree(relpath)
95
        files = ['a', 'b/', 'b/c']
96
        self.build_tree(files, line_endings='binary',
97
                        transport=tree.bzrdir.root_transport)
98
        tree.set_root_id('root-id')
99
        tree.add(files, ['a-id', 'b-id', 'c-id'])
100
        tree.commit('a, b and b/c', rev_id='base')
101
        tree2 = tree.bzrdir.sprout(relpath + '2').open_workingtree()
102
        # Delete 'a' in tree
103
        tree.remove('a', keep_files=False)
104
        tree.commit('remove a', rev_id='this')
105
        # Delete 'c' in tree2
106
        tree2.remove('b/c', keep_files=False)
107
        tree2.remove('b', keep_files=False)
108
        tree2.commit('remove b/c', rev_id='other')
109
        # Merge tree2 into tree
110
        tree.merge_from_branch(tree2.branch)
111
        return tree
112
113
    def test_kind_parent_tree(self):
114
        tree = self.make_branch_with_merged_deletions()
115
        tree.lock_read()
116
        self.addCleanup(tree.unlock)
117
        parents = tree.get_parent_ids()
118
        self.assertEqual(['this', 'other'], parents)
5080.3.4 by Vincent Ladeuil
Cleanup test from overly cautious checks.
119
        basis = tree.revision_tree(parents[0])
5080.3.2 by Vincent Ladeuil
Reproduce bug #533547 where DirstateRevisionTree.kind query the wrong inventory entry.
120
        basis.lock_read()
121
        self.addCleanup(basis.unlock)
122
        self.assertRaises(errors.NoSuchId, basis.kind, 'a-id')
123
        self.assertEqual(['directory', 'file'],
124
                         [basis.kind('b-id'), basis.kind('c-id')])
125
        try:
126
            other = tree.revision_tree(parents[1])
127
        except errors.NoSuchRevisionInTree:
128
            raise tests.TestNotApplicable(
129
                'Tree type %s caches only the basis revision tree.'
130
                % type(tree))
131
        other.lock_read()
132
        self.addCleanup(other.unlock)
133
        self.assertRaises(errors.NoSuchId, other.kind, 'b-id')
134
        self.assertRaises(errors.NoSuchId, other.kind, 'c-id')
135
        self.assertEqual('file', other.kind('a-id'))