/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/tree_implementations/__init__.py

Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 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
27
27
 
28
28
from bzrlib import (
29
29
    errors,
 
30
    osutils,
 
31
    tests,
30
32
    transform,
31
33
    )
32
34
from bzrlib.transport import get_transport
35
37
                          default_transport,
36
38
                          TestCaseWithTransport,
37
39
                          TestLoader,
 
40
                          TestSkipped,
38
41
                          TestSuite,
39
42
                          )
40
43
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
41
44
from bzrlib.revisiontree import RevisionTree
42
 
from bzrlib.workingtree import (WorkingTreeFormat,
43
 
                                WorkingTreeTestProviderAdapter,
44
 
                                _legacy_formats,
45
 
                                )
 
45
from bzrlib.workingtree import (
 
46
    WorkingTreeFormat,
 
47
    WorkingTreeFormat3,
 
48
    WorkingTreeTestProviderAdapter,
 
49
    _legacy_formats,
 
50
    )
 
51
from bzrlib.workingtree_4 import (
 
52
    DirStateRevisionTree,
 
53
    WorkingTreeFormat4,
 
54
    )
46
55
 
47
56
 
48
57
def return_parameter(something):
52
61
 
53
62
def revision_tree_from_workingtree(tree):
54
63
    """Create a revision tree from a working tree."""
 
64
    revid = tree.commit('save tree', allow_pointless=True, recursive=None)
 
65
    return tree.branch.repository.revision_tree(revid)
 
66
 
 
67
 
 
68
def _dirstate_tree_from_workingtree(tree):
55
69
    revid = tree.commit('save tree', allow_pointless=True)
56
 
    return tree.branch.repository.revision_tree(revid)
 
70
    return tree.basis_tree()
57
71
 
58
72
 
59
73
class TestTreeImplementationSupport(TestCaseWithTransport):
92
106
    def _make_abc_tree(self, tree):
93
107
        """setup an abc content tree."""
94
108
        files = ['a', 'b/', 'b/c']
