/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
1
# Copyright (C) 2006-2010 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
4183.7.1 by Sabin Iacob
update FSF mailing address
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
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
4523.1.3 by Martin Pool
Rename to per_interrepository
25
rather than in tests/per_interrepository/*.py.
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
26
"""
27
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
28
5676.1.9 by Jelmer Vernooij
Fix existing implementation.
29
from bzrlib import (
30
    pyutils,
31
    transport,
32
    )
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
33
from bzrlib.errors import (
34
    FileExists,
35
    UninitializableFormat,
36
    )
37
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
38
from bzrlib.repository import (
5676.1.6 by Jelmer Vernooij
Add _ObjGetter.get_module.
39
    format_registry,
5676.1.1 by Jelmer Vernooij
Add RepositoryFormat._get_extra_interrepo_test_combinations.
40
    InterDifferingSerializer,
4257.3.8 by Andrew Bennetts
Fix TestCase.make_branch_builder to make a branch in the specified format. Also add an interrepo test scenario for KnitPack1 -> KnitPack6RichRoot, which fails.
41
    InterRepository,
42
    )
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
43
from bzrlib.tests import (
5651.3.1 by Jelmer Vernooij
Add RepositoryFormatRegistry.
44
    TestSkipped,
45
    default_transport,
46
    multiply_tests,
47
    )
5363.2.18 by Jelmer Vernooij
Rename TestCaseWithBzrDir -> TestCaseWithControlDir.
48
from bzrlib.tests.per_controldir.test_controldir import TestCaseWithControlDir
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
49
50
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
51
def make_scenarios(transport_server, transport_readonly_server, formats):
52
    """Transform the input formats to a list of scenarios.
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
53
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
54
    :param formats: A list of tuples:
4476.3.75 by Andrew Bennetts
Restore InterRepo class names in per_interrepo test ids, but make it clear they are just labels and not actually part of the scenario.
55
        (label, repository_format, repository_format_to).
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
56
    """
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
57
    result = []
5050.32.1 by Andrew Bennetts
Fix fetching more than 100 revisions from non-rich-root to rich-root repositories.
58
    for label, repository_format, repository_format_to, extra_setup in formats:
4476.3.75 by Andrew Bennetts
Restore InterRepo class names in per_interrepo test ids, but make it clear they are just labels and not actually part of the scenario.
59
        id = '%s,%s,%s' % (label, repository_format.__class__.__name__,
60
                           repository_format_to.__class__.__name__)
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
61
        scenario = (id,
62
            {"transport_server": transport_server,
63
             "transport_readonly_server": transport_readonly_server,
64
             "repository_format": repository_format,
65
             "repository_format_to": repository_format_to,
5050.32.1 by Andrew Bennetts
Fix fetching more than 100 revisions from non-rich-root to rich-root repositories.
66
             "extra_setup": extra_setup,
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
67
             })
68
        result.append(scenario)
69
    return result
70
71
72
def default_test_list():
73
    """Generate the default list of interrepo permutations to test."""
4476.3.4 by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out.
74
    from bzrlib.repofmt import (
4597.1.3 by John Arbash Meinel
Add a conversion to 2a format to make sure things get tested, see that it is now failing the inventories test.
75
        groupcompress_repo,
76
        knitrepo,
77
        pack_repo,
4476.3.4 by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out.
78
        )
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
79
    result = []
5676.1.1 by Jelmer Vernooij
Add RepositoryFormat._get_extra_interrepo_test_combinations.
80
    def add_combo(interrepo_cls, from_format, to_format, extra_setup=None,
81
                  label=None):
82
        if label is None:
83
            label = interrepo_cls.__name__
5050.32.1 by Andrew Bennetts
Fix fetching more than 100 revisions from non-rich-root to rich-root repositories.
84
        result.append((label, from_format, to_format, extra_setup))
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
85
    # test the default InterRepository between format 6 and the current
86
    # default format.
87
    # XXX: robertc 20060220 reinstate this when there are two supported
88
    # formats which do not have an optimal code path between them.
89
    #result.append((InterRepository,
90
    #               RepositoryFormat6(),
91
    #               RepositoryFormatKnit1()))
92
    for optimiser_class in InterRepository._optimisers:
93
        format_to_test = optimiser_class._get_repo_format_to_test()
94
        if format_to_test is not None:
5676.1.1 by Jelmer Vernooij
Add RepositoryFormat._get_extra_interrepo_test_combinations.
95
            add_combo(optimiser_class, format_to_test, format_to_test)
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
96
    # if there are specific combinations we want to use, we can add them
97
    # here. We want to test rich root upgrading.
4476.3.75 by Andrew Bennetts
Restore InterRepo class names in per_interrepo test ids, but make it clear they are just labels and not actually part of the scenario.
98
    # XXX: although we attach InterRepository class names to these scenarios,
4476.3.83 by Andrew Bennetts
Fix typo in comment.
99
    # there's nothing asserting that these labels correspond to what is
4476.3.75 by Andrew Bennetts
Restore InterRepo class names in per_interrepo test ids, but make it clear they are just labels and not actually part of the scenario.
100
    # actually used.
5050.32.1 by Andrew Bennetts
Fix fetching more than 100 revisions from non-rich-root to rich-root repositories.
101
    def force_known_graph(testcase):
102
        from bzrlib.fetch import Inter1and2Helper
103
        testcase.overrideAttr(Inter1and2Helper, 'known_graph_threshold', -1)
5676.1.1 by Jelmer Vernooij
Add RepositoryFormat._get_extra_interrepo_test_combinations.
104
    # Gather extra scenarios from the repository implementations,
105
    # as InterRepositories can be used by Repository implementations
106
    # they aren't aware of.
5676.1.9 by Jelmer Vernooij
Fix existing implementation.
107
    for module_name in format_registry._get_all_modules():
108
        module = pyutils.get_named_object(module_name)
5676.1.3 by Jelmer Vernooij
Move interrepo extra combinations function to module level.
109
        try:
5676.1.9 by Jelmer Vernooij
Fix existing implementation.
110
            get_extra_interrepo_test_combinations = getattr(
111
                module,
5676.1.3 by Jelmer Vernooij
Move interrepo extra combinations function to module level.
112
                "get_extra_interrepo_test_combinations")
113
        except AttributeError:
114
            continue
5676.1.1 by Jelmer Vernooij
Add RepositoryFormat._get_extra_interrepo_test_combinations.
115
        for (interrepo_cls, from_format, to_format) in (
5676.1.3 by Jelmer Vernooij
Move interrepo extra combinations function to module level.
116
            get_extra_interrepo_test_combinations()):
5676.1.1 by Jelmer Vernooij
Add RepositoryFormat._get_extra_interrepo_test_combinations.
117
            add_combo(interrepo_cls, from_format, to_format)
118
    add_combo(InterRepository,
4476.3.75 by Andrew Bennetts
Restore InterRepo class names in per_interrepo test ids, but make it clear they are just labels and not actually part of the scenario.
119
              knitrepo.RepositoryFormatKnit1(),
120
              knitrepo.RepositoryFormatKnit3())
5676.1.1 by Jelmer Vernooij
Add RepositoryFormat._get_extra_interrepo_test_combinations.
121
    add_combo(knitrepo.InterKnitRepo,
4476.3.75 by Andrew Bennetts
Restore InterRepo class names in per_interrepo test ids, but make it clear they are just labels and not actually part of the scenario.
122
              knitrepo.RepositoryFormatKnit1(),
4476.3.10 by Andrew Bennetts
Fix streaming of inventory records in get_stream_for_missing_keys, plus other tweaks.
123
              pack_repo.RepositoryFormatKnitPack1())
5676.1.1 by Jelmer Vernooij
Add RepositoryFormat._get_extra_interrepo_test_combinations.
124
    add_combo(knitrepo.InterKnitRepo,
4476.3.75 by Andrew Bennetts
Restore InterRepo class names in per_interrepo test ids, but make it clear they are just labels and not actually part of the scenario.
125
              pack_repo.RepositoryFormatKnitPack1(),
4476.3.10 by Andrew Bennetts
Fix streaming of inventory records in get_stream_for_missing_keys, plus other tweaks.
126
              knitrepo.RepositoryFormatKnit1())
5676.1.1 by Jelmer Vernooij
Add RepositoryFormat._get_extra_interrepo_test_combinations.
127
    add_combo(knitrepo.InterKnitRepo,
4476.3.75 by Andrew Bennetts
Restore InterRepo class names in per_interrepo test ids, but make it clear they are just labels and not actually part of the scenario.
128
              knitrepo.RepositoryFormatKnit3(),
4476.3.10 by Andrew Bennetts
Fix streaming of inventory records in get_stream_for_missing_keys, plus other tweaks.
129
              pack_repo.RepositoryFormatKnitPack3())
5676.1.1 by Jelmer Vernooij
Add RepositoryFormat._get_extra_interrepo_test_combinations.
130
    add_combo(knitrepo.InterKnitRepo,
4476.3.75 by Andrew Bennetts
Restore InterRepo class names in per_interrepo test ids, but make it clear they are just labels and not actually part of the scenario.
131
              pack_repo.RepositoryFormatKnitPack3(),
4476.3.10 by Andrew Bennetts
Fix streaming of inventory records in get_stream_for_missing_keys, plus other tweaks.
132
              knitrepo.RepositoryFormatKnit3())
5676.1.1 by Jelmer Vernooij
Add RepositoryFormat._get_extra_interrepo_test_combinations.
133
    add_combo(knitrepo.InterKnitRepo,
4476.3.75 by Andrew Bennetts
Restore InterRepo class names in per_interrepo test ids, but make it clear they are just labels and not actually part of the scenario.
134
              pack_repo.RepositoryFormatKnitPack3(),
4476.3.10 by Andrew Bennetts
Fix streaming of inventory records in get_stream_for_missing_keys, plus other tweaks.
135
              pack_repo.RepositoryFormatKnitPack4())
5676.1.1 by Jelmer Vernooij
Add RepositoryFormat._get_extra_interrepo_test_combinations.
136
    add_combo(InterDifferingSerializer,
4476.3.75 by Andrew Bennetts
Restore InterRepo class names in per_interrepo test ids, but make it clear they are just labels and not actually part of the scenario.
137
              pack_repo.RepositoryFormatKnitPack1(),
138
              pack_repo.RepositoryFormatKnitPack6RichRoot())
5676.1.1 by Jelmer Vernooij
Add RepositoryFormat._get_extra_interrepo_test_combinations.
139
    add_combo(InterDifferingSerializer,
5050.32.1 by Andrew Bennetts
Fix fetching more than 100 revisions from non-rich-root to rich-root repositories.
140
              pack_repo.RepositoryFormatKnitPack1(),
141
              pack_repo.RepositoryFormatKnitPack6RichRoot(),
142
              force_known_graph,
5676.1.1 by Jelmer Vernooij
Add RepositoryFormat._get_extra_interrepo_test_combinations.
143
              label='InterDifferingSerializer+get_known_graph_ancestry')
144
    add_combo(InterDifferingSerializer,
4476.3.75 by Andrew Bennetts
Restore InterRepo class names in per_interrepo test ids, but make it clear they are just labels and not actually part of the scenario.
145
              pack_repo.RepositoryFormatKnitPack6RichRoot(),
146
              groupcompress_repo.RepositoryFormat2a())
5676.1.1 by Jelmer Vernooij
Add RepositoryFormat._get_extra_interrepo_test_combinations.
147
    add_combo(InterDifferingSerializer,
4476.3.75 by Andrew Bennetts
Restore InterRepo class names in per_interrepo test ids, but make it clear they are just labels and not actually part of the scenario.
148
              groupcompress_repo.RepositoryFormat2a(),
149
              pack_repo.RepositoryFormatKnitPack6RichRoot())
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
150
    return result
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
151
152
5363.2.18 by Jelmer Vernooij
Rename TestCaseWithBzrDir -> TestCaseWithControlDir.
153
class TestCaseWithInterRepository(TestCaseWithControlDir):
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
154
155
    def setUp(self):
156
        super(TestCaseWithInterRepository, self).setUp()
5050.32.1 by Andrew Bennetts
Fix fetching more than 100 revisions from non-rich-root to rich-root repositories.
157
        if self.extra_setup:
158
            self.extra_setup(self)
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
159
160
    def make_branch(self, relpath, format=None):
161
        repo = self.make_repository(relpath, format=format)
162
        return repo.bzrdir.create_branch()
163
164
    def make_bzrdir(self, relpath, format=None):
165
        try:
166
            url = self.get_url(relpath)
167
            segments = url.split('/')
168
            if segments and segments[-1] not in ('', '.'):
169
                parent = '/'.join(segments[:-1])
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
170
                t = transport.get_transport(parent)
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
171
                try:
172
                    t.mkdir(segments[-1])
173
                except FileExists:
174
                    pass
175
            if format is None:
176
                format = self.repository_format._matchingbzrdir
177
            return format.initialize(url)
178
        except UninitializableFormat:
179
            raise TestSkipped("Format %s is not initializable." % format)
180
181
    def make_repository(self, relpath, format=None):
182
        made_control = self.make_bzrdir(relpath, format=format)
183
        return self.repository_format.initialize(made_control)
184
185
    def make_to_repository(self, relpath):
186
        made_control = self.make_bzrdir(relpath,
187
            self.repository_format_to._matchingbzrdir)
188
        return self.repository_format_to.initialize(made_control)
189
190
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
191
def load_tests(standard_tests, module, loader):
192
    submod_tests = loader.loadTestsFromModuleNames([
4523.1.3 by Martin Pool
Rename to per_interrepository
193
        'bzrlib.tests.per_interrepository.test_fetch',
194
        'bzrlib.tests.per_interrepository.test_interrepository',
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
195
        ])
196
    scenarios = make_scenarios(
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
197
        default_transport,
198
        # None here will cause a readonly decorator to be created
199
        # by the TestCaseWithTransport.get_readonly_transport method.
200
        None,
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
201
        default_test_list()
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
202
        )
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
203
    return multiply_tests(submod_tests, scenarios, standard_tests)