/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()))
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
125
        return result
126
127
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
128
class TestCaseWithInterRepository(TestCaseWithBzrDir):
129
130
    def setUp(self):
131
        super(TestCaseWithInterRepository, self).setUp()
132
133
    def make_branch(self, relpath, format=None):
134
        repo = self.make_repository(relpath, format=format)
135
        return repo.bzrdir.create_branch()
136
137
    def make_bzrdir(self, relpath, format=None):
138
        try:
139
            url = self.get_url(relpath)
140
            segments = url.split('/')
141
            if segments and segments[-1] not in ('', '.'):
142
                parent = '/'.join(segments[:-1])
143
                t = get_transport(parent)
144
                try:
145
                    t.mkdir(segments[-1])
146
                except FileExists:
147
                    pass
148
            if format is None:
149
                format = self.repository_format._matchingbzrdir
150
            return format.initialize(url)
151
        except UninitializableFormat:
152
            raise TestSkipped("Format %s is not initializable." % format)
153
154
    def make_repository(self, relpath, format=None):
155
        made_control = self.make_bzrdir(relpath, format=format)
156
        return self.repository_format.initialize(made_control)
157
158
    def make_to_repository(self, relpath):
159
        made_control = self.make_bzrdir(relpath,
160
            self.repository_format_to._matchingbzrdir)
161
        return self.repository_format_to.initialize(made_control)
162
163
3302.9.10 by Vincent Ladeuil
bzrlib.tests.interrepository_implementations switched from test_suite()
164
def load_tests(basic_tests, module, loader):
165
    result = loader.suiteClass()
166
    # add the tests for this module
167
    result.addTests(basic_tests)
168
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
169
    test_interrepository_implementations = [
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
170
        '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.
171
        'bzrlib.tests.interrepository_implementations.test_interrepository',
172
        ]
173
    adapter = InterRepositoryTestProviderAdapter(
174
        default_transport,
175
        # None here will cause a readonly decorator to be created
176
        # by the TestCaseWithTransport.get_readonly_transport method.
177
        None,
178
        InterRepositoryTestProviderAdapter.default_test_list()
179
        )
3302.9.27 by Vincent Ladeuil
Fixed as per Ian's review.
180
    # 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.
181
    adapt_modules(test_interrepository_implementations, adapter, loader, result)
182
    return result