/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.15 by John Arbash Meinel
Merge bzr.dev 5597 to resolve NEWS, aka bzr-2.3.txt
1
# Copyright (C) 2006-2009, 2011 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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1852.8.2 by Robert Collins
Add InterTree class to represent InterTree operations.
16
17
"""Tests for Tree and InterTree."""
18
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
19
from breezy import (
3514.3.1 by John Arbash Meinel
Start working on a special walker that can iterate several trees at once.
20
    errors,
21
    revision,
22
    tree as _mod_tree,
23
    )
6731.1.1 by Jelmer Vernooij
Move FileTimestampUnavailable to breezy.tree.
24
from breezy.tests import (
25
    TestCase,
26
    TestCaseWithTransport,
27
    )
6731.1.5 by Jelmer Vernooij
Fix import errors.
28
from breezy.tree import (
29
    FileTimestampUnavailable,
30
    InterTree,
6883.5.2 by Jelmer Vernooij
Add find_previous_paths call.
31
    find_previous_paths,
7131.4.1 by Jelmer Vernooij
Fix get_canonical_path and add some basic tests.
32
    get_canonical_path,
6731.1.5 by Jelmer Vernooij
Fix import errors.
33
    )
1852.8.2 by Robert Collins
Add InterTree class to represent InterTree operations.
34
35
6734.1.22 by Jelmer Vernooij
review comments.
36
class TestErrors(TestCase):
6731.1.1 by Jelmer Vernooij
Move FileTimestampUnavailable to breezy.tree.
37
38
    def test_file_timestamp_unavailable(self):
39
        e = FileTimestampUnavailable("/path/foo")
40
        self.assertEqual("The filestamp for /path/foo is not available.",
41
                         str(e))
42
43
1852.8.2 by Robert Collins
Add InterTree class to represent InterTree operations.
44
class TestInterTree(TestCaseWithTransport):
45
46
    def test_revision_tree_revision_tree(self):
47
        # we should have an InterTree registered for RevisionTree to
48
        # RevisionTree.
49
        tree = self.make_branch_and_tree('.')
50
        rev_id = tree.commit('first post')
51
        rev_id2 = tree.commit('second post', allow_pointless=True)
52
        rev_tree = tree.branch.repository.revision_tree(rev_id)
53
        rev_tree2 = tree.branch.repository.revision_tree(rev_id2)
54
        optimiser = InterTree.get(rev_tree, rev_tree2)
55
        self.assertIsInstance(optimiser, InterTree)
56
        optimiser = InterTree.get(rev_tree2, rev_tree)
57
        self.assertIsInstance(optimiser, InterTree)
