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

  • Committer: Aaron Bentley
  • Date: 2008-10-16 21:27:10 UTC
  • mfrom: (0.15.26 unshelve)
  • mto: (0.16.74 shelf-ui)
  • mto: This revision was merged to the branch mainline in revision 3820.
  • Revision ID: aaron@aaronbentley.com-20081016212710-h9av3nhk76dvmsv5
Merge with unshelve

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
# -*- coding: utf-8 -*-
 
4
#
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free Software Foundation; either version 2 of the License, or
 
8
# (at your option) any later version.
 
9
#
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program; if not, write to the Free Software
 
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 
 
19
 
 
20
"""InterRepository implementation tests for bzr.
 
21
 
 
22
These test the conformance of all the interrepository variations to the
 
23
expected API including generally applicable corner cases.
 
24
Specific tests for individual formats are in the tests/test_repository.py file 
 
25
rather than in tests/interrepository_implementations/*.py.
 
26
"""
 
27
 
 
28
 
 
29
from bzrlib.errors import (
 
30
    FileExists,
 
31
    UninitializableFormat,
 
32
    )
 
33
 
 
34
from bzrlib.repository import (
 
35
                               InterKnitRepo,
 
36
                               InterKnit1and2,
 
37
                               InterModel1and2,
 
38
                               InterRepository,
 
39
                               )
 
40
from bzrlib.tests import (
 
41
                          adapt_modules,
 
42
                          default_transport,
 
43
                          TestScenarioApplier,
 
44
                          )
 
45
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
 
46
from bzrlib.transport import get_transport
 
47
 
 
48
 
 
49
class InterRepositoryTestProviderAdapter(TestScenarioApplier):
 
50
    """A tool to generate a suite testing multiple inter repository formats.
 
51
 
 
52
    This is done by copying the test once for each interrepo provider and injecting
 
53
    the transport_server, transport_readonly_server, repository_format and 
 
54
    repository_to_format classes into each copy.
 
55
    Each copy is also given a new id() to make it easy to identify.
 
56
    """
 
57
 
 
58
    def __init__(self, transport_server, transport_readonly_server, formats):
 
59
        TestScenarioApplier.__init__(self)
 
60
        self._transport_server = transport_server
 
61
        self._transport_readonly_server = transport_readonly_server
 
62
        self.scenarios = self.formats_to_scenarios(formats)
 
63
    
 
64
    def formats_to_scenarios(self, formats):
 
65
        """Transform the input formats to a list of scenarios.
 
66
 
 
67
        :param formats: A list of tuples:
 
68
            (interrepo_class, repository_format, repository_format_to).
 
69
        """
 
70
        result = []
 
71
        for interrepo_class, repository_format, repository_format_to in formats:
 
72
            id = '%s,%s,%s' % (interrepo_class.__name__,
 
73
                                repository_format.__class__.__name__,
 
74
                                repository_format_to.__class__.__name__)
 
75
            scenario = (id,
 
76
                {"transport_server":self._transport_server,
 
77
                 "transport_readonly_server":self._transport_readonly_server,
 
78
                 "repository_format":repository_format,
 
79
                 "interrepo_class":interrepo_class,
 
80
                 "repository_format_to":repository_format_to,
 
81
                 })
 
82
            result.append(scenario)
 
83
        return result
 
84
    
 
85
    @staticmethod
 
86
    def default_test_list():
 
87
        """Generate the default list of interrepo permutations to test."""
 
88
        from bzrlib.repofmt import knitrepo, pack_repo, weaverepo
 
89
        result = []
 
90
        # test the default InterRepository between format 6 and the current 
 
91
        # default format.
 
92
        # XXX: robertc 20060220 reinstate this when there are two supported
 
93
        # formats which do not have an optimal code path between them.
 
94
        #result.append((InterRepository,
 
95
        #               RepositoryFormat6(),
 
96
        #               RepositoryFormatKnit1()))
 
97
        for optimiser_class in InterRepository._optimisers:
 
98
            format_to_test = optimiser_class._get_repo_format_to_test()
 
