~ubuntu-branches/ubuntu/karmic/bzr/karmic-proposed

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2008-08-25 19:06:49 UTC
  • mfrom: (1.1.44 upstream)
  • Revision ID: james.westby@ubuntu.com-20080825190649-pq87jonr4uvs7s0y
Tags: 1.6-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
2
 
# Authors: Robert Collins <robert.collins@canonical.com>
3
 
#
4
 
# This program is free software; you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation; either version 2 of the License, or
7
 
# (at your option) any later version.
8
 
#
9
 
# This program is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU General Public License
15
 
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 
 
18
 
 
19
 
"""InterVersioned implementation tests for bzr.
20
 
 
21
 
These test the conformance of all the interversionedfile variations to the
22
 
expected API including generally applicable corner cases.
23
 
Specific tests for individual cases are in the tests/test_versionedfile.py file 
24
 
rather than in tests/interversionedfile_implementations/*.py.
25
 
"""
26
 
 
27
 
from bzrlib.tests import (
28
 
                          adapt_modules,
29
 
                          default_transport,
30
 
                          TestScenarioApplier,
31
 
                          )
32
 
 
33
 
 
34
 
class InterVersionedFileTestProviderAdapter(TestScenarioApplier):
35
 
    """A tool to generate a suite testing multiple inter versioned-file classes.
36
 
 
37
 
    This is done by copying the test once for each InterVersionedFile provider
38
 
    and injecting the transport_server, transport_readonly_server,
39
 
    versionedfile_factory and versionedfile_factory_to classes into each copy.
40
 
    Each copy is also given a new id() to make it easy to identify.
41
 
    """
42
 
 
43
 
    def __init__(self, transport_server, transport_readonly_server, formats):
44
 
        self._transport_server = transport_server
45
 
        self._transport_readonly_server = transport_readonly_server
46
 
        self.scenarios = self.formats_to_scenarios(formats)
47
 
    
48
 
    def formats_to_scenarios(self, formats):
49
 
        """Transform the input formats to a list of scenarios.
50
 
 
51
 
        :param formats: A list of tuples:
52
 
            (interversionedfile_class, versionedfile_factory,
53
 
             versionedfile_factory_to).
54
 
        """
55
 
        result = []
56
 
        for (interversionedfile_class,
57
 
             versionedfile_factory,
58
 
             versionedfile_factory_to) in formats:
59
 
            scenario = (interversionedfile_class.__name__, {
60
 
                "transport_server":self._transport_server,
61
 
                "transport_readonly_server":self._transport_readonly_server,
62
 
                "interversionedfile_class":interversionedfile_class,
63
 
                "versionedfile_factory":versionedfile_factory,
64
 
                "versionedfile_factory_to":versionedfile_factory_to,
65
 
                })
66
 
            result.append(scenario)
67
 
        return result
68
 
 
69
 
    @staticmethod
70
 
    def default_test_list():
71
 
        """Generate the default list of interversionedfile permutations to test."""
72
 
        from bzrlib.versionedfile import InterVersionedFile
73
 
        from bzrlib.weave import WeaveFile
74
 
        from bzrlib.knit import make_file_knit
75
 
        result = []
76
 
        # test the fallback InterVersionedFile from annotated knits to weave
77
 
        result.append((InterVersionedFile,
78
 
                       make_file_knit,
79
 
                       WeaveFile))
80
 
        for optimiser in InterVersionedFile._optimisers:
81
 
            result.append((optimiser,
82
 
                           optimiser._matching_file_from_factory,
83
 
                           optimiser._matching_file_to_factory
84
 
                           ))
85
 
        # if there are specific combinations we want to use, we can add them 
86
 
        # here.
87
 
        return result
88
 
 
89
 
 
90
 
def load_tests(basic_tests, module, loader):
91
 
    result = loader.suiteClass()
92
 
    # add the tests for this module
93
 
    result.addTests(basic_tests)
94
 
 
95
 
    test_interversionedfile_implementations = [
96
 
        'bzrlib.tests.interversionedfile_implementations.test_join',
97
 
        ]
98
 
    adapter = InterVersionedFileTestProviderAdapter(
99
 
        default_transport,
100
 
        # None here will cause a readonly decorator to be created
101
 
        # by the TestCaseWithTransport.get_readonly_transport method.
102
 
        None,
103
 
        InterVersionedFileTestProviderAdapter.default_test_list()
104
 
        )
105
 
    # add the tests for the sub modules
106
 
    adapt_modules(test_interversionedfile_implementations,
107
 
                  adapter, loader, result)
108
 
    return result