/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
1852.8.4 by Robert Collins
Hook InterTree into Tree.
94
    @classmethod
95
    def is_compatible(klass, source, target):
96
        return True
97
98
99
class TestTree(TestCaseWithTransport):
100
101
    def test_compare_calls_InterTree_compare(self):
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
102
        """This test tests the way Tree.compare() uses InterTree."""
1852.8.4 by Robert Collins
Hook InterTree into Tree.
103
        old_optimisers = InterTree._optimisers
104
        try:
1910.2.15 by Aaron Bentley
Back out inter.get changes, make optimizers an ordered list
105
            InterTree._optimisers = []
1852.8.4 by Robert Collins
Hook InterTree into Tree.
106
            RecordingOptimiser.calls = []
107
            InterTree.register_optimiser(RecordingOptimiser)
108
            tree = self.make_branch_and_tree('1')
109
            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.
110
            # do a series of calls:
111
            # trivial usage
1852.8.8 by Robert Collins
change Tree.compare to Tree.changes_from - its better for the common case.
112
            tree.changes_from(tree2)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
113
            # pass in all optional arguments by position
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
114
            tree.changes_from(tree2, 'unchanged', 'specific', 'extra',
1910.2.57 by Aaron Bentley
Got 0.9 bundles working, with root included by changes_from
115
                              'require', True)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
116
            # pass in all optional arguments by keyword
1852.9.6 by Robert Collins
Merge the change from Tree.compare to Tree.changes_from.
117
            tree.changes_from(tree2,
7143.15.2 by Jelmer Vernooij
Run autopep8.
118
                              specific_files='specific',
119
                              want_unchanged='unchanged',
120
                              extra_trees='extra',
121
                              require_versioned='require',
122
                              include_root=True,
123
                              want_unversioned=True,
124
                              )
1852.8.4 by Robert Collins
Hook InterTree into Tree.
125
        finally:
126
            InterTree._optimisers = old_optimisers
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
127
        self.assertEqual(
128
            [
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
129
                ('compare', tree2, tree, False, None, None, False, False,
130
                    False),
7143.15.2 by Jelmer Vernooij
Run autopep8.
131
                ('compare', tree2, tree, 'unchanged', 'specific', 'extra',
132
                    'require', True, False),
133
                ('compare', tree2, tree, 'unchanged', 'specific', 'extra',
134
                    'require', True, True),
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
135
            ], RecordingOptimiser.calls)
1731.1.33 by Aaron Bentley
Revert no-special-root changes
136
137
    def test_changes_from_with_root(self):
138
        """Ensure the include_root option does what's expected."""
139
        wt = self.make_branch_and_tree('.')
140
        delta = wt.changes_from(wt.basis_tree())
141
        self.assertEqual(len(delta.added), 0)
4570.2.7 by Robert Collins
Fix misuse of tree.compare API in test_tree.py
142
        delta = wt.changes_from(wt.basis_tree(), include_root=True)
1731.1.33 by Aaron Bentley
Revert no-special-root changes
143
        self.assertEqual(len(delta.added), 1)
7358.11.3 by Jelmer Vernooij
TreeDelta holds TreeChange objects rather than tuples of various sizes.
144
        self.assertEqual(delta.added[0].path[1], '')
2655.2.1 by Marius Kruger
InterTree.compare and delta._compare_trees did not pass its
145
146
    def test_changes_from_with_require_versioned(self):
147
        """Ensure the require_versioned option does what's expected."""
148
        wt = self.make_branch_and_tree('.')
149
        self.build_tree(['known_file', 'unknown_file'])
150
        wt.add('known_file')
151
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
152
        self.assertRaises(
153
            errors.PathsNotVersionedError,
154
            wt.changes_from, wt.basis_tree(), wt,
155
            specific_files=['known_file', 'unknown_file'],
156
            require_versioned=True)
2655.2.1 by Marius Kruger
InterTree.compare and delta._compare_trees did not pass its
157
158
        # we need to pass a known file with an unknown file to get this to
159
        # fail when expected.
4570.2.7 by Robert Collins
Fix misuse of tree.compare API in test_tree.py
160
        delta = wt.changes_from(wt.basis_tree(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
161
                                specific_files=['known_file', 'unknown_file'],
162
                                require_versioned=False)
2655.2.1 by Marius Kruger
InterTree.compare and delta._compare_trees did not pass its
163
        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.
164
165
6883.5.2 by Jelmer Vernooij
Add find_previous_paths call.
166
class FindPreviousPathsTests(TestCaseWithTransport):
167
168
    def test_new(self):
169
        tree = self.make_branch_and_tree('tree')
170
        self.build_tree(['tree/b'])
171
        tree.add(['b'])
172
        revid1 = tree.commit('first')
173
        tree1 = tree.branch.repository.revision_tree(revid1)
174
175
        tree0 = tree.branch.repository.revision_tree(revision.NULL_REVISION)
176
177
        self.assertEqual({'b': None}, find_previous_paths(tree1, tree0, ['b']))
178
179
    def test_find_previous_paths(self):
180
        tree = self.make_branch_and_tree('tree')
181
        self.build_tree(['tree/b'])
182
        tree.add(['b'])
183
        revid1 = tree.commit('first')
184
        tree1 = tree.branch.repository.revision_tree(revid1)
185
186
        tree.rename_one('b', 'c')
187
        self.build_tree(['tree/b'])
188
        tree.add(['b'])
189
        revid2 = tree.commit('second')
190
        tree2 = tree.branch.repository.revision_tree(revid2)
191
192
        self.assertEqual({'c': 'b', 'b': None},
193
                         find_previous_paths(tree2, tree1, ['b', 'c']))
7131.4.1 by Jelmer Vernooij
Fix get_canonical_path and add some basic tests.
194
195
196
class GetCanonicalPath(TestCaseWithTransport):
197
198
    def test_existing_case(self):
199
        # Test that we can find a file from a path with different case
200
        tree = self.make_branch_and_tree('tree')
201
        self.build_tree(['tree/b'])
202
        tree.add(['b'])
203
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
204
            'b',
205
            get_canonical_path(tree, 'b', lambda x: x.lower()))
7131.4.1 by Jelmer Vernooij
Fix get_canonical_path and add some basic tests.
206
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
207
            'b',
208
            get_canonical_path(tree, 'B', lambda x: x.lower()))
7131.4.1 by Jelmer Vernooij
Fix get_canonical_path and add some basic tests.
209
210
    def test_nonexistant_preserves_case(self):
211
        tree = self.make_branch_and_tree('tree')
212
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
213
            'b',
214
            get_canonical_path(tree, 'b', lambda x: x.lower()))
7131.4.1 by Jelmer Vernooij
Fix get_canonical_path and add some basic tests.
215
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
216
            'B',
217
            get_canonical_path(tree, 'B', lambda x: x.lower()))
7131.4.1 by Jelmer Vernooij
Fix get_canonical_path and add some basic tests.
218
219
    def test_in_directory_with_case(self):
220
        tree = self.make_branch_and_tree('tree')
221
        self.build_tree(['tree/a/', 'tree/a/b'])
222
        tree.add(['a', 'a/b'])
223
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
224
            'a/b',
225
            get_canonical_path(tree, 'a/b', lambda x: x.lower()))
226
        self.assertEqual(
227
            'a/b',
228
            get_canonical_path(tree, 'A/B', lambda x: x.lower()))
229
        self.assertEqual(
230
            'a/b',
231
            get_canonical_path(tree, 'A/b', lambda x: x.lower()))
232
        self.assertEqual(
233
            'a/C',
234
            get_canonical_path(tree, 'A/C', lambda x: x.lower()))