~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    tests,
30
30
    )
31
31
from bzrlib.branch import (BranchFormat,
32
 
                           BranchTestProviderAdapter,
33
32
                           _legacy_formats,
34
33
                           )
35
34
from bzrlib.remote import RemoteBranchFormat, RemoteBzrDirFormat
41
40
from bzrlib.transport.memory import MemoryServer
42
41
 
43
42
 
 
43
class BranchTestProviderAdapter(tests.TestScenarioApplier):
 
44
    """A tool to generate a suite testing multiple branch formats at once.
 
45
 
 
46
    This is done by copying the test once for each transport and injecting
 
47
    the transport_server, transport_readonly_server, and branch_format
 
48
    classes into each copy. Each copy is also given a new id() to make it
 
49
    easy to identify.
 
50
    """
 
51
 
 
52
    def __init__(self, transport_server, transport_readonly_server, formats,
 
53
        vfs_transport_factory=None):
 
54
        self._transport_server = transport_server
 
55
        self._transport_readonly_server = transport_readonly_server
 
56
        self.scenarios = self.formats_to_scenarios(formats)
 
57
    
 
58
    def formats_to_scenarios(self, formats):
 
59
        """Transform the input formats to a list of scenarios.
 
60
 
 
61
        :param formats: A list of (branch_format, bzrdir_format).
 
62
        """
 
63
        result = []
 
64
        for branch_format, bzrdir_format in formats:
 
65
            # some branches don't have separate format objects.
 
66
            # so we have a conditional here to handle them.
 
67
            scenario_name = getattr(branch_format, '__name__',
 
68
                branch_format.__class__.__name__)
 
69
            scenario = (scenario_name, {
 
70
                "transport_server":self._transport_server,
 
71
                "transport_readonly_server":self._transport_readonly_server,
 
72
                "bzrdir_format":bzrdir_format,
 
73
                "branch_format":branch_format,
 
74
                    })
 
75
            result.append(scenario)
 
76
        return result
 
77
 
 
78
 
44
79
class TestCaseWithBranch(TestCaseWithBzrDir):
45
80
    """This helper will be adapted for each branch_implementation test."""
46
81