~bzr-pqm/bzr/bzr.dev

2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 Canonical Ltd
1852.8.2 by Robert Collins
Add InterTree class to represent InterTree operations.
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 Tree and InterTree."""
18
19
from bzrlib.tests import TestCaseWithTransport
20
from bzrlib.tree import InterTree
21
22
23
class TestInterTree(TestCaseWithTransport):
24
25
    def test_revision_tree_revision_tree(self):
26
        # we should have an InterTree registered for RevisionTree to
27
        # RevisionTree.
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)
37
38
    def test_working_tree_revision_tree(self):
39
        # we should have an InterTree available for WorkingTree to 
40
        # RevisionTree.
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)
48
49
    def test_working_tree_working_tree(self):
50
        # we should have an InterTree available for WorkingTree to 
51
        # WorkingTree.
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)
1852.8.4 by Robert Collins
Hook InterTree into Tree.
58
59
60
class RecordingOptimiser(InterTree):
61
62
    calls = []
63
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
64
    def compare(self, want_unchanged=False, specific_files=None,
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
65
        extra_trees=None, require_versioned=False, include_root=False,
66
        want_unversioned=False):
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
67
        self.calls.append(
1852.9.6 by Robert Collins
Merge the change from Tree.compare to Tree.changes_from.
68
            ('compare', self.source, self.target, want_unchanged,
1910.2.57 by Aaron Bentley
Got 0.9 bundles working, with root included by changes_from
69
             specific_files, extra_trees, require_versioned, 
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
70
             include_root, want_unversioned)
1852.9.5 by Robert Collins
Add tests for require_versioned to the InterTree.compare() test suite.
71
            )
1852.8.4 by Robert Collins
Hook InterTree into Tree.
72
    
73
    @classmethod
74
    def is_compatible(klass, source, target):
75
        return True
76
77
78
class TestTree(TestCaseWithTransport):
79
80
    def test_compare_calls_InterTree_compare(self):
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
81
        """This test tests the way Tree.compare() uses InterTree."""
1852.8.4 by Robert Collins
Hook InterTree into Tree.
82
        old_optimisers = InterTree._optimisers
83
        try:
1910.2.15 by Aaron Bentley
Back out inter.get changes, make optimizers an ordered list
84
            InterTree._optimisers = []
1852.8.4 by Robert Collins
Hook InterTree into Tree.
85
            RecordingOptimiser.calls = []
86
            InterTree.register_optimiser(RecordingOptimiser)
87
            tree = self.make_branch_and_tree('1')
88
            tree2 = self.make_branch_and_tree('2')
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
89
            # do a series of calls:
90
            # trivial usage
1852.8.8 by Robert Collins
change Tree.compare to Tree.changes_from - its better for the common case.
91
            tree.changes_from(tree2)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
92
            # pass in all optional arguments by position
1731.1.33 by Aaron Bentley
Revert no-special-root changes
93
            tree.changes_from(tree2, 'unchanged', 'specific', 'extra', 
1910.2.57 by Aaron Bentley
Got 0.9 bundles working, with root included by changes_from
94
                              'require', True)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
95
            # pass in all optional arguments by keyword
1852.9.6 by Robert Collins
Merge the change from Tree.compare to Tree.changes_from.
96
            tree.changes_from(tree2,
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
97
                specific_files='specific',
98
                want_unchanged='unchanged',
99
                extra_trees='extra',
1852.9.5 by Robert Collins
Add tests for require_versioned to the InterTree.compare() test suite.
100
                require_versioned='require',
1910.2.57 by Aaron Bentley
Got 0.9 bundles working, with root included by changes_from
101
                include_root=True,
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
102
                want_unversioned=True,
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
103
                )
1852.8.4 by Robert Collins
Hook InterTree into Tree.
104
        finally:
105
            InterTree._optimisers = old_optimisers
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
106
        self.assertEqual(
107
            [
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
108
             ('compare', tree2, tree, False, None, None, False, False, False),
109
             ('compare', tree2, tree, 'unchanged', 'specific', 'extra',
110
              'require', True, False),
111
             ('compare', tree2, tree, 'unchanged', 'specific', 'extra',
112
              'require', True, True),
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
113
            ], RecordingOptimiser.calls)
1731.1.33 by Aaron Bentley
Revert no-special-root changes
114
115
    def test_changes_from_with_root(self):
116
        """Ensure the include_root option does what's expected."""
117
        wt = self.make_branch_and_tree('.')
118
        delta = wt.changes_from(wt.basis_tree())
119
        self.assertEqual(len(delta.added), 0)
120
        delta = wt.changes_from(wt.basis_tree(), wt, include_root=True)
121
        self.assertEqual(len(delta.added), 1)
122
        self.assertEqual(delta.added[0][0], '')