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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-03-09 08:45:56 UTC
  • mfrom: (4084.5.2 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090309084556-9i2m12qlud2qcrtw
(robertc) Bulk update all test adaptation into a single approach
        using multiply_tests rather than many varied test adapters.
        (Robert Collins

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    FileExists,
34
34
    UninitializableFormat,
35
35
    )
36
 
from bzrlib.tests import (
37
 
                          adapt_modules,
38
 
                          TestScenarioApplier,
39
 
                          )
 
36
from bzrlib.tests import multiply_tests
40
37
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
41
38
from bzrlib.transport import get_transport
42
39
 
43
40
 
44
 
class InterBranchTestProviderAdapter(TestScenarioApplier):
45
 
    """A tool to generate a suite testing multiple inter branch formats.
 
41
def make_scenarios(test_list):
 
42
    """Transform the input test list to a list of scenarios.
46
43
 
47
 
    This is done by copying the test once for each interbranch provider and
48
 
    injecting the branch_format_from and branch_to_format classes into each
49
 
    copy.  Each copy is also given a new id() to make it easy to identify.
 
44
    :param formats: A list of tuples:
 
45
        (interbranch_class, branch_format_from, branch_format_to).
50
46
    """
51
 
 
52
 
    def __init__(self, formats):
53
 
        TestScenarioApplier.__init__(self)
54
 
        self.scenarios = self.formats_to_scenarios(formats)
55
 
 
56
 
    def formats_to_scenarios(self, formats):
57
 
        """Transform the input formats to a list of scenarios.
58
 
 
59
 
        :param formats: A list of tuples:
60
 
            (interbranch_class, branch_format_from, branch_format_to).
61
 
        """
62
 
        result = []
63
 
        for interbranch_class, branch_format_from, branch_format_to in formats:
64
 
            id = '%s,%s,%s' % (interbranch_class.__name__,
65
 
                                branch_format_from.__class__.__name__,
66
 
                                branch_format_to.__class__.__name__)
67
 
            scenario = (id,
68
 
                {
69
 
                 "branch_format_from":branch_format_from,
70
 
                 "interbranch_class":interbranch_class,
71
 
                 "branch_format_to":branch_format_to,
72
 
                 })
73
 
            result.append(scenario)
74
 
        return result
75
 
 
76
 
    @staticmethod
77
 
    def default_test_list():
78
 
        """Generate the default list of interbranch permutations to test."""
79
 
        result = []
80
 
        # test the default InterBranch between format 6 and the current
81
 
        # default format.
82
 
        for optimiser_class in InterBranch._optimisers:
83
 
            format_from_test, format_to_test = \
84
 
                optimiser_class._get_branch_formats_to_test()
85
 
            if format_to_test is not None:
86
 
                result.append((optimiser_class,
87
 
                               format_from_test, format_to_test))
88
 
        # if there are specific combinations we want to use, we can add them
89
 
        # here.
90
 
        return result
 
47
    result = []
 
48
    for interbranch_class, branch_format_from, branch_format_to in test_list:
 
49
        id = '%s,%s,%s' % (interbranch_class.__name__,
 
50
                            branch_format_from.__class__.__name__,
 
51
                            branch_format_to.__class__.__name__)
 
52
        scenario = (id,
 
53
            {
 
54
             "branch_format_from": branch_format_from,
 
55
             "interbranch_class": interbranch_class,
 
56
             "branch_format_to": branch_format_to,
 
57
             })
 
58
        result.append(scenario)
 
59
    return result
 
60
 
 
61
 
 
62
def default_test_list():
 
63
    """Generate the default list of interbranch permutations to test."""
 
64
    result = []
 
65
    # test the default InterBranch between format 6 and the current
 
66
    # default format.
 
67
    for optimiser_class in InterBranch._optimisers:
 
68
        format_from_test, format_to_test = \
 
69
            optimiser_class._get_branch_formats_to_test()
 
70
        if format_to_test is not None:
 
71
            result.append((optimiser_class,
 
72
                           format_from_test, format_to_test))
 
73
    # if there are specific combinations we want to use, we can add them
 
74
    # here.
 
75
    return result
91
76
 
92
77
 
93
78
class TestCaseWithInterBranch(TestCaseWithBzrDir):
129
114
        return self.branch_format_to.initialize(made_control)
130
115
 
131
116
 
132
 
def load_tests(basic_tests, module, loader):
133
 
    result = loader.suiteClass()
134
 
    # add the tests for this module
135
 
    result.addTests(basic_tests)
136
 
 
137
 
    test_interbranch_implementations = [
 
117
def load_tests(standard_tests, module, loader):
 
118
    submod_tests = loader.loadTestsFromModuleNames([
138
119
        'bzrlib.tests.per_interbranch.test_update_revisions',
139
 
        ]
140
 
    adapter = InterBranchTestProviderAdapter(
141
 
        InterBranchTestProviderAdapter.default_test_list()
142
 
        )
143
 
    # add the tests for the sub modules
144
 
    adapt_modules(test_interbranch_implementations, adapter, loader, result)
145
 
    return result
 
120
        ])
 
121
    scenarios = make_scenarios(default_test_list())
 
122
    return multiply_tests(submod_tests, scenarios, standard_tests)