/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.
24
Specific tests for individual formats are in the tests/test_repository.py file 
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,
36
                               InterKnit1and2,
37
                               InterModel1and2,
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
38
                               InterRepository,
39
                               )
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
40
from bzrlib.tests import (
41
                          adapt_modules,
42
                          default_transport,
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
43
                          TestScenarioApplier,
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
44
                          )
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
45
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
46
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.
47
48
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
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:
3302.5.4 by Vincent Ladeuil
Make interreop parametrized tests IDs unique.
72
            id = '%s,%s,%s' % (interrepo_class.__name__,
73
                                repository_format.__class__.__name__,
74
                                repository_format_to.__class__.__name__)
75
            scenario = (id,
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
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."""
2998.2.2 by John Arbash Meinel
implement a faster path for copying from packs back to knits.
88
        from bzrlib.repofmt import knitrepo, pack_repo, weaverepo
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
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()))
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
107
        result.append((InterModel1and2,
108
                       knitrepo.RepositoryFormatKnit1(),
109
                       knitrepo.RepositoryFormatKnit3()))
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
110
        result.append((InterKnit1and2,
111
                       knitrepo.RepositoryFormatKnit1(),
112
                       knitrepo.RepositoryFormatKnit3()))
2998.2.2 by John Arbash Meinel
implement a faster path for copying from packs back to knits.
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()))
3879.2.7 by John Arbash Meinel
Add an Inter test that actually uses InterDifferingSerializer
125
        result.append((InterKnitRepo,
126
                       pack_repo.RepositoryFormatKnitPack3(),
127
                       pack_repo.RepositoryFormatKnitPack4()))
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
128
        return result
129
130
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
131
class TestCaseWithInterRepository(TestCaseWithBzrDir):
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 = 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
3302.9.10 by Vincent Ladeuil
bzrlib.tests.interrepository_implementations switched from test_suite()
167
def load_tests(basic_tests, module, loader):
168
    result = loader.suiteClass()
169
    # add the tests for this module
170
    result.addTests(basic_tests)
171
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
172
    test_interrepository_implementations = [
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
173
        '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.
174
        'bzrlib.tests.interrepository_implementations.test_interrepository',
175
        ]
176
    adapter = InterRepositoryTestProviderAdapter(
177
        default_transport,
178
        # None here will cause a readonly decorator to be created
179
        # by the TestCaseWithTransport.get_readonly_transport method.
180
        None,
181
        InterRepositoryTestProviderAdapter.default_test_list()
182
        )
3302.9.27 by Vincent Ladeuil
Fixed as per Ian's review.
183
    # 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.
184
    adapt_modules(test_interrepository_implementations, adapter, loader, result)
185
    return result