~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2009-07-27 05:35:00 UTC
  • mfrom: (4570 +trunk)
  • mto: (4634.6.29 2.0)
  • mto: This revision was merged to the branch mainline in revision 4680.
  • Revision ID: andrew.bennetts@canonical.com-20090727053500-q76zsn2dx33jhmj5
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
96
90
    return preview_tree
97
91
 
98
92
 
99
 
class TestTreeImplementationSupport(TestCaseWithTransport):
 
93
class TestTreeImplementationSupport(tests.TestCaseWithTransport):
100
94
 
101
95
    def test_revision_tree_from_workingtree(self):
102
96
        tree = self.make_branch_and_tree('.')
238
232
        note that the order of the paths and fileids is deliberately
239
233
        mismatched to ensure that the result order is path based.
240
234
        """
 
235
        self.requireFeature(tests.UnicodeFilenameFeature)
241
236
        tree = self.make_branch_and_tree('.')
242
237
        paths = ['0file',
243
238
            '1top-dir/',
252
247
            '1file-in-1topdir',
253
248
            '0dir-in-1topdir'
254
249
            ]
255
 
        try:
256
 
            self.build_tree(paths)
257
 
        except UnicodeError:
258
 
            raise TestSkipped(
259
 
                'This platform does not support unicode file paths.')
 
250
        self.build_tree(paths)
260
251
        tree.add(paths, ids)
261
252
        tt = transform.TreeTransform(tree)
262
253
        if symlinks:
273
264
 
274
265
    def _create_tree_with_utf8(self, tree):
275
266
        """Generate a tree with a utf8 revision and unicode paths."""
 
267
        self.requireFeature(tests.UnicodeFilenameFeature)
276
268
        # We avoid combining characters in file names here, normalization
277
269
        # checks (as performed by some file systems (OSX) are outside the scope
278
270
        # of these tests).  We use the euro sign \N{Euro Sign} or \u20ac in
289
281
                    'ba\xe2\x82\xacr-id',
290
282
                    'ba\xe2\x82\xacz-id',
291
283
                   ]
292
 
        try:
293
 
            self.build_tree(paths[1:])
294
 
        except UnicodeError:
295
 
            raise tests.TestSkipped('filesystem does not support unicode.')
 
284
        self.build_tree(paths[1:])
296
285
        if tree.get_root_id() is None:
297
286
            # Some trees do not have a root yet.
298
287
            tree.add(paths, file_ids)
319
308
        return self.workingtree_to_test_tree(tree)
320
309
 
321
310
 
322
 
class TreeTestProviderAdapter(WorkingTreeTestProviderAdapter):
 
311
def make_scenarios(transport_server, transport_readonly_server, formats):
323
312
    """Generate test suites for each Tree implementation in bzrlib.
324
313
 
325
314
    Currently this covers all working tree formats, and RevisionTree and
326
315
    DirStateRevisionTree by committing a working tree to create the revision
327
316
    tree.
328
317
    """
329
 
 
330
 
    def __init__(self, transport_server, transport_readonly_server, formats):
331
 
        """Create a TreeTestProviderAdapter.
332
 
 
333
 
        :param formats: [workingtree_format]
334
 
        """
335
 
        super(TreeTestProviderAdapter, self).__init__(transport_server,
336
 
            transport_readonly_server, formats)
337
 
        # now adjust the scenarios and add the non-working-tree tree scenarios.
338
 
        for scenario in self.scenarios:
339
 
            # for working tree adapted tests, preserve the tree
340
 
            scenario[1]["_workingtree_to_test_tree"] = return_parameter
341
 
        # add RevisionTree scenario
342
 
        self.scenarios.append(self.create_tree_scenario(RevisionTree.__name__,
343
 
                              revision_tree_from_workingtree,))
344
 
 
345
 
        # also test WorkingTree4's RevisionTree implementation which is
346
 
        # specialised.
347
 
        self.scenarios.append(self.create_tree_scenario(
348
 
            DirStateRevisionTree.__name__, _dirstate_tree_from_workingtree,
349
 
            WorkingTreeFormat4()))
350
 
        self.scenarios.append(self.create_tree_scenario(
351
 
            DirStateRevisionTree.__name__, _dirstate_tree_from_workingtree,
352
 
            WorkingTreeFormat5()))
353
 
        self.scenarios.append(self.create_tree_scenario('PreviewTree',
354
 
            preview_tree_pre))
355
 
        self.scenarios.append(self.create_tree_scenario('PreviewTreePost',
356
 
            preview_tree_post))
357
 
 
358
 
    def create_tree_scenario(self, name, converter, workingtree_format=None):
359
 
        """Create a scenario for the specified converter
360
 
 
361
 
        :param name: The name to append to tests using this converter
362
 
        :param converter: A function that converts a workingtree into the
363
 
            desired format.
364
 
        :param workingtree_format: The particular workingtree format to
365
 
            convert from.
366
 
        :return: a (name, options) tuple, where options is a dict of values
367
 
            to be used as members of the TestCase.
