~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-07-02 07:06:39 UTC
  • mfrom: (2553.2.14 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20070702070639-um9oyfoc2i6g8umv
(robertc) Reduce duplication in interface based testing by extracting a new class TestScenarioApplier.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
from bzrlib.lazy_import import lazy_import
21
21
lazy_import(globals(), """
22
 
from copy import deepcopy
23
 
from unittest import TestSuite
24
22
from warnings import warn
25
23
 
26
24
import bzrlib
2099
2097
        return BasicTags(self)
2100
2098
 
2101
2099
 
2102
 
class BranchTestProviderAdapter(object):
2103
 
    """A tool to generate a suite testing multiple branch formats at once.
2104
 
 
2105
 
    This is done by copying the test once for each transport and injecting
2106
 
    the transport_server, transport_readonly_server, and branch_format
2107
 
    classes into each copy. Each copy is also given a new id() to make it
2108
 
    easy to identify.
2109
 
    """
2110
 
 
2111
 
    def __init__(self, transport_server, transport_readonly_server, formats,
2112
 
        vfs_transport_factory=None):
2113
 
        self._transport_server = transport_server
2114
 
        self._transport_readonly_server = transport_readonly_server
2115
 
        self._formats = formats
2116
 
    
2117
 
    def adapt(self, test):
2118
 
        result = TestSuite()
2119
 
        for branch_format, bzrdir_format in self._formats:
2120
 
            new_test = deepcopy(test)
2121
 
            new_test.transport_server = self._transport_server
2122
 
            new_test.transport_readonly_server = self._transport_readonly_server
2123
 
            new_test.bzrdir_format = bzrdir_format
2124
 
            new_test.branch_format = branch_format
2125
 
            def make_new_test_id():
2126
 
                # the format can be either a class or an instance
2127
 
                name = getattr(branch_format, '__name__',
2128
 
                        branch_format.__class__.__name__)
2129
 
                new_id = "%s(%s)" % (new_test.id(), name)
2130
 
                return lambda: new_id
2131
 
            new_test.id = make_new_test_id()
2132
 
            result.addTest(new_test)
2133
 
        return result
2134
 
 
2135
 
 
2136
2100
######################################################################
2137
2101
# results of operations
2138
2102