~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/tree_implementations/__init__.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by 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
 
from bzrlib.tree import RevisionTree
42
 
from bzrlib.workingtree import (WorkingTreeFormat,
43
 
                                WorkingTreeTestProviderAdapter,
44
 
                                _legacy_formats,
45
 
                                )
 
44
from bzrlib.tests.workingtree_implementations import (
 
45
    WorkingTreeTestProviderAdapter,
 
46
    )
 
47
from bzrlib.revisiontree import RevisionTree
 
48
from bzrlib.workingtree import (
 
49
    WorkingTreeFormat,
 
50
    WorkingTreeFormat3,
 
51
    _legacy_formats,
 
52
    )
 
53
from bzrlib.workingtree_4 import (
 
54
    DirStateRevisionTree,
 
55
    WorkingTreeFormat4,
 
56
    )
46
57
 
47
58
 
48
59
def return_parameter(something):
52
63
 
53
64
def revision_tree_from_workingtree(tree):
54
65
    """Create a revision tree from a working tree."""
 
66
    revid = tree.commit('save tree', allow_pointless=True, recursive=None)
 
67
    return tree.branch.repository.revision_tree(revid)
 
68
 
 
69
 
 
70
def _dirstate_tree_from_workingtree(tree):
55
71
    revid = tree.commit('save tree', allow_pointless=True)
56
 
    return tree.branch.repository.revision_tree(revid)
 
72
    return tree.basis_tree()
57
73
 
58
74
 
59
75
class TestTreeImplementationSupport(TestCaseWithTransport):
86
102
        :param empty_tree: A working tree with no content and no parents to
87
103
            modify.
88
104
        """
 
105
        empty_tree.set_root_id('empty-root-id')
89
106
        return self._convert_tree(empty_tree, converter)
90
107
 
91
108
    def _make_abc_tree(self, tree):
93
110
        files = ['a', 'b/', 'b/c']
94
111
        self.build_tree(files, line_endings='binary',
95
112
                        transport=tree.bzrdir.root_transport)
 
113
        tree.set_root_id('root-id')
96
114
        tree.add(files, ['a-id', 'b-id', 'c-id'])
97
115
 
98
116
    def get_tree_no_parents_abc_content(self, tree, converter=None):
162
180
        tt.apply()
163
181
        return self._convert_tree(tree, converter)
164
182
 
 
183
    def get_tree_with_subdirs_and_all_content_types(self):
 
184
        """Return a test tree with subdirs and all content types.
 
185
        See get_tree_with_subdirs_and_all_supported_content_types for details.
 
186
        """
 
187
        return self.get_tree_with_subdirs_and_all_supported_content_types(True)
 
188
 
 
189
    def get_tree_with_subdirs_and_all_supported_content_types(self, symlinks):
 
190
        """Return a test tree with subdirs and all supported content types.
 
191
        Some content types may not be created on some platforms
 
192
        (like symlinks on native win32)
 
193
 
 
194
        :param  symlinks:   control is symlink should be created in the tree.
 
195
                            Note: if you wish to automatically set this
 
196
                            parameters depending on underlying system,
 
197
                            please use value returned
 
198
                            by bzrlib.osutils.has_symlinks() function.
 
199
 
 
200
        The returned tree has the following inventory:
 
201
            [('', inventory.ROOT_ID),
 
202
             ('0file', '2file'),
 
203
             ('1top-dir', '1top-dir'),
 
204
             (u'2utf\u1234file', u'0utf\u1234file'),
 
205
             ('symlink', 'symlink'),            # only if symlinks arg is True
 
206
             ('1top-dir/0file-in-1topdir', '1file-in-1topdir'),
 
207
             ('1top-dir/1dir-in-1topdir', '0dir-in-1topdir')]
 
208
        where each component has the type of its name -
 
209
        i.e. '1file..' is afile.
 
210
 
 
211
        note that the order of the paths and fileids is deliberately 
 
212
        mismatched to ensure that the result order is path based.
 