95
 
        self.build_tree(files, line_endings='binary', 
 
109
        self.build_tree(files, line_endings='binary',
96
110
                        transport=tree.bzrdir.root_transport)
97
111
        tree.set_root_id('root-id')
98
112
        tree.add(files, ['a-id', 'b-id', 'c-id'])
164
178
        tt.apply()
165
179
        return self._convert_tree(tree, converter)
166
180
 
 
181
    def get_tree_with_subdirs_and_all_content_types(self):
 
182
        """Return a test tree with subdirs and all content types.
 
183
 
 
184
        The returned tree has the following inventory:
 
185
            [('', inventory.ROOT_ID),
 
186
             ('0file', '2file'),
 
187
             ('1top-dir', '1top-dir'),
 
188
             (u'2utf\u1234file', u'0utf\u1234file'),
 
189
             ('symlink', 'symlink'),
 
190
             ('1top-dir/0file-in-1topdir', '1file-in-1topdir'),
 
191
             ('1top-dir/1dir-in-1topdir', '0dir-in-1topdir')]
 
192
        where each component has the type of its name - i.e. '1file..' is afile.
 
193
 
 
194
        note that the order of the paths and fileids is deliberately 
 
195
        mismatched to ensure that the result order is path based.
 
196
        """
 
197
        tree = self.make_branch_and_tree('.')
 
198
        paths = ['0file',
 
199
            '1top-dir/',
 
200
            u'2utf\u1234file',
 
201
            '1top-dir/0file-in-1topdir',
 
202
            '1top-dir/1dir-in-1topdir/'
 
203
            ]
 
204
        ids = [
 
205
            '2file',
 
206
            '1top-dir',
 
207
            u'0utf\u1234file'.encode('utf8'),
 
208
            '1file-in-1topdir',
 
209
            '0dir-in-1topdir'
 
210
            ]
 
211
        try:
 
212
            self.build_tree(paths)
 
213
        except UnicodeError:
 
214
            raise TestSkipped(
 
215
                'This platform does not support unicode file paths.')
 
216
        tree.add(paths, ids)
 
217
        tt = transform.TreeTransform(tree)
 
218
        root_transaction_id = tt.trans_id_tree_path('')
 
219
        tt.new_symlink('symlink',
 
220
            root_transaction_id, 'link-target', 'symlink')
 
221
        tt.apply()
 
222
        return self.workingtree_to_test_tree(tree)
 
223
 
 
224
    def get_tree_with_utf8(self, tree):
 
225
        """Generate a tree with a utf8 revision and unicode paths."""
 
226
        self._create_tree_with_utf8(tree)
 
227
        return self.workingtree_to_test_tree(tree)
 
228
 
 
229
    def _create_tree_with_utf8(self, tree):
 
230
        """Generate a tree with a utf8 revision and unicode paths."""
 
231
        paths = [u'',
 
232
                 u'f\xf6',
 
233
                 u'b\xe5r/',
 
234
                 u'b\xe5r/b\xe1z',
 
235
                ]
 
236
        # bzr itself does not create unicode file ids, but we want them for
 
237
        # testing.
 
238
        file_ids = ['TREE_ROOT',
 
239
                    'f\xc3\xb6-id',
 
240
                    'b\xc3\xa5r-id',
 
241
                    'b\xc3\xa1z-id',
 
242
                   ]
 
243
        try:
 
244
            self.build_tree(paths[1:])
 
245
        except UnicodeError:
 
246
            raise tests.TestSkipped('filesystem does not support unicode.')
 
247
        if tree.path2id('') is None:
 
248
            # Some trees do not have a root yet.
 
249
            tree.add(paths, file_ids)
 
250
        else:
 
251
            # Some trees will already have a root
 
252
            tree.set_root_id(file_ids[0])
 
253
            tree.add(paths[1:], file_ids[1:])
 
254
        try:
 
255
            tree.commit(u'in\xedtial', rev_id=u'r\xe9v-1'.encode('utf8'))
 
256
        except errors.NonAsciiRevisionId:
 
257
            raise tests.TestSkipped('non-ascii revision ids not supported')
 
258
 
 
259
    def get_tree_with_merged_utf8(self, tree):
 
260
        """Generate a tree with utf8 ancestors."""
 
261
        self._create_tree_with_utf8(tree)
 
262
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
 
263
        self.build_tree([u'tree2/b\xe5r/z\xf7z'])
 
264
        self.callDeprecated([osutils._file_id_warning],
 
265
                            tree2.add, [u'b\xe5r/z\xf7z'], [u'z\xf7z-id'])
 
266
        tree2.commit(u'to m\xe9rge', rev_id=u'r\xe9v-2'.encode('utf8'))
 
267
 
 
268
        tree.merge_from_branch(tree2.branch)
 
269
        tree.commit(u'm\xe9rge', rev_id=u'r\xe9v-3'.encode('utf8'))
 
270
        return self.workingtree_to_test_tree(tree)
 
271
 
167
272
 
168
273
class TreeTestProviderAdapter(WorkingTreeTestProviderAdapter):
169
274
    """Generate test suites for each Tree implementation in bzrlib.
177
282
        for adapted_test in result:
178
283
            # for working tree adapted tests, preserve the tree
179
284
            adapted_test.workingtree_to_test_tree = return_parameter
180
 
        default_format = WorkingTreeFormat.get_default_format()
 
285
        # this is the default in that it's used to test the generic InterTree
 
286
        # code.
 
287
        default_format = WorkingTreeFormat3()
181
288
        revision_tree_test = self._clone_test(
182
289
            test,
183
290
            default_format._matchingbzrdir, 
185
292
            RevisionTree.__name__)
186
293
        revision_tree_test.workingtree_to_test_tree = revision_tree_from_workingtree
187
294
        result.addTest(revision_tree_test)
 
295
        # also explicity test WorkingTree4 against everything
 
296
        dirstate_format = WorkingTreeFormat4()
 
297
        dirstate_revision_tree_test = self._clone_test(
 
298
            test,
 
299
            dirstate_format._matchingbzrdir,
 
300
            dirstate_format,
 
301
            DirStateRevisionTree.__name__)
 
302
        dirstate_revision_tree_test.workingtree_to_test_tree = _dirstate_tree_from_workingtree
 
303
        result.addTest(dirstate_revision_tree_test)
188
304
        return result
189
305
 
190
306
 
191
307
def test_suite():
192
308
    result = TestSuite()
193
309
    test_tree_implementations = [
 
310
        'bzrlib.tests.tree_implementations.test_get_file_mtime',
 
311
        'bzrlib.tests.tree_implementations.test_get_symlink_target',
 
312
        'bzrlib.tests.tree_implementations.test_list_files',
 
313
        'bzrlib.tests.tree_implementations.test_revision_tree',
194
314
        'bzrlib.tests.tree_implementations.test_test_trees',
195
315
        'bzrlib.tests.tree_implementations.test_tree',
 
316
        'bzrlib.tests.tree_implementations.test_walkdirs',
196
317
        ]
197
318
    adapter = TreeTestProviderAdapter(
198
319
        default_transport,