1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# Copyright (C) 2006 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Tests for WorkingTree.revision_tree.
These tests are in addition to the tests from
tree_implementations.test_revision_tree which cover the behaviour expected from
all Trees. WorkingTrees implement the revision_tree api to allow access to
cached data, but we don't require that all WorkingTrees have such a cache,
so these tests are testing that when there is a cache, it performs correctly.
"""
from bzrlib import errors
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
class TestRevisionTree(TestCaseWithWorkingTree):
def assertTreesEqual(self, left, right):
"""Check that left and right have the same content and properties."""
# we use a tree delta to check for equality of the content, and we
# manually check for equality of other things such as the parents list.
self.assertEqual(left.get_parent_ids(), right.get_parent_ids())
differences = left.changes_from(right)
self.assertFalse(differences.has_changed())
def test_get_zeroth_basis_tree_via_revision_tree(self):
tree = self.make_branch_and_tree('.')
try:
revision_tree = tree.revision_tree(tree.last_revision())
except errors.NoSuchRevision:
# its ok for a working tree to not cache trees, so just return.
return
basis_tree = tree.basis_tree()
self.assertTreesEqual(revision_tree, basis_tree)
def test_get_nonzeroth_basis_tree_via_revision_tree(self):
tree = self.make_branch_and_tree('.')
revision1 = tree.commit('first post')
revision_tree = tree.revision_tree(revision1)
basis_tree = tree.basis_tree()
self.assertTreesEqual(revision_tree, basis_tree)
def test_get_pending_merge_revision_tree(self):
tree = self.make_branch_and_tree('tree1')
tree.commit('first post')
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
revision1 = tree2.commit('commit in branch', allow_pointless=True)
tree.merge_from_branch(tree2.branch)
try:
cached_revision_tree = tree.revision_tree(revision1)
except errors.NoSuchRevision:
# its ok for a working tree to not cache trees, so just return.
return
real_revision_tree = tree2.basis_tree()
self.assertTreesEqual(real_revision_tree, cached_revision_tree)
def test_get_uncached_basis_via_revision_tree(self):
# The basis_tree method returns an empty tree when you ask for the
# basis if the basis is not cached, and it is a ghost. However the
# revision_tree method should always raise when a request tree is not
# cached, so we force this by setting a basis that is a ghost and
# thus cannot be cached.
tree = self.make_branch_and_tree('.')
tree.set_parent_ids(['a-ghost'], allow_leftmost_as_ghost=True)
self.assertRaises(errors.NoSuchRevision, tree.revision_tree, 'a-ghost')
|