/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_tree.py

  • Committer: Robert Collins
  • Date: 2007-04-19 02:27:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2426.
  • Revision ID: robertc@robertcollins.net-20070419022744-pfdqz42kp1wizh43
``make docs`` now creates a man page at ``man1/bzr.1`` fixing bug 107388.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2009, 2011 Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Tests for Tree and InterTree."""
18
18
 
19
 
from breezy import (
20
 
    errors,
21
 
    revision,
22
 
    tree as _mod_tree,
23
 
    )
24
 
from breezy.tests import (
25
 
    TestCase,
26
 
    TestCaseWithTransport,
27
 
    )
28
 
from breezy.tree import (
29
 
    FileTimestampUnavailable,
30
 
    InterTree,
31
 
    find_previous_paths,
32
 
    get_canonical_path,
33
 
    )
34
 
 
35
 
 
36
 
class TestErrors(TestCase):
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))
 
19
from bzrlib.tests import TestCaseWithTransport
 
20
from bzrlib.tree import InterTree
42
21
 
43
22
 
44
23
class TestInterTree(TestCaseWithTransport):
57
36
        self.assertIsInstance(optimiser, InterTree)
58
37
 
59
38
    def test_working_tree_revision_tree(self):
60
 
        # we should have an InterTree available for WorkingTree to
 
39
        # we should have an InterTree available for WorkingTree to 
61
40
        # RevisionTree.
62
41
        tree = self.make_branch_and_tree('.')
63
42
        rev_id = tree.commit('first post')
68
47
        self.assertIsInstance(optimiser, InterTree)
69
48
 
70
49
    def test_working_tree_working_tree(self):
71
 
        # we should have an InterTree available for WorkingTree to
 
50
        # we should have an InterTree available for WorkingTree to 
72
51
        # WorkingTree.
73
52
        tree = self.make_branch_and_tree('1')
74
53
        tree2 = self.make_branch_and_tree('2')
83
62
    calls = []
84
63
 
85
64
    def compare(self, want_unchanged=False, specific_files=None,
86
 
                extra_trees=None, require_versioned=False, include_root=False,
87
 
                want_unversioned=False):
 
65
        extra_trees=None, require_versioned=False, include_root=False,
 
66
        want_unversioned=False):
88
67
        self.calls.append(
89
68
            ('compare', self.source, self.target, want_unchanged,
90
 
             specific_files, extra_trees, require_versioned,
 
69
             specific_files, extra_trees, require_versioned, 
91
70
             include_root, want_unversioned)
92
71
            )
93
 
 
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
 
 
 
72
    
98
73
    @classmethod
99
74
    def is_compatible(klass, source, target):
100
75
        return True
110
85
            RecordingOptimiser.calls = []
111
86
            InterTree.register_optimiser(RecordingOptimiser)
112
87
            tree = self.make_branch_and_tree('1')
113
 
            null_tree = tree.basis_tree()
114
88
            tree2 = self.make_branch_and_tree('2')
115
89
            # do a series of calls:
116
90
            # trivial usage
117
91
            tree.changes_from(tree2)
118
92
            # pass in all optional arguments by position
119
 
            tree.changes_from(tree2, 'unchanged', 'specific', 'extra',
 
93
            tree.changes_from(tree2, 'unchanged', 'specific', 'extra', 
120
94
                              'require', True)
121
95
            # pass in all optional arguments by keyword
122
96
            tree.changes_from(tree2,
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
 
                              )
 
97
                specific_files='specific',
 
98
                want_unchanged='unchanged',
 
99
                extra_trees='extra',
 
100
                require_versioned='require',
 
101
                include_root=True,
 
102
                want_unversioned=True,
 
103
                )
130
104
        finally:
131
105
            InterTree._optimisers = old_optimisers
132
106
        self.assertEqual(
133
107
            [
134
 
                ('find_source_path', null_tree, tree, '', 'none'),
135
 
                ('find_source_path', null_tree, tree2, '', 'none'),
136
 
                ('compare', tree2, tree, False, None, None, False, False,
137
 
                    False),
138
 
                ('compare', tree2, tree, 'unchanged', 'specific', 'extra',
139
 
                    'require', True, False),
140
 
                ('compare', tree2, tree, 'unchanged', 'specific', 'extra',
141
 
                    'require', True, True),
 
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),
142
113
            ], RecordingOptimiser.calls)
143
114
 
144
115
    def test_changes_from_with_root(self):
146
117
        wt = self.make_branch_and_tree('.')
147
118
        delta = wt.changes_from(wt.basis_tree())
148
119
        self.assertEqual(len(delta.added), 0)
149
 
        delta = wt.changes_from(wt.basis_tree(), include_root=True)
150
 
        self.assertEqual(len(delta.added), 1)
151
 
        self.assertEqual(delta.added[0].path[1], '')
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
 
 
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)
164
 
 
165
 
        # we need to pass a known file with an unknown file to get this to
166
 
        # fail when expected.
167
 
        delta = wt.changes_from(wt.basis_tree(),
168
 
                                specific_files=['known_file', 'unknown_file'],
169
 
                                require_versioned=False)
170
 
        self.assertEqual(len(delta.added), 1)
171
 
 
172
 
 
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']))
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(
211
 
            'b',
212
 
            get_canonical_path(tree, 'b', lambda x: x.lower()))
213
 
        self.assertEqual(
214
 
            'b',
215
 
            get_canonical_path(tree, 'B', lambda x: x.lower()))
216
 
 
217
 
    def test_nonexistant_preserves_case(self):
218
 
        tree = self.make_branch_and_tree('tree')
219
 
        self.assertEqual(
220
 
            'b',
221
 
            get_canonical_path(tree, 'b', lambda x: x.lower()))
222
 
        self.assertEqual(
223
 
            'B',
224
 
            get_canonical_path(tree, 'B', lambda x: x.lower()))
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(
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()))
 
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], '')