1
# Copyright (C) 2006 by Canonical Ltd
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.
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.
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
17
"""Tests for Tree and InterTree."""
19
from bzrlib.tests import TestCaseWithTransport
20
from bzrlib.tree import InterTree
23
class TestInterTree(TestCaseWithTransport):
25
def test_revision_tree_revision_tree(self):
26
# we should have an InterTree registered for RevisionTree to
28
tree = self.make_branch_and_tree('.')
29
rev_id = tree.commit('first post')
30
rev_id2 = tree.commit('second post', allow_pointless=True)
31
rev_tree = tree.branch.repository.revision_tree(rev_id)
32
rev_tree2 = tree.branch.repository.revision_tree(rev_id2)
33
optimiser = InterTree.get(rev_tree, rev_tree2)
34
self.assertIsInstance(optimiser, InterTree)
35
optimiser = InterTree.get(rev_tree2, rev_tree)
36
self.assertIsInstance(optimiser, InterTree)
38
def test_working_tree_revision_tree(self):
39
# we should have an InterTree available for WorkingTree to
41
tree = self.make_branch_and_tree('.')
42
rev_id = tree.commit('first post')
43
rev_tree = tree.branch.repository.revision_tree(rev_id)
44
optimiser = InterTree.get(rev_tree, tree)
45
self.assertIsInstance(optimiser, InterTree)
46
optimiser = InterTree.get(tree, rev_tree)
47
self.assertIsInstance(optimiser, InterTree)
49
def test_working_tree_working_tree(self):
50
# we should have an InterTree available for WorkingTree to
52
tree = self.make_branch_and_tree('1')
53
tree2 = self.make_branch_and_tree('2')
54
optimiser = InterTree.get(tree, tree2)
55
self.assertIsInstance(optimiser, InterTree)
56
optimiser = InterTree.get(tree2, tree)
57
self.assertIsInstance(optimiser, InterTree)
60
class RecordingOptimiser(InterTree):
64
def compare(self, specific_files=None):
65
self.calls.append(('compare', specific_files))
68
def is_compatible(klass, source, target):
72
class TestTree(TestCaseWithTransport):
74
def test_compare_calls_InterTree_compare(self):
75
old_optimisers = InterTree._optimisers
77
InterTree._optimisers = set()
78
RecordingOptimiser.calls = []
79
InterTree.register_optimiser(RecordingOptimiser)
80
tree = self.make_branch_and_tree('1')
81
tree2 = self.make_branch_and_tree('2')
82
# do a series of calls:
85
# pass in all optional arguments by position
86
tree.compare(tree2, 'specific')
87
# pass in all optional arguments by keyword
88
tree.compare(tree2, specific_files='specific')
90
InterTree._optimisers = old_optimisers
94
('compare', 'specific'),
95
('compare', 'specific'),
96
], RecordingOptimiser.calls)