/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
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
29
from bzrlib import transport
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
30
from bzrlib.errors import (
31
    FileExists,
32
    UninitializableFormat,
33
    )
34
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
35
from bzrlib.repository import (
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.
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
                          default_transport,
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
40
                          multiply_tests,
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
41
                          )
5363.2.18 by Jelmer Vernooij
Rename TestCaseWithBzrDir -> TestCaseWithControlDir.
42
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.
43
44
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
45
def make_scenarios(transport_server, transport_readonly_server, formats):
46
    """Transform the input formats to a list of scenarios.
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
47
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
48
    :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.
49
        (label, repository_format, repository_format_to).
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
50
    """
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
51
    result = []
5050.32.1 by Andrew Bennetts
Fix fetching more than 100 revisions from non-rich-root to rich-root repositories.
52
    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.
53
        id = '%s,%s,%s' % (label, repository_format.__class__.__name__,
54
                           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.
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,
5050.32.1 by Andrew Bennetts
Fix fetching more than 100 revisions from non-rich-root to rich-root repositories.
60
             "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.
61
             })
62
        result.append(scenario)
63
    return result
64
65
66
def default_test_list():
67
    """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.
68
    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.
69
        groupcompress_repo,
70
        knitrepo,
71
        pack_repo,
72
        weaverepo,
4476.3.4 by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out.
73
        )
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
74
    result = []
5050.32.1 by Andrew Bennetts
Fix fetching more than 100 revisions from non-rich-root to rich-root repositories.
75
    def add_combo(label, from_format, to_format, extra_setup=None):
76
        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.
77
    # test the default InterRepository between format 6 and the current
78
    # default format.
79
    # XXX: robertc 20060220 reinstate this when there are two supported
80
    # formats which do not have an optimal code path between them.
81
    #result.append((InterRepository,
82
    #               RepositoryFormat6(),
83
    #               RepositoryFormatKnit1()))
84
    for optimiser_class in InterRepository._optimisers:
85
        format_to_test = optimiser_class._get_repo_format_to_test()
86
        if format_to_test is not None:
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.
87
            add_combo(optimiser_class.__name__, 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.
88
    # if there are specific combinations we want to use, we can add them
89
    # 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.
90
    # XXX: although we attach InterRepository class names to these scenarios,
4476.3.83 by Andrew Bennetts
Fix typo in comment.
91
    # 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.
92
    # actually used.
5050.32.1 by Andrew Bennetts
Fix fetching more than 100 revisions from non-rich-root to rich-root repositories.
93
    def force_known_graph(testcase):
94
        from bzrlib.fetch import Inter1and2Helper
95
        testcase.overrideAttr(Inter1and2Helper, 'known_graph_threshold', -1)
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.
96
    add_combo('InterRepository',
97
              weaverepo.RepositoryFormat5(),
98
              knitrepo.RepositoryFormatKnit3())
99
    add_combo('InterRepository',
100
              knitrepo.RepositoryFormatKnit1(),
101
              knitrepo.RepositoryFormatKnit3())
102
    add_combo('InterKnitRepo',
103
              knitrepo.RepositoryFormatKnit1(),
4476.3.10 by Andrew Bennetts
Fix streaming of inventory records in get_stream_for_missing_keys, plus other tweaks.
104
              pack_repo.RepositoryFormatKnitPack1())
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.
105
    add_combo('InterKnitRepo',
106
              pack_repo.RepositoryFormatKnitPack1(),
4476.3.10 by Andrew Bennetts
Fix streaming of inventory records in get_stream_for_missing_keys, plus other tweaks.
107
              knitrepo.RepositoryFormatKnit1())
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.
108
    add_combo('InterKnitRepo',
109
              knitrepo.RepositoryFormatKnit3(),
4476.3.10 by Andrew Bennetts
Fix streaming of inventory records in get_stream_for_missing_keys, plus other tweaks.
110
              pack_repo.RepositoryFormatKnitPack3())
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.
111
    add_combo('InterKnitRepo',
112
              pack_repo.RepositoryFormatKnitPack3(),
4476.3.10 by Andrew Bennetts
Fix streaming of inventory records in get_stream_for_missing_keys, plus other tweaks.
113
              knitrepo.RepositoryFormatKnit3())
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.
114
    add_combo('InterKnitRepo',
115
              pack_repo.RepositoryFormatKnitPack3(),
4476.3.10 by Andrew Bennetts
Fix streaming of inventory records in get_stream_for_missing_keys, plus other tweaks.
116
              pack_repo.RepositoryFormatKnitPack4())
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.
117
    add_combo('InterDifferingSerializer',
118
              pack_repo.RepositoryFormatKnitPack1(),
119
              pack_repo.RepositoryFormatKnitPack6RichRoot())
5050.32.1 by Andrew Bennetts
Fix fetching more than 100 revisions from non-rich-root to rich-root repositories.
120
    add_combo('InterDifferingSerializer+get_known_graph_ancestry',
121
              pack_repo.RepositoryFormatKnitPack1(),
122
              pack_repo.RepositoryFormatKnitPack6RichRoot(),
123
              force_known_graph,
124
              )
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
    add_combo('InterDifferingSerializer',
126
              pack_repo.RepositoryFormatKnitPack6RichRoot(),
127
              groupcompress_repo.RepositoryFormat2a())
128
    add_combo('InterDifferingSerializer',
129
              groupcompress_repo.RepositoryFormat2a(),
130
              pack_repo.RepositoryFormatKnitPack6RichRoot())
131
    add_combo('InterRepository',
132
              groupcompress_repo.RepositoryFormatCHK2(),
133
              groupcompress_repo.RepositoryFormat2a())
134
    add_combo('InterDifferingSerializer',
135
              groupcompress_repo.RepositoryFormatCHK1(),
4476.3.29 by Andrew Bennetts
Add Repository.get_stream_1.18 verb.
136
              groupcompress_repo.RepositoryFormat2a())
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
137
    return result
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
138
139
5363.2.18 by Jelmer Vernooij
Rename TestCaseWithBzrDir -> TestCaseWithControlDir.
140
class TestCaseWithInterRepository(TestCaseWithControlDir):
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
141
142
    def setUp(self):
143
        super(TestCaseWithInterRepository, self).setUp()
5050.32.1 by Andrew Bennetts
Fix fetching more than 100 revisions from non-rich-root to rich-root repositories.
144
        if self.extra_setup:
145
            self.extra_setup(self)
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
146
147
    def make_branch(self, relpath, format=None):
148
        repo = self.make_repository(relpath, format=format)
149
        return repo.bzrdir.create_branch()
150
151
    def make_bzrdir(self, relpath, format=None):
152
        try:
153
            url = self.get_url(relpath)
154
            segments = url.split('/')
155
            if segments and segments[-1] not in ('', '.'):
156
                parent = '/'.join(segments[:-1])
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
157
                t = transport.get_transport(parent)
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
158
                try:
159
                    t.mkdir(segments[-1])
160
                except FileExists:
161
                    pass
162
            if format is None:
163
                format = self.repository_format._matchingbzrdir
164
            return format.initialize(url)
165
        except UninitializableFormat:
166
            raise TestSkipped("Format %s is not initializable." % format)
167
168
    def make_repository(self, relpath, format=None):
169
        made_control = self.make_bzrdir(relpath, format=format)
170
        return self.repository_format.initialize(made_control)
171
172
    def make_to_repository(self, relpath):
173
        made_control = self.make_bzrdir(relpath,
174
            self.repository_format_to._matchingbzrdir)
175
        return self.repository_format_to.initialize(made_control)
176
177
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
178
def load_tests(standard_tests, module, loader):
179
    submod_tests = loader.loadTestsFromModuleNames([
4523.1.3 by Martin Pool
Rename to per_interrepository
180
        'bzrlib.tests.per_interrepository.test_fetch',
181
        '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.
182
        ])
183
    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.
184
        default_transport,
185
        # None here will cause a readonly decorator to be created
186
        # by the TestCaseWithTransport.get_readonly_transport method.
187
        None,
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
188
        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.
189
        )
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
190
    return multiply_tests(submod_tests, scenarios, standard_tests)