/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,
43
                          TestLoader,
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
44
                          TestScenarioApplier,
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
45
                          TestSuite,
46
                          )
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
47
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
48
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.
49
50
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
51
class InterRepositoryTestProviderAdapter(TestScenarioApplier):
52
    """A tool to generate a suite testing multiple inter repository formats.
53
54
    This is done by copying the test once for each interrepo provider and injecting
55
    the transport_server, transport_readonly_server, repository_format and 
56
    repository_to_format classes into each copy.
57
    Each copy is also given a new id() to make it easy to identify.
58
    """
59
60
    def __init__(self, transport_server, transport_readonly_server, formats):
61
        TestScenarioApplier.__init__(self)
62
        self._transport_server = transport_server
63
        self._transport_readonly_server = transport_readonly_server
64
        self.scenarios = self.formats_to_scenarios(formats)
65
    
66
    def formats_to_scenarios(self, formats):
67
        """Transform the input formats to a list of scenarios.
68
69
        :param formats: A list of tuples:
70
            (interrepo_class, repository_format, repository_format_to).
71
        """
72
        result = []
73
        for interrepo_class, repository_format, repository_format_to in formats:
3302.5.4 by Vincent Ladeuil
Make interreop parametrized tests IDs unique.
74
            id = '%s,%s,%s' % (interrepo_class.__name__,
75
                                repository_format.__class__.__name__,
76
                                repository_format_to.__class__.__name__)
77
            scenario = (id,
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
78
                {"transport_server":self._transport_server,
79
                 "transport_readonly_server":self._transport_readonly_server,
80
                 "repository_format":repository_format,
81
                 "interrepo_class":interrepo_class,
82
                 "repository_format_to":repository_format_to,
83
                 })
84
            result.append(scenario)
85
        return result
86
    
87
    @staticmethod
88
    def default_test_list():
89
        """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.
90
        from bzrlib.repofmt import knitrepo, pack_repo, weaverepo
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
91
        result = []
92
        # test the default InterRepository between format 6 and the current 
93
        # default format.
94
        # XXX: robertc 20060220 reinstate this when there are two supported
95
        # formats which do not have an optimal code path between them.
96
        #result.append((InterRepository,
97
        #               RepositoryFormat6(),
98
        #               RepositoryFormatKnit1()))
99
        for optimiser_class in InterRepository._optimisers:
100
            format_to_test = optimiser_class._get_repo_format_to_test()
101
            if format_to_test is not None:
102
                result.append((optimiser_class,
103
                               format_to_test, format_to_test))
104
        # if there are specific combinations we want to use, we can add them 
105
        # here.
106
        result.append((InterModel1and2,
107
                       weaverepo.RepositoryFormat5(),
108
                       knitrepo.RepositoryFormatKnit3()))
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
109
        result.append((InterModel1and2,
110
                       knitrepo.RepositoryFormatKnit1(),
111
                       knitrepo.RepositoryFormatKnit3()))
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
112
        result.append((InterKnit1and2,
113
                       knitrepo.RepositoryFormatKnit1(),
114
                       knitrepo.RepositoryFormatKnit3()))
2998.2.2 by John Arbash Meinel
implement a faster path for copying from packs back to knits.
115
        result.append((InterKnitRepo,
116
                       knitrepo.RepositoryFormatKnit1(),
117
                       pack_repo.RepositoryFormatKnitPack1()))
118
        result.append((InterKnitRepo,
119
                       pack_repo.RepositoryFormatKnitPack1(),
120
                       knitrepo.RepositoryFormatKnit1()))
121
        result.append((InterKnitRepo,
122
                       knitrepo.RepositoryFormatKnit3(),
123
                       pack_repo.RepositoryFormatKnitPack3()))
124
        result.append((InterKnitRepo,
125
                       pack_repo.RepositoryFormatKnitPack3(),
126
                       knitrepo.RepositoryFormatKnit3()))
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
127
        return result
128
129
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
130
class TestCaseWithInterRepository(TestCaseWithBzrDir):
131
132
    def setUp(self):
133
        super(TestCaseWithInterRepository, self).setUp()
134
135
    def make_branch(self, relpath, format=None):
136
        repo = self.make_repository(relpath, format=format)
137
        return repo.bzrdir.create_branch()
138
139
    def make_bzrdir(self, relpath, format=None):
140
        try:
141
            url = self.get_url(relpath)
142
            segments = url.split('/')
143
            if segments and segments[-1] not in ('', '.'):
144
                parent = '/'.join(segments[:-1])
145
                t = get_transport(parent)
146
                try:
147
                    t.mkdir(segments[-1])
148
                except FileExists:
149
                    pass
150
            if format is None:
151
                format = self.repository_format._matchingbzrdir
152
            return format.initialize(url)
153
        except UninitializableFormat:
154
            raise TestSkipped("Format %s is not initializable." % format)
155
156
    def make_repository(self, relpath, format=None):
157
        made_control = self.make_bzrdir(relpath, format=format)
158
        return self.repository_format.initialize(made_control)
159
160
    def make_to_repository(self, relpath):
161
        made_control = self.make_bzrdir(relpath,
162
            self.repository_format_to._matchingbzrdir)
163
        return self.repository_format_to.initialize(made_control)
164
165
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
166
def test_suite():
167
    result = TestSuite()
168
    test_interrepository_implementations = [
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
169
        '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.
170
        'bzrlib.tests.interrepository_implementations.test_interrepository',
171
        ]
172
    adapter = InterRepositoryTestProviderAdapter(
173
        default_transport,
174
        # None here will cause a readonly decorator to be created
175
        # by the TestCaseWithTransport.get_readonly_transport method.
176
        None,
177
        InterRepositoryTestProviderAdapter.default_test_list()
178
        )
179
    loader = TestLoader()
180
    adapt_modules(test_interrepository_implementations, adapter, loader, result)
181
    return result