~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Alexander Belchenko
  • Date: 2006-07-30 16:43:12 UTC
  • mto: (1711.2.111 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1906.
  • Revision ID: bialix@ukr.net-20060730164312-b025fd3ff0cee59e
rename  gpl.txt => COPYING.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006 by Canonical Ltd
2
2
# Authors: Robert Collins <robert.collins@canonical.com>
3
3
# -*- coding: utf-8 -*-
4
4
#
14
14
#
15
15
# You should have received a copy of the GNU General Public License
16
16
# along with this program; if not, write to the Free Software
17
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
 
19
19
 
20
20
"""InterRepository implementation tests for bzr.
21
21
 
22
22
These test the conformance of all the interrepository variations to the
23
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/per_interrepository/*.py.
 
24
Specific tests for individual formats are in the tests/test_repository.py file 
 
25
rather than in tests/interrepository_implementations/*.py.
26
26
"""
27
27
 
28
 
 
29
 
from bzrlib import transport
30
 
from bzrlib.errors import (
31
 
    FileExists,
32
 
    UninitializableFormat,
33
 
    )
34
 
 
35
 
from bzrlib.repository import (
36
 
    InterRepository,
37
 
    )
 
28
from bzrlib.repository import (_legacy_formats,
 
29
                               InterRepositoryTestProviderAdapter,
 
30
                               )
 
31
                            
38
32
from bzrlib.tests import (
 
33
                          adapt_modules,
39
34
                          default_transport,
40
 
                          multiply_tests,
 
35
                          TestLoader,
 
36
                          TestSuite,
41
37
                          )
42
 
from bzrlib.tests.per_controldir.test_controldir import TestCaseWithControlDir
43
 
 
44
 
 
45
 
def make_scenarios(transport_server, transport_readonly_server, formats):
46
 
    """Transform the input formats to a list of scenarios.
47
 
 
48
 
    :param formats: A list of tuples:
49
 
        (label, repository_format, repository_format_to).
50
 
    """
51
 
    result = []
52
 
    for label, repository_format, repository_format_to in formats:
53
 
        id = '%s,%s,%s' % (label, repository_format.__class__.__name__,
54
 
                           repository_format_to.__class__.__name__)
55
 
        scenario = (id,
56
 
            {"transport_server": transport_server,
57
 
             "transport_readonly_server": transport_readonly_server,
58
 
             "repository_format": repository_format,
59
 
             "repository_format_to": repository_format_to,
60
 
             })
61
 
        result.append(scenario)
62
 
    return result
63
 
 
64
 
 
65
 
def default_test_list():
66
 
    """Generate the default list of interrepo permutations to test."""
67
 
    from bzrlib.repofmt import (
68
 
        groupcompress_repo,
69
 
        knitrepo,
70
 
        pack_repo,
71
 
        weaverepo,
72
 
        )
73
 
    result = []
74
 
    def add_combo(label, from_format, to_format):
75
 
        result.append((label, from_format, to_format))
76
 
    # test the default InterRepository between format 6 and the current
77
 
    # default format.
78
 
    # XXX: robertc 20060220 reinstate this when there are two supported
79
 
    # formats which do not have an optimal code path between them.
80
 
    #result.append((InterRepository,
81
 
    #               RepositoryFormat6(),
82
 
    #               RepositoryFormatKnit1()))
83
 
    for optimiser_class in InterRepository._optimisers:
84
 
        format_to_test = optimiser_class._get_repo_format_to_test()
85
 
        if format_to_test is not None:
86
 
            add_combo(optimiser_class.__name__, format_to_test, format_to_test)
87
 
    # if there are specific combinations we want to use, we can add them
88
 
    # here. We want to test rich root upgrading.
89
 
    # XXX: although we attach InterRepository class names to these scenarios,
90
 
    # there's nothing asserting that these labels correspond to what is
91
 
    # actually used.
92
 
    add_combo('InterRepository',
93
 
              weaverepo.RepositoryFormat5(),
94
 
              knitrepo.RepositoryFormatKnit3())
95
 
    add_combo('InterRepository',
96
 
              knitrepo.RepositoryFormatKnit1(),
97
 
              knitrepo.RepositoryFormatKnit3())
98
 
    add_combo('InterKnitRepo',
99
 
              knitrepo.RepositoryFormatKnit1(),
100
 
              pack_repo.RepositoryFormatKnitPack1())
101
 
    add_combo('InterKnitRepo',
102
 
              pack_repo.RepositoryFormatKnitPack1(),
103
 
              knitrepo.RepositoryFormatKnit1())
104
 
    add_combo('InterKnitRepo',
105
 
              knitrepo.RepositoryFormatKnit3(),
106
 
              pack_repo.RepositoryFormatKnitPack3())
107
 
    add_combo('InterKnitRepo',
108
 
              pack_repo.RepositoryFormatKnitPack3(),
109
 
              knitrepo.RepositoryFormatKnit3())
110
 
    add_combo('InterKnitRepo',
111
 
              pack_repo.RepositoryFormatKnitPack3(),
112
 
              pack_repo.RepositoryFormatKnitPack4())
113
 
    add_combo('InterDifferingSerializer',
114
 
              pack_repo.RepositoryFormatKnitPack1(),
115
 
              pack_repo.RepositoryFormatKnitPack6RichRoot())
116
 
    add_combo('InterDifferingSerializer',
117
 
              pack_repo.RepositoryFormatKnitPack6RichRoot(),
118
 
              groupcompress_repo.RepositoryFormat2a())
119
 
    add_combo('InterDifferingSerializer',
120
 
              groupcompress_repo.RepositoryFormat2a(),
121
 
              pack_repo.RepositoryFormatKnitPack6RichRoot())
122
 
    add_combo('InterRepository',
123
 
              groupcompress_repo.RepositoryFormatCHK2(),
124
 
              groupcompress_repo.RepositoryFormat2a())
125
 
    add_combo('InterDifferingSerializer',
126
 
              groupcompress_repo.RepositoryFormatCHK1(),
127
 
              groupcompress_repo.RepositoryFormat2a())
128
 
    return result
129
 
 
130
 
 
131
 
class TestCaseWithInterRepository(TestCaseWithControlDir):
132
 
 
133
 
    def setUp(self):
134
 
        super(TestCaseWithInterRepository, self).setUp()
135
 
 
136
 
    def make_branch(self, relpath, format=None):
137
 
        repo = self.make_repository(relpath, format=format)
138
 
        return repo.bzrdir.create_branch()
139
 
 
140
 
    def make_bzrdir(self, relpath, format=None):
141
 
        try:
142
 
            url = self.get_url(relpath)
143
 
            segments = url.split('/')
144
 
            if segments and segments[-1] not in ('', '.'):
145
 
                parent = '/'.join(segments[:-1])
146
 
                t = transport.get_transport(parent)
147
 
                try:
148
 
                    t.mkdir(segments[-1])
149
 
                except FileExists:
150
 
                    pass
151
 
            if format is None:
152
 
                format = self.repository_format._matchingbzrdir
153
 
            return format.initialize(url)
154
 
        except UninitializableFormat:
155
 
            raise TestSkipped("Format %s is not initializable." % format)
156
 
 
157
 
    def make_repository(self, relpath, format=None):
158
 
        made_control = self.make_bzrdir(relpath, format=format)
159
 
        return self.repository_format.initialize(made_control)
160
 
 
161
 
    def make_to_repository(self, relpath):
162
 
        made_control = self.make_bzrdir(relpath,
163
 
            self.repository_format_to._matchingbzrdir)
164
 
        return self.repository_format_to.initialize(made_control)
165
 
 
166
 
 
167
 
def load_tests(standard_tests, module, loader):
168
 
    submod_tests = loader.loadTestsFromModuleNames([
169
 
        'bzrlib.tests.per_interrepository.test_fetch',
170
 
        'bzrlib.tests.per_interrepository.test_interrepository',
171
 
        ])
172
 
    scenarios = make_scenarios(
 
38
 
 
39
 
 
40
def test_suite():
 
41
    result = TestSuite()
 
42
    test_interrepository_implementations = [
 
43
        'bzrlib.tests.interrepository_implementations.test_interrepository',
 
44
        ]
 
45
    adapter = InterRepositoryTestProviderAdapter(
173
46
        default_transport,
174
47
        # None here will cause a readonly decorator to be created
175
48
        # by the TestCaseWithTransport.get_readonly_transport method.
176
49
        None,
177
 
        default_test_list()
 
50
        InterRepositoryTestProviderAdapter.default_test_list()
178
51
        )
179
 
    return multiply_tests(submod_tests, scenarios, standard_tests)
 
52
    loader = TestLoader()
 
53
    adapt_modules(test_interrepository_implementations, adapter, loader, result)
 
54
    return result