368
 
        """
369
 
        if workingtree_format is None:
370
 
            workingtree_format = WorkingTreeFormat._default_format
371
 
        scenario_options = WorkingTreeTestProviderAdapter.create_scenario(self,
372
 
            workingtree_format)[1]
373
 
        scenario_options["_workingtree_to_test_tree"] = converter
374
 
        return name, scenario_options
375
 
 
376
 
 
377
 
def load_tests(basic_tests, module, loader):
378
 
    result = loader.suiteClass()
379
 
    # add the tests for this module
380
 
    result.addTests(basic_tests)
381
 
 
382
 
    test_tree_implementations = [
383
 
        'bzrlib.tests.tree_implementations.test_annotate_iter',
384
 
        'bzrlib.tests.tree_implementations.test_get_file_mtime',
385
 
        'bzrlib.tests.tree_implementations.test_get_root_id',
386
 
        'bzrlib.tests.tree_implementations.test_get_symlink_target',
387
 
        'bzrlib.tests.tree_implementations.test_inv',
388
 
        'bzrlib.tests.tree_implementations.test_iter_search_rules',
389
 
        'bzrlib.tests.tree_implementations.test_list_files',
390
 
        'bzrlib.tests.tree_implementations.test_path_content_summary',
391
 
        'bzrlib.tests.tree_implementations.test_revision_tree',
392
 
        'bzrlib.tests.tree_implementations.test_test_trees',
393
 
        'bzrlib.tests.tree_implementations.test_tree',
394
 
        'bzrlib.tests.tree_implementations.test_walkdirs',
 
318
    scenarios = wt_make_scenarios(transport_server, transport_readonly_server,
 
319
        formats)
 
320
    # now adjust the scenarios and add the non-working-tree tree scenarios.
 
321
    for scenario in scenarios:
 
322
        # for working tree format tests, preserve the tree
 
323
        scenario[1]["_workingtree_to_test_tree"] = return_parameter
 
324
    # add RevisionTree scenario
 
325
    workingtree_format = WorkingTreeFormat._default_format
 
326
    scenarios.append((RevisionTree.__name__,
 
327
        create_tree_scenario(transport_server, transport_readonly_server,
 
328
        workingtree_format, revision_tree_from_workingtree,)))
 
329
 
 
330
    # also test WorkingTree4/5's RevisionTree implementation which is
 
331
    # specialised.
 
332
    # XXX: Ask igc if WT5 revision tree actually is different.
 
333
    scenarios.append((DirStateRevisionTree.__name__ + ",WT4",
 
334
        create_tree_scenario(transport_server, transport_readonly_server,
 
335
        WorkingTreeFormat4(), _dirstate_tree_from_workingtree)))
 
336
    scenarios.append((DirStateRevisionTree.__name__ + ",WT5",
 
337
        create_tree_scenario(transport_server, transport_readonly_server,
 
338
        WorkingTreeFormat5(), _dirstate_tree_from_workingtree)))
 
339
    scenarios.append(("PreviewTree", create_tree_scenario(transport_server,
 
340
        transport_readonly_server, workingtree_format, preview_tree_pre)))
 
341
    scenarios.append(("PreviewTreePost", create_tree_scenario(transport_server,
 
342
        transport_readonly_server, workingtree_format, preview_tree_post)))
 
343
    return scenarios
 
344
 
 
345
 
 
346
def create_tree_scenario(transport_server, transport_readonly_server,
 
347
    workingtree_format, converter):
 
348
    """Create a scenario for the specified converter
 
349
 
 
350
    :param converter: A function that converts a workingtree into the
 
351
        desired format.
 
352
    :param workingtree_format: The particular workingtree format to
 
353
        convert from.
 
354
    :return: a (name, options) tuple, where options is a dict of values
 
355
        to be used as members of the TestCase.
 
356
    """
 
357
    scenario_options = wt_make_scenario(transport_server,
 
358
                                        transport_readonly_server,
 
359
                                        workingtree_format)
 
360
    scenario_options["_workingtree_to_test_tree"] = converter
 
361
    return scenario_options
 
362
 
 
363
 
 
364
def load_tests(standard_tests, module, loader):
 
365
    per_tree_mod_names = [
 
366
        'annotate_iter',
 
367
        'get_file_mtime',
 
368
        'get_file_with_stat',
 
369
        'get_root_id',
 
370
        'get_symlink_target',
 
371
        'inv',
 
372
        'iter_search_rules',
 
373
        'list_files',
 
374
        'path_content_summary',
 
375
        'revision_tree',
 
376
        'test_trees',
 
377
        'tree',
 
378
        'walkdirs',
395
379
        ]
396
 
 
397
 
    adapter = TreeTestProviderAdapter(
398
 
        default_transport,
 
380
    submod_tests = loader.loadTestsFromModuleNames(
 
381
        ['bzrlib.tests.per_tree.test_' + name
 
382
         for name in per_tree_mod_names])
 
383
    scenarios = make_scenarios(
 
384
        tests.default_transport,
399
385
        # None here will cause a readonly decorator to be created
400
386
        # by the TestCaseWithTransport.get_readonly_transport method.
401
387
        None,
402
388
        WorkingTreeFormat._formats.values() + _legacy_formats)
403
 
 
404
389
    # add the tests for the sub modules
405
 
    adapt_modules(test_tree_implementations, adapter, loader, result)
406
 
    return result
 
390
    return tests.multiply_tests(submod_tests, scenarios, standard_tests)