/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1908.11.5 by John Arbash Meinel
[merge] bzr.dev 2240
1
# Copyright (C) 2006 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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Tests for WorkingTree.revision_tree.
18
19
These tests are in addition to the tests from 
20
tree_implementations.test_revision_tree which cover the behaviour expected from
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
26
from bzrlib import errors
27
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
28
29
30
class TestRevisionTree(TestCaseWithWorkingTree):
31
32
    def assertTreesEqual(self, left, right):
33
        """Check that left and right have the same content and properties."""
34
        # we use a tree delta to check for equality of the content, and we
35
        # manually check for equality of other things such as the parents list.
36
        self.assertEqual(left.get_parent_ids(), right.get_parent_ids())
37
        differences = left.changes_from(right)
38
        self.assertFalse(differences.has_changed())
39
40
    def test_get_zeroth_basis_tree_via_revision_tree(self):
41
        tree = self.make_branch_and_tree('.')
42
        try:
43
            revision_tree = tree.revision_tree(tree.last_revision())
44
        except errors.NoSuchRevision:
45
            # its ok for a working tree to not cache trees, so just return.
46
            return
47
        basis_tree = tree.basis_tree()
48
        self.assertTreesEqual(revision_tree, basis_tree)
49
50
    def test_get_nonzeroth_basis_tree_via_revision_tree(self):
51
        tree = self.make_branch_and_tree('.')
52
        revision1 = tree.commit('first post')
53
        revision_tree = tree.revision_tree(revision1)
54
        basis_tree = tree.basis_tree()
55
        self.assertTreesEqual(revision_tree, basis_tree)
56
57
    def test_get_pending_merge_revision_tree(self):
58
        tree = self.make_branch_and_tree('tree1')
59
        tree.commit('first post')
60
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
61
        revision1 = tree2.commit('commit in branch', allow_pointless=True)
62
        tree.merge_from_branch(tree2.branch)
63
        try:
64
            cached_revision_tree = tree.revision_tree(revision1)
65
        except errors.NoSuchRevision:
66
            # its ok for a working tree to not cache trees, so just return.
67
            return
68
        real_revision_tree = tree2.basis_tree()
69
        self.assertTreesEqual(real_revision_tree, cached_revision_tree)
70
71
    def test_get_uncached_basis_via_revision_tree(self):
72
        # The basis_tree method returns an empty tree when you ask for the
73
        # basis if the basis is not cached, and it is a ghost. However the
74
        # revision_tree method should always raise when a request tree is not
75
        # cached, so we force this by setting a basis that is a ghost and
76
        # thus cannot be cached.
77
        tree = self.make_branch_and_tree('.')
78
        tree.set_parent_ids(['a-ghost'], allow_leftmost_as_ghost=True)
79
        self.assertRaises(errors.NoSuchRevision, tree.revision_tree, 'a-ghost')