/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 Canonical Ltd
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
2
# Authors: Robert Collins <robert.collins@canonical.com>
3
# -*- coding: utf-8 -*-
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
4
#
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
9
#
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
14
#
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
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.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
24
Specific tests for individual formats are in the tests/test_repository.py file
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
25
rather than in tests/interrepository_implementations/*.py.
26
"""
27
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
28
29
from bzrlib.errors import (
30
    FileExists,
31
    UninitializableFormat,
32
    )
33
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
34
from bzrlib.repository import (
2998.2.2 by John Arbash Meinel
implement a faster path for copying from packs back to knits.
35
                               InterKnitRepo,
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
36
                               InterRepository,
37
                               )
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
38
from bzrlib.tests import (
39
                          adapt_modules,
40
                          default_transport,
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
41
                          TestScenarioApplier,
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
42
                          )
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
43
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
44
from bzrlib.transport import get_transport
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
45
46
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
47
class InterRepositoryTestProviderAdapter(TestScenarioApplier):
48
    """A tool to generate a suite testing multiple inter repository formats.
49
50
    This is done by copying the test once for each interrepo provider and injecting
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
51
    the transport_server, transport_readonly_server, repository_format and
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
52
    repository_to_format classes into each copy.
53
    Each copy is also given a new id() to make it easy to identify.
54
    """
55
56
    def __init__(self, transport_server, transport_readonly_server, formats):
57
        TestScenarioApplier.__init__(self)
58
        self._transport_server = transport_server
59
        self._transport_readonly_server = transport_readonly_server
60
        self.scenarios = self.formats_to_scenarios(formats)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
61
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
62
    def formats_to_scenarios(self, formats):
63
        """Transform the input formats to a list of scenarios.
64
65
        :param formats: A list of tuples:
66
            (interrepo_class, repository_format, repository_format_to).
67
        """
68
        result = []
69
        for interrepo_class, repository_format, repository_format_to in formats:
3302.5.4 by Vincent Ladeuil
Make interreop parametrized tests IDs unique.
70
            id = '%s,%s,%s' % (interrepo_class.__name__,
71
                                repository_format.__class__.__name__,
72
                                repository_format_to.__class__.__name__)
73
            scenario = (id,
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
74
                {"transport_server":self._transport_server,
75
                 "transport_readonly_server":self._transport_readonly_server,
76
                 "repository_format":repository_format,
77
                 "interrepo_class":interrepo_class,
78
                 "repository_format_to":repository_format_to,
79
                 })
80
            result.append(scenario)
81
        return result
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
82
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
83
    @staticmethod
84
    def default_test_list():
85
        """Generate the default list of interrepo permutations to test."""
2998.2.2 by John Arbash Meinel
implement a faster path for copying from packs back to knits.
86
        from bzrlib.repofmt import knitrepo, pack_repo, weaverepo
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
87
        result = []
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
88
        # test the default InterRepository between format 6 and the current
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
89
        # default format.
90
        # XXX: robertc 20060220 reinstate this when there are two supported
91
        # formats which do not have an optimal code path between them.
92
        #result.append((InterRepository,
93
        #               RepositoryFormat6(),
94
        #               RepositoryFormatKnit1()))
95
        for optimiser_class in InterRepository._optimisers:
96
            format_to_test = optimiser_class._get_repo_format_to_test()
97
            if format_to_test is not None:
98
                result.append((optimiser_class,
99
                               format_to_test, format_to_test))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
100
        # if there are specific combinations we want to use, we can add them
4060.1.3 by Robert Collins
Implement the separate source component for fetch - repository.StreamSource.
101
        # here. We want to test rich root upgrading.
102
        result.append((InterRepository,
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
103
                       weaverepo.RepositoryFormat5(),
104
                       knitrepo.RepositoryFormatKnit3()))
4060.1.3 by Robert Collins
Implement the separate source component for fetch - repository.StreamSource.
105
        result.append((InterRepository,
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
106
                       knitrepo.RepositoryFormatKnit1(),
107
                       knitrepo.RepositoryFormatKnit3()))
4060.1.3 by Robert Collins
Implement the separate source component for fetch - repository.StreamSource.
108
        result.append((InterRepository,
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
109
                       knitrepo.RepositoryFormatKnit1(),
110
                       knitrepo.RepositoryFormatKnit3()))
2998.2.2 by John Arbash Meinel
implement a faster path for copying from packs back to knits.
111
        result.append((InterKnitRepo,
112
                       knitrepo.RepositoryFormatKnit1(),
113
                       pack_repo.RepositoryFormatKnitPack1()))
114
        result.append((InterKnitRepo,
115
                       pack_repo.RepositoryFormatKnitPack1(),
116
                       knitrepo.RepositoryFormatKnit1()))
117
        result.append((InterKnitRepo,
118
                       knitrepo.RepositoryFormatKnit3(),
119
                       pack_repo.RepositoryFormatKnitPack3()))
120
        result.append((InterKnitRepo,
121
                       pack_repo.RepositoryFormatKnitPack3(),
122
                       knitrepo.RepositoryFormatKnit3()))
3879.2.7 by John Arbash Meinel
Add an Inter test that actually uses InterDifferingSerializer
123
        result.append((InterKnitRepo,
124
                       pack_repo.RepositoryFormatKnitPack3(),
125
                       pack_repo.RepositoryFormatKnitPack4()))
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
126
        return result
127
128
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
129
class TestCaseWithInterRepository(TestCaseWithBzrDir):
130
131
    def setUp(self):
132
        super(TestCaseWithInterRepository, self).setUp()
133
134
    def make_branch(self, relpath, format=None):
135
        repo = self.make_repository(relpath, format=format)
136
        return repo.bzrdir.create_branch()
137
138
    def make_bzrdir(self, relpath, format=None):
139
        try:
140
            url = self.get_url(relpath)
141
            segments = url.split('/')
142
            if segments and segments[-1] not in ('', '.'):
143
                parent = '/'.join(segments[:-1])
144
                t = get_transport(parent)
145
                try:
146
                    t.mkdir(segments[-1])
147
                except FileExists:
148
                    pass
149
            if format is None:
150
                format = self.repository_format._matchingbzrdir
151
            return format.initialize(url)
152
        except UninitializableFormat:
153
            raise TestSkipped("Format %s is not initializable." % format)
154
155
    def make_repository(self, relpath, format=None):
156
        made_control = self.make_bzrdir(relpath, format=format)
157
        return self.repository_format.initialize(made_control)
158
159
    def make_to_repository(self, relpath):
160
        made_control = self.make_bzrdir(relpath,
161
            self.repository_format_to._matchingbzrdir)
162
        return self.repository_format_to.initialize(made_control)
163
164
3302.9.10 by Vincent Ladeuil
bzrlib.tests.interrepository_implementations switched from test_suite()
165
def load_tests(basic_tests, module, loader):
166
    result = loader.suiteClass()
167
    # add the tests for this module
168
    result.addTests(basic_tests)
169
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
170
    test_interrepository_implementations = [
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
171
        'bzrlib.tests.interrepository_implementations.test_fetch',
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
172
        'bzrlib.tests.interrepository_implementations.test_interrepository',
173
        ]
174
    adapter = InterRepositoryTestProviderAdapter(
175
        default_transport,
176
        # None here will cause a readonly decorator to be created
177
        # by the TestCaseWithTransport.get_readonly_transport method.
178
        None,
179
        InterRepositoryTestProviderAdapter.default_test_list()
180
        )
3302.9.27 by Vincent Ladeuil
Fixed as per Ian's review.
181
    # add the tests for the sub modules
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
182
    adapt_modules(test_interrepository_implementations, adapter, loader, result)
183
    return result