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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# 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 Tree and InterTree."""
from bzrlib.tests import TestCaseWithTransport
from bzrlib.tree import InterTree
class TestInterTree(TestCaseWithTransport):
def test_revision_tree_revision_tree(self):
# we should have an InterTree registered for RevisionTree to
# RevisionTree.
tree = self.make_branch_and_tree('.')
rev_id = tree.commit('first post')
rev_id2 = tree.commit('second post', allow_pointless=True)
rev_tree = tree.branch.repository.revision_tree(rev_id)
rev_tree2 = tree.branch.repository.revision_tree(rev_id2)
optimiser = InterTree.get(rev_tree, rev_tree2)
self.assertIsInstance(optimiser, InterTree)
optimiser = InterTree.get(rev_tree2, rev_tree)
self.assertIsInstance(optimiser, InterTree)
def test_working_tree_revision_tree(self):
# we should have an InterTree available for WorkingTree to
# RevisionTree.
tree = self.make_branch_and_tree('.')
rev_id = tree.commit('first post')
rev_tree = tree.branch.repository.revision_tree(rev_id)
optimiser = InterTree.get(rev_tree, tree)
self.assertIsInstance(optimiser, InterTree)
optimiser = InterTree.get(tree, rev_tree)
self.assertIsInstance(optimiser, InterTree)
def test_working_tree_working_tree(self):
# we should have an InterTree available for WorkingTree to
# WorkingTree.
tree = self.make_branch_and_tree('1')
tree2 = self.make_branch_and_tree('2')
optimiser = InterTree.get(tree, tree2)
self.assertIsInstance(optimiser, InterTree)
optimiser = InterTree.get(tree2, tree)
self.assertIsInstance(optimiser, InterTree)
class RecordingOptimiser(InterTree):
calls = []
def compare(self, want_unchanged=False, specific_files=None,
extra_trees=None, require_versioned=False, include_root=False):
self.calls.append(
('compare', self.source, self.target, want_unchanged,
specific_files, extra_trees, require_versioned,
include_root)
)
@classmethod
def is_compatible(klass, source, target):
return True
class TestTree(TestCaseWithTransport):
def test_compare_calls_InterTree_compare(self):
"""This test tests the way Tree.compare() uses InterTree."""
old_optimisers = InterTree._optimisers
try:
InterTree._optimisers = []
RecordingOptimiser.calls = []
InterTree.register_optimiser(RecordingOptimiser)
tree = self.make_branch_and_tree('1')
tree2 = self.make_branch_and_tree('2')
# do a series of calls:
# trivial usage
tree.changes_from(tree2)
# pass in all optional arguments by position
tree.changes_from(tree2, 'unchanged', 'specific', 'extra',
'require', True)
# pass in all optional arguments by keyword
tree.changes_from(tree2,
specific_files='specific',
want_unchanged='unchanged',
extra_trees='extra',
require_versioned='require',
include_root=True,
)
finally:
InterTree._optimisers = old_optimisers
self.assertEqual(
[
('compare', tree2, tree, False, None, None, False, False),
('compare', tree2, tree, 'unchanged', 'specific', 'extra',
'require', True),
('compare', tree2, tree, 'unchanged', 'specific', 'extra',
'require', True),
], RecordingOptimiser.calls)
def test_changes_from_with_root(self):
"""Ensure the include_root option does what's expected."""
wt = self.make_branch_and_tree('.')
delta = wt.changes_from(wt.basis_tree())
self.assertEqual(len(delta.added), 0)
delta = wt.changes_from(wt.basis_tree(), wt, include_root=True)
self.assertEqual(len(delta.added), 1)
self.assertEqual(delta.added[0][0], '')
|