58
59
    def test_working_tree_revision_tree(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
60
        # we should have an InterTree available for WorkingTree to
1852.8.2 by Robert Collins
Add InterTree class to represent InterTree operations.
61
        # RevisionTree.
62
        tree = self.make_branch_and_tree('.')
63
        rev_id = tree.commit('first post')
64
        rev_tree = tree.branch.repository.revision_tree(rev_id)
65
        optimiser = InterTree.get(rev_tree, tree)
66
        self.assertIsInstance(optimiser, InterTree)
67
        optimiser = InterTree.get(tree, rev_tree)
68
        self.assertIsInstance(optimiser, InterTree)
69
70
    def test_working_tree_working_tree(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
71
        # we should have an InterTree available for WorkingTree to
1852.8.2 by Robert Collins
Add InterTree class to represent InterTree operations.
72
        # WorkingTree.
73
        tree = self.make_branch_and_tree('1')
74
        tree2 = self.make_branch_and_tree('2')
75
        optimiser = InterTree.get(tree, tree2)
76
        self.assertIsInstance(optimiser, InterTree)
77
        optimiser = InterTree.get(tree2, tree)
78
        self.assertIsInstance(optimiser, InterTree)
1852.8.4 by Robert Collins
Hook InterTree into Tree.
79
80
81
class RecordingOptimiser(InterTree):
82
83
    calls = []
84
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
85
    def compare(self, want_unchanged=False, specific_files=None,
7143.15.2 by Jelmer Vernooij
Run autopep8.
86
                extra_trees=None, require_versioned=False, include_root=False,
87
                want_unversioned=False):
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
88
        self.calls.append(
1852.9.6 by Robert Collins
Merge the change from Tree.compare to Tree.changes_from.
89
            ('compare', self.source, self.target, want_unchanged,
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
90
             specific_files, extra_trees, require_versioned,
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
91
             include_root, want_unversioned)
1852.9.5 by Robert Collins
Add tests for require_versioned to the InterTree.compare() test suite.
92
            )
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
93
7490.83.10 by Jelmer Vernooij
Fix tests.
94
    def find_source_path(self, target_path, recurse='none'):
95
        self.calls.append(
96
            ('find_source_path', self.source, self.target, target_path, recurse))
97
1852.8.4 by Robert Collins
Hook InterTree into Tree.
98
    @classmethod
99
    def is_compatible(klass, source, target):
100
        return True
101
102
103
class TestTree(TestCaseWithTransport):
104
105
    def test_compare_calls_InterTree_compare(self):
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
106
        """This test tests the way Tree.compare() uses InterTree."""
1852.8.4 by Robert Collins
Hook InterTree into Tree.
107
        old_optimisers = InterTree._optimisers
108
        try:
1910.2.15 by Aaron Bentley
Back out inter.get changes, make optimizers an ordered list
109
            InterTree._optimisers = []
1852.8.4 by Robert Collins
Hook InterTree into Tree.
110
            RecordingOptimiser.calls = []
111
            InterTree.register_optimiser(RecordingOptimiser)
112
            tree = self.make_branch_and_tree('1')
7490.83.10 by Jelmer Vernooij
Fix tests.
113
            null_tree = tree.basis_tree()
1852.8.4 by Robert Collins
Hook InterTree into Tree.
114
            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.
115
            # do a series of calls:
116
            # trivial usage
1852.8.8 by Robert Collins
change Tree.compare to Tree.changes_from - its better for the common case.
117
            tree.changes_from(tree2)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
118
            # pass in all optional arguments by position
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
119
            tree.changes_from(tree2, 'unchanged', 'specific', 'extra',
1910.2.57 by Aaron Bentley
Got 0.9 bundles working, with root included by changes_from
120
                              'require', True)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
121
            # pass in all optional arguments by keyword
1852.9.6 by Robert Collins
Merge the change from Tree.compare to Tree.changes_from.
122
            tree.changes_from(tree2,
7143.15.2 by Jelmer Vernooij
Run autopep8.
123
                              specific_files='specific',
124
                              want_unchanged='unchanged',
125
                              extra_trees='extra',
126
                              require_versioned='require',
127
                              include_root=True,
128
                              want_unversioned=True,
129
                              )
1852.8.4 by Robert Collins
Hook InterTree into Tree.
130
        finally:
131
            InterTree._optimisers = old_optimisers
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
132
        self.assertEqual(
133
            [
7490.83.10 by Jelmer Vernooij
Fix tests.
134
                ('find_source_path', null_tree, tree, '', 'none'),
135
                ('find_source_path', null_tree, tree2, '', 'none'),
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
136
                ('compare', tree2, tree, False, None, None, False, False,
137
                    False),
7143.15.2 by Jelmer Vernooij
Run autopep8.
138
                ('compare', tree2, tree, 'unchanged', 'specific', 'extra',
139
                    'require', True, False),
140
                ('compare', tree2, tree, 'unchanged', 'specific', 'extra',
141
                    'require', True, True),
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
142
            ], RecordingOptimiser.calls)
1731.1.33 by Aaron Bentley
Revert no-special-root changes
143
144
    def test_changes_from_with_root(self):
145
        """Ensure the include_root option does what's expected."""
146
        wt = self.make_branch_and_tree('.')
147
        delta = wt.changes_from(wt.basis_tree())
148
        self.assertEqual(len(delta.added), 0)
4570.2.7 by Robert Collins
Fix misuse of tree.compare API in test_tree.py
149
        delta = wt.changes_from(wt.basis_tree(), include_root=True)
1731.1.33 by Aaron Bentley
Revert no-special-root changes
150
        self.assertEqual(len(delta.added), 1)
7358.11.3 by Jelmer Vernooij
TreeDelta holds TreeChange objects rather than tuples of various sizes.
151
        self.assertEqual(delta.added[0].path[1], '')
2655.2.1 by Marius Kruger
InterTree.compare and delta._compare_trees did not pass its
152
153
    def test_changes_from_with_require_versioned(self):
154
        """Ensure the require_versioned option does what's expected."""
155
        wt = self.make_branch_and_tree('.')
156
        self.build_tree(['known_file', 'unknown_file'])
157
        wt.add('known_file')
158
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
159
        self.assertRaises(
160
            errors.PathsNotVersionedError,
161
            wt.changes_from, wt.basis_tree(), wt,
162
            specific_files=['known_file', 'unknown_file'],
163
            require_versioned=True)
2655.2.1 by Marius Kruger
InterTree.compare and delta._compare_trees did not pass its
164
165
        # we need to pass a known file with an unknown file to get this to
166
        # fail when expected.
4570.2.7 by Robert Collins
Fix misuse of tree.compare API in test_tree.py
167
        delta = wt.changes_from(wt.basis_tree(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
168
                                specific_files=['known_file', 'unknown_file'],
169
                                require_versioned=False)
2655.2.1 by Marius Kruger
InterTree.compare and delta._compare_trees did not pass its
170
        self.assertEqual(len(delta.added), 1)
3514.3.1 by John Arbash Meinel
Start working on a special walker that can iterate several trees at once.
171
172
6883.5.2 by Jelmer Vernooij
Add find_previous_paths call.
173
class FindPreviousPathsTests(TestCaseWithTransport):
174
175
    def test_new(self):
176
        tree = self.make_branch_and_tree('tree')
177
        self.build_tree(['tree/b'])
178
        tree.add(['b'])
179
        revid1 = tree.commit('first')
180
        tree1 = tree.branch.repository.revision_tree(revid1)
181
182
        tree0 = tree.branch.repository.revision_tree(revision.NULL_REVISION)
183
184
        self.assertEqual({'b': None}, find_previous_paths(tree1, tree0, ['b']))
185
186
    def test_find_previous_paths(self):
187
        tree = self.make_branch_and_tree('tree')
188
        self.build_tree(['tree/b'])
189
        tree.add(['b'])
190
        revid1 = tree.commit('first')
191
        tree1 = tree.branch.repository.revision_tree(revid1)
192
193
        tree.rename_one('b', 'c')
194
        self.build_tree(['tree/b'])
195
        tree.add(['b'])
196
        revid2 = tree.commit('second')
197
        tree2 = tree.branch.repository.revision_tree(revid2)
198
199
        self.assertEqual({'c': 'b', 'b': None},
200
                         find_previous_paths(tree2, tree1, ['b', 'c']))
7131.4.1 by Jelmer Vernooij
Fix get_canonical_path and add some basic tests.
201
202
203
class GetCanonicalPath(TestCaseWithTransport):
204
205
    def test_existing_case(self):
206
        # Test that we can find a file from a path with different case
207
        tree = self.make_branch_and_tree('tree')
208
        self.build_tree(['tree/b'])
209
        tree.add(['b'])
210
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
211
            'b',
212
            get_canonical_path(tree, 'b', lambda x: x.lower()))
7131.4.1 by Jelmer Vernooij
Fix get_canonical_path and add some basic tests.
213
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
214
            'b',
215
            get_canonical_path(tree, 'B', lambda x: x.lower()))
7131.4.1 by Jelmer Vernooij
Fix get_canonical_path and add some basic tests.
216
217
    def test_nonexistant_preserves_case(self):
218
        tree = self.make_branch_and_tree('tree')
219
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
220
            'b',
221
            get_canonical_path(tree, 'b', lambda x: x.lower()))
7131.4.1 by Jelmer Vernooij
Fix get_canonical_path and add some basic tests.
222
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
223
            'B',
224
            get_canonical_path(tree, 'B', lambda x: x.lower()))
7131.4.1 by Jelmer Vernooij
Fix get_canonical_path and add some basic tests.
225
226
    def test_in_directory_with_case(self):
227
        tree = self.make_branch_and_tree('tree')
228
        self.build_tree(['tree/a/', 'tree/a/b'])
229
        tree.add(['a', 'a/b'])
230
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
231
            'a/b',
232
            get_canonical_path(tree, 'a/b', lambda x: x.lower()))
233
        self.assertEqual(
234
            'a/b',
235
            get_canonical_path(tree, 'A/B', lambda x: x.lower()))
236
        self.assertEqual(
237
            'a/b',
238
            get_canonical_path(tree, 'A/b', lambda x: x.lower()))
239
        self.assertEqual(
240
            'a/C',
241
            get_canonical_path(tree, 'A/C', lambda x: x.lower()))