99
            if format_to_test is not None:
 
100
                result.append((optimiser_class,
 
101
                               format_to_test, format_to_test))
 
102
        # if there are specific combinations we want to use, we can add them 
 
103
        # here.
 
104
        result.append((InterModel1and2,
 
105
                       weaverepo.RepositoryFormat5(),
 
106
                       knitrepo.RepositoryFormatKnit3()))
 
107
        result.append((InterModel1and2,
 
108
                       knitrepo.RepositoryFormatKnit1(),
 
109
                       knitrepo.RepositoryFormatKnit3()))
 
110
        result.append((InterKnit1and2,
 
111
                       knitrepo.RepositoryFormatKnit1(),
 
112
                       knitrepo.RepositoryFormatKnit3()))
 
113
        result.append((InterKnitRepo,
 
114
                       knitrepo.RepositoryFormatKnit1(),
 
115
                       pack_repo.RepositoryFormatKnitPack1()))
 
116
        result.append((InterKnitRepo,
 
117
                       pack_repo.RepositoryFormatKnitPack1(),
 
118
                       knitrepo.RepositoryFormatKnit1()))
 
119
        result.append((InterKnitRepo,
 
120
                       knitrepo.RepositoryFormatKnit3(),
 
121
                       pack_repo.RepositoryFormatKnitPack3()))
 
122
        result.append((InterKnitRepo,
 
123
                       pack_repo.RepositoryFormatKnitPack3(),
 
124
                       knitrepo.RepositoryFormatKnit3()))
 
125
        return result
 
126
 
 
127
 
 
128
class TestCaseWithInterRepository(TestCaseWithBzrDir):
 
129
 
 
130
    def setUp(self):
 
131
        super(TestCaseWithInterRepository, self).setUp()
 
132
 
 
133
    def make_branch(self, relpath, format=None):
 
134
        repo = self.make_repository(relpath, format=format)
 
135
        return repo.bzrdir.create_branch()
 
136
 
 
137
    def make_bzrdir(self, relpath, format=None):
 
138
        try:
 
139
            url = self.get_url(relpath)
 
140
            segments = url.split('/')
 
141
            if segments and segments[-1] not in ('', '.'):
 
142
                parent = '/'.join(segments[:-1])
 
143
                t = get_transport(parent)
 
144
                try:
 
145
                    t.mkdir(segments[-1])
 
146
                except FileExists:
 
147
                    pass
 
148
            if format is None:
 
149
                format = self.repository_format._matchingbzrdir
 
150
            return format.initialize(url)
 
151
        except UninitializableFormat:
 
152
            raise TestSkipped("Format %s is not initializable." % format)
 
153
 
 
154
    def make_repository(self, relpath, format=None):
 
155
        made_control = self.make_bzrdir(relpath, format=format)
 
156
        return self.repository_format.initialize(made_control)
 
157
 
 
158
    def make_to_repository(self, relpath):
 
159
        made_control = self.make_bzrdir(relpath,
 
160
            self.repository_format_to._matchingbzrdir)
 
161
        return self.repository_format_to.initialize(made_control)
 
162
 
 
163
 
 
164
def load_tests(basic_tests, module, loader):
 
165
    result = loader.suiteClass()
 
166
    # add the tests for this module
 
167
    result.addTests(basic_tests)
 
168
 
 
169
    test_interrepository_implementations = [
 
170
        'bzrlib.tests.interrepository_implementations.test_fetch',
 
171
        'bzrlib.tests.interrepository_implementations.test_interrepository',
 
172
        ]
 
173
    adapter = InterRepositoryTestProviderAdapter(
 
174
        default_transport,
 
175
        # None here will cause a readonly decorator to be created
 
176
        # by the TestCaseWithTransport.get_readonly_transport method.
 
177
        None,
 
178
        InterRepositoryTestProviderAdapter.default_test_list()
 
179
        )
 
180
    # add the tests for the sub modules
 
181
    adapt_modules(test_interrepository_implementations, adapter, loader, result)
 
182
    return result