213
        """
 
214
        tree = self.make_branch_and_tree('.')
 
215
        paths = ['0file',
 
216
            '1top-dir/',
 
217
            u'2utf\u1234file',
 
218
            '1top-dir/0file-in-1topdir',
 
219
            '1top-dir/1dir-in-1topdir/'
 
220
            ]
 
221
        ids = [
 
222
            '2file',
 
223
            '1top-dir',
 
224
            u'0utf\u1234file'.encode('utf8'),
 
225
            '1file-in-1topdir',
 
226
            '0dir-in-1topdir'
 
227
            ]
 
228
        try:
 
229
            self.build_tree(paths)
 
230
        except UnicodeError:
 
231
            raise TestSkipped(
 
232
                'This platform does not support unicode file paths.')
 
233
        tree.add(paths, ids)
 
234
        tt = transform.TreeTransform(tree)
 
235
        if symlinks:
 
236
            root_transaction_id = tt.trans_id_tree_path('')
 
237
            tt.new_symlink('symlink',
 
238
                root_transaction_id, 'link-target', 'symlink')
 
239
        tt.apply()
 
240
        return self.workingtree_to_test_tree(tree)
 
241
 
 
242
    def get_tree_with_utf8(self, tree):
 
243
        """Generate a tree with a utf8 revision and unicode paths."""
 
244
        self._create_tree_with_utf8(tree)
 
245
        return self.workingtree_to_test_tree(tree)
 
246
 
 
247
    def _create_tree_with_utf8(self, tree):
 
248
        """Generate a tree with a utf8 revision and unicode paths."""
 
249
        paths = [u'',
 
250
                 u'f\xf6',
 
251
                 u'b\xe5r/',
 
252
                 u'b\xe5r/b\xe1z',
 
253
                ]
 
254
        # bzr itself does not create unicode file ids, but we want them for
 
255
        # testing.
 
256
        file_ids = ['TREE_ROOT',
 
257
                    'f\xc3\xb6-id',
 
258
                    'b\xc3\xa5r-id',
 
259
                    'b\xc3\xa1z-id',
 
260
                   ]
 
261
        try:
 
262
            self.build_tree(paths[1:])
 
263
        except UnicodeError:
 
264
            raise tests.TestSkipped('filesystem does not support unicode.')
 
265
        if tree.path2id('') is None:
 
266
            # Some trees do not have a root yet.
 
267
            tree.add(paths, file_ids)
 
268
        else:
 
269
            # Some trees will already have a root
 
270
            tree.set_root_id(file_ids[0])
 
271
            tree.add(paths[1:], file_ids[1:])
 
272
        try:
 
273
            tree.commit(u'in\xedtial', rev_id=u'r\xe9v-1'.encode('utf8'))
 
274
        except errors.NonAsciiRevisionId:
 
275
            raise tests.TestSkipped('non-ascii revision ids not supported')
 
276
 
 
277
    def get_tree_with_merged_utf8(self, tree):
 
278
        """Generate a tree with utf8 ancestors."""
 
279
        self._create_tree_with_utf8(tree)
 
280
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
 
281
        self.build_tree([u'tree2/b\xe5r/z\xf7z'])
 
282
        self.callDeprecated([osutils._file_id_warning],
 
283
                            tree2.add, [u'b\xe5r/z\xf7z'], [u'z\xf7z-id'])
 
284
        tree2.commit(u'to m\xe9rge', rev_id=u'r\xe9v-2'.encode('utf8'))
 
285
 
 
286
        tree.merge_from_branch(tree2.branch)
 
287
        tree.commit(u'm\xe9rge', rev_id=u'r\xe9v-3'.encode('utf8'))
 
288
        return self.workingtree_to_test_tree(tree)
 
289
 
165
290
 
166
291
class TreeTestProviderAdapter(WorkingTreeTestProviderAdapter):
167
292
    """Generate test suites for each Tree implementation in bzrlib.
168
293
 
169
 
    Currently this covers all working tree formats, and RevisionTree by 
170
 
    committing a working tree to create the revision tree.
 
294
    Currently this covers all working tree formats, and RevisionTree and
 
295
    DirStateRevisionTree by committing a working tree to create the revision
 
296
    tree.
171
297
    """
172
298
 
173
 
    def adapt(self, test):
174
 
        result = super(TreeTestProviderAdapter, self).adapt(test)
175
 
        for adapted_test in result:
 
299
    def __init__(self, transport_server, transport_readonly_server, formats):
 
300
        super(TreeTestProviderAdapter, self).__init__(transport_server,
 
301
            transport_readonly_server, formats)
 
302
        # now adjust the scenarios and add the non-working-tree tree scenarios.
 
303
        for scenario in self.scenarios:
176
304
            # for working tree adapted tests, preserve the tree
177
 
            adapted_test.workingtree_to_test_tree = return_parameter
178
 
        default_format = WorkingTreeFormat.get_default_format()
179
 
        revision_tree_test = self._clone_test(
180
 
            test,
181
 
            default_format._matchingbzrdir, 
182
 
            default_format,
183
 
            RevisionTree.__name__)
184
 
        revision_tree_test.workingtree_to_test_tree = revision_tree_from_workingtree
185
 
        result.addTest(revision_tree_test)
186
 
        return result
 
305
            scenario[1]["workingtree_to_test_tree"] = return_parameter
 
306
        # add RevisionTree scenario
 
307
        # this is the 'default format' in that it's used to test the generic InterTree
 
308
        # code.
 
309
        default_format = WorkingTreeFormat3()
 
310
        self.scenarios.append(self.formats_to_scenarios([
 
311
            (default_format, default_format._matchingbzrdir)])[0])
 
312
        self.scenarios[-1] = (RevisionTree.__name__, self.scenarios[-1][1])
 
313
        self.scenarios[-1][1]["workingtree_to_test_tree"] = revision_tree_from_workingtree
 
314
 
 
315
        # also test WorkingTree4's RevisionTree implementation which is specialised.
 
316
        dirstate_format = WorkingTreeFormat4()
 
317
        self.scenarios.append(self.formats_to_scenarios([
 
318
            (dirstate_format, dirstate_format._matchingbzrdir)])[0])
 
319
        self.scenarios[-1] = (DirStateRevisionTree.__name__, self.scenarios[-1][1])
 
320
        self.scenarios[-1][1]["workingtree_to_test_tree"] = _dirstate_tree_from_workingtree
187
321
 
188
322
 
189
323
def test_suite():
190
324
    result = TestSuite()
191
325
    test_tree_implementations = [
 
326
        'bzrlib.tests.tree_implementations.test_get_file_mtime',
 
327
        'bzrlib.tests.tree_implementations.test_get_symlink_target',
 
328
        'bzrlib.tests.tree_implementations.test_inv',
 
329
        'bzrlib.tests.tree_implementations.test_list_files',
 
330
        'bzrlib.tests.tree_implementations.test_revision_tree',
192
331
        'bzrlib.tests.tree_implementations.test_test_trees',
 
332
        'bzrlib.tests.tree_implementations.test_tree',
 
333
        'bzrlib.tests.tree_implementations.test_walkdirs',
193
334
        ]
194
335
    adapter = TreeTestProviderAdapter(
195
336
        default_transport,