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

  • Committer: Martin von Gagern
  • Date: 2010-04-20 08:47:38 UTC
  • mfrom: (5167 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5195.
  • Revision ID: martin.vgagern@gmx.net-20100420084738-ygymnqmdllzrhpfn
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2006-2010 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
18
"""Tree implementation tests for bzr.
19
19
 
20
20
These test the conformance of all the tree variations to the expected API.
21
21
Specific tests for individual variations are in other places such as:
 
22
 - tests/per_workingtree/*.py.
22
23
 - tests/test_tree.py
23
24
 - tests/test_revision.py
24
25
 - tests/test_workingtree.py
25
 
 - tests/workingtree_implementations/*.py.
26
26
"""
27
27
 
28
28
from bzrlib import (
32
32
    tests,
33
33
    transform,
34
34
    )
35
 
from bzrlib.transport import get_transport
36
 
from bzrlib.tests import (
37
 
                          adapt_modules,
38
 
                          default_transport,
39
 
                          TestCaseWithTransport,
40
 
                          TestSkipped,
41
 
                          )
42
 
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
43
 
from bzrlib.tests.workingtree_implementations import (
44
 
    WorkingTreeTestProviderAdapter,
 
35
from bzrlib.tests.per_bzrdir.test_bzrdir import TestCaseWithBzrDir
 
36
from bzrlib.tests.per_workingtree import (
 
37
    make_scenarios as wt_make_scenarios,
 
38
    make_scenario as wt_make_scenario,
45
39
    )
46
40
from bzrlib.revision import NULL_REVISION
47
41
from bzrlib.revisiontree import RevisionTree
54
48
from bzrlib.workingtree_4 import (
55
49
    DirStateRevisionTree,
56
50
    WorkingTreeFormat4,
 
51
    WorkingTreeFormat5,
57
52
    )
58
53
 
59
54
 
85
80
    basis = tree.basis_tree()
86
81
    tt = TransformPreview(basis)
87
82
    testcase.addCleanup(tt.finalize)
88
 
    pp = progress.ProgressPhase('', 1, progress.DummyProgress())
89
83
    tree.lock_read()
90
84
    testcase.addCleanup(tree.unlock)
91
 
    transform._prepare_revert_transform(basis, tree, tt, None, False, pp,
 
85
    pp = None
 
86
    transform._prepare_revert_transform(basis, tree, tt, None, False, None,
92
87
                                        basis, {})
93
88
    preview_tree = tt.get_preview_tree()
94
89
    preview_tree.set_parent_ids(tree.get_parent_ids())
95
90
    return preview_tree
96
91
 
97
92
 
98
 
class TestTreeImplementationSupport(TestCaseWithTransport):
 
93
class TestTreeImplementationSupport(tests.TestCaseWithTransport):
99
94
 
100
95
    def test_revision_tree_from_workingtree(self):
101
96
        tree = self.make_branch_and_tree('.')
124
119
 
125
120
    def get_tree_no_parents_no_content(self, empty_tree, converter=None):
126
121
        """Make a tree with no parents and no contents from empty_tree.
127
 
        
 
122
 
128
123
        :param empty_tree: A working tree with no content and no parents to
129
124
            modify.
130
125
        """
146
141
 
147
142
    def get_tree_no_parents_abc_content_2(self, tree, converter=None):
148
143
        """return a test tree with a, b/, b/c contents.
149
 
        
 
144
 
150
145
        This variation changes the content of 'a' to foobar\n.
151
146
        """
152
147
        self._make_abc_tree(tree)
159
154
 
160
155
    def get_tree_no_parents_abc_content_3(self, tree, converter=None):
161
156
        """return a test tree with a, b/, b/c contents.
162
 
        
 
157
 
163
158
        This variation changes the executable flag of b/c to True.
164
159
        """
165
160
        self._make_abc_tree(tree)
171
166
 
172
167
    def get_tree_no_parents_abc_content_4(self, tree, converter=None):
173
168
        """return a test tree with d, b/, b/c contents.
174
 
        
 
169
 
175
170
        This variation renames a to d.
176
171
        """
177
172
        self._make_abc_tree(tree)
180
175
 
181
176
    def get_tree_no_parents_abc_content_5(self, tree, converter=None):
182
177
        """return a test tree with d, b/, b/c contents.
183
 
        
 
178
 
184
179
        This variation renames a to d and alters its content to 'bar\n'.
185
180
        """
186
181
        self._make_abc_tree(tree)
194
189
 
195
190
    def get_tree_no_parents_abc_content_6(self, tree, converter=None):
196
191
        """return a test tree with a, b/, e contents.
197
 
        
 
192
 
198
193
        This variation renames b/c to e, and makes it executable.
199
194
        """
200
195
        self._make_abc_tree(tree)
206
201
        tt.apply()
207
202
        return self._convert_tree(tree, converter)
208
203
 
 
204
    def get_tree_no_parents_abc_content_7(self, tree, converter=None):
 
205
        """return a test tree with a, b/, d/e contents.
 
206
 
 
207
        This variation adds a dir 'd' ('d-id'), renames b to d/e.
 
208
        """
 
209
        self._make_abc_tree(tree)
 
210
        self.build_tree(['d/'], transport=tree.bzrdir.root_transport)
 
211
        tree.add(['d'], ['d-id'])
 
212
        tt = transform.TreeTransform(tree)
 
213
        trans_id = tt.trans_id_tree_path('b')
 
214
        parent_trans_id = tt.trans_id_tree_path('d')
 
215
        tt.adjust_path('e', parent_trans_id, trans_id)
 
216
        tt.apply()
 
217
        return self._convert_tree(tree, converter)
 
218
 
209
219
    def get_tree_with_subdirs_and_all_content_types(self):
210
220
        """Return a test tree with subdirs and all content types.
211
221
        See get_tree_with_subdirs_and_all_supported_content_types for details.
234
244
        where each component has the type of its name -
235
245
        i.e. '1file..' is afile.
236
246
 
237
 
        note that the order of the paths and fileids is deliberately 
 
247
        note that the order of the paths and fileids is deliberately
238
248
        mismatched to ensure that the result order is path based.
239
249
        """
 
250
        self.requireFeature(tests.UnicodeFilenameFeature)
240
251
        tree = self.make_branch_and_tree('.')
241
252
        paths = ['0file',
242
253
            '1top-dir/',
251
262
            '1file-in-1topdir',
252
263
            '0dir-in-1topdir'
253
264
            ]
254
 
        try:
255
 
            self.build_tree(paths)
256
 
        except UnicodeError:
257
 
            raise TestSkipped(
258
 
                'This platform does not support unicode file paths.')
 
265
        self.build_tree(paths)
259
266
        tree.add(paths, ids)
260
267
        tt = transform.TreeTransform(tree)
261
268
        if symlinks:
272
279
 
273
280
    def _create_tree_with_utf8(self, tree):
274
281
        """Generate a tree with a utf8 revision and unicode paths."""
 
282
        self.requireFeature(tests.UnicodeFilenameFeature)
275
283
        # We avoid combining characters in file names here, normalization
276
284
        # checks (as performed by some file systems (OSX) are outside the scope
277
285
        # of these tests).  We use the euro sign \N{Euro Sign} or \u20ac in
288
296
                    'ba\xe2\x82\xacr-id',
289
297
                    'ba\xe2\x82\xacz-id',
290
298
                   ]
291
 
        try:
292
 
            self.build_tree(paths[1:])
293
 
        except UnicodeError:
294
 
            raise tests.TestSkipped('filesystem does not support unicode.')
 
299
        self.build_tree(paths[1:])
295
300
        if tree.get_root_id() is None:
296
301
            # Some trees do not have a root yet.
297
302
            tree.add(paths, file_ids)
318
323
        return self.workingtree_to_test_tree(tree)
319
324
 
320
325
 
321
 
class TreeTestProviderAdapter(WorkingTreeTestProviderAdapter):
 
326
def make_scenarios(transport_server, transport_readonly_server, formats):
322
327
    """Generate test suites for each Tree implementation in bzrlib.
323
328
 
324
329
    Currently this covers all working tree formats, and RevisionTree and
325
330
    DirStateRevisionTree by committing a working tree to create the revision
326
331
    tree.
327
332
    """
328
 
 
329
 
    def __init__(self, transport_server, transport_readonly_server, formats):
330
 
        """Create a TreeTestProviderAdapter.
331
 
 
332
 
        :param formats: [workingtree_format]
333
 
        """
334
 
        super(TreeTestProviderAdapter, self).__init__(transport_server,
335
 
            transport_readonly_server, formats)
336
 
        # now adjust the scenarios and add the non-working-tree tree scenarios.
337
 
        for scenario in self.scenarios:
338
 
            # for working tree adapted tests, preserve the tree
339
 
            scenario[1]["_workingtree_to_test_tree"] = return_parameter
340
 
        # add RevisionTree scenario
341
 
        self.scenarios.append(self.create_tree_scenario(RevisionTree.__name__,
342
 
                              revision_tree_from_workingtree,))
343
 
 
344
 
        # also test WorkingTree4's RevisionTree implementation which is
345
 
        # specialised.
346
 
        self.scenarios.append(self.create_tree_scenario(
347
 
            DirStateRevisionTree.__name__, _dirstate_tree_from_workingtree,
348
 
            WorkingTreeFormat4()))
349
 
        self.scenarios.append(self.create_tree_scenario('PreviewTree',
350
 
            preview_tree_pre))
351
 
        self.scenarios.append(self.create_tree_scenario('PreviewTreePost',
352
 
            preview_tree_post))
353
 
 
354
 
    def create_tree_scenario(self, name, converter, workingtree_format=None):
355
 
        """Create a scenario for the specified converter
356
 
 
357
 
        :param name: The name to append to tests using this converter
358
 
        :param converter: A function that converts a workingtree into the
359
 
            desired format.
360
 
        :param workingtree_format: The particular workingtree format to
361
 
            convert from.
362
 
        :return: a (name, options) tuple, where options is a dict of values
363
 
            to be used as members of the TestCase.
364
 
        """
365
 
        if workingtree_format is None:
366
 
            workingtree_format = WorkingTreeFormat._default_format
367
 
        scenario_options = WorkingTreeTestProviderAdapter.create_scenario(self,
368
 
            workingtree_format)[1]
369
 
        scenario_options["_workingtree_to_test_tree"] = converter
370
 
        return name, scenario_options
371
 
 
372
 
 
373
 
def load_tests(basic_tests, module, loader):
374
 
    result = loader.suiteClass()
375
 
    # add the tests for this module
376
 
    result.addTests(basic_tests)
377
 
 
378
 
    test_tree_implementations = [
379
 
        'bzrlib.tests.tree_implementations.test_annotate_iter',
380
 
        'bzrlib.tests.tree_implementations.test_get_file_mtime',
381
 
        'bzrlib.tests.tree_implementations.test_get_root_id',
382
 
        'bzrlib.tests.tree_implementations.test_get_symlink_target',
383
 
        'bzrlib.tests.tree_implementations.test_inv',
384
 
        'bzrlib.tests.tree_implementations.test_iter_search_rules',
385
 
        'bzrlib.tests.tree_implementations.test_list_files',
386
 
        'bzrlib.tests.tree_implementations.test_path_content_summary',
387
 
        'bzrlib.tests.tree_implementations.test_revision_tree',
388
 
        'bzrlib.tests.tree_implementations.test_test_trees',
389
 
        'bzrlib.tests.tree_implementations.test_tree',
390
 
        'bzrlib.tests.tree_implementations.test_walkdirs',
 
333
    scenarios = wt_make_scenarios(transport_server, transport_readonly_server,
 
334
        formats)
 
335
    # now adjust the scenarios and add the non-working-tree tree scenarios.
 
336
    for scenario in scenarios:
 
337
        # for working tree format tests, preserve the tree
 
338
        scenario[1]["_workingtree_to_test_tree"] = return_parameter
 
339
    # add RevisionTree scenario
 
340
    workingtree_format = WorkingTreeFormat._default_format
 
341
    scenarios.append((RevisionTree.__name__,
 
342
        create_tree_scenario(transport_server, transport_readonly_server,
 
343
        workingtree_format, revision_tree_from_workingtree,)))
 
344
 
 
345
    # also test WorkingTree4/5's RevisionTree implementation which is
 
346
    # specialised.
 
347
    # XXX: Ask igc if WT5 revision tree actually is different.
 
348
    scenarios.append((DirStateRevisionTree.__name__ + ",WT4",
 
349
        create_tree_scenario(transport_server, transport_readonly_server,
 
350
        WorkingTreeFormat4(), _dirstate_tree_from_workingtree)))
 
351
    scenarios.append((DirStateRevisionTree.__name__ + ",WT5",
 
352
        create_tree_scenario(transport_server, transport_readonly_server,
 
353
        WorkingTreeFormat5(), _dirstate_tree_from_workingtree)))
 
354
    scenarios.append(("PreviewTree", create_tree_scenario(transport_server,
 
355
        transport_readonly_server, workingtree_format, preview_tree_pre)))
 
356
    scenarios.append(("PreviewTreePost", create_tree_scenario(transport_server,
 
357
        transport_readonly_server, workingtree_format, preview_tree_post)))
 
358
    return scenarios
 
359
 
 
360
 
 
361
def create_tree_scenario(transport_server, transport_readonly_server,
 
362
    workingtree_format, converter):
 
363
    """Create a scenario for the specified converter
 
364
 
 
365
    :param converter: A function that converts a workingtree into the
 
366
        desired format.
 
367
    :param workingtree_format: The particular workingtree format to
 
368
        convert from.
 
369
    :return: a (name, options) tuple, where options is a dict of values
 
370
        to be used as members of the TestCase.
 
371
    """
 
372
    scenario_options = wt_make_scenario(transport_server,
 
373
                                        transport_readonly_server,
 
374
                                        workingtree_format)
 
375
    scenario_options["_workingtree_to_test_tree"] = converter
 
376
    return scenario_options
 
377
 
 
378
 
 
379
def load_tests(standard_tests, module, loader):
 
380
    per_tree_mod_names = [
 
381
        'annotate_iter',
 
382
        'get_file_mtime',
 
383
        'get_file_with_stat',
 
384
        'get_root_id',
 
385
        'get_symlink_target',
 
386
        'inv',
 
387
        'iter_search_rules',
 
388
        'list_files',
 
389
        'path_content_summary',
 
390
        'revision_tree',
 
391
        'test_trees',
 
392
        'tree',
 
393
        'walkdirs',
391
394
        ]
392
 
 
393
 
    adapter = TreeTestProviderAdapter(
394
 
        default_transport,
 
395
    submod_tests = loader.loadTestsFromModuleNames(
 
396
        ['bzrlib.tests.per_tree.test_' + name
 
397
         for name in per_tree_mod_names])
 
398
    scenarios = make_scenarios(
 
399
        tests.default_transport,
395
400
        # None here will cause a readonly decorator to be created
396
401
        # by the TestCaseWithTransport.get_readonly_transport method.
397
402
        None,
398
403
        WorkingTreeFormat._formats.values() + _legacy_formats)
399
 
 
400
404
    # add the tests for the sub modules
401
 
    adapt_modules(test_tree_implementations, adapter, loader, result)
402
 
    return result
 
405
    return tests.multiply_tests(submod_tests, scenarios, standard_tests)