/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
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
28
from bzrlib.repository import (
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
29
                               InterRepository,
30
                               InterModel1and2,
31
                               InterKnit1and2,
32
                               )
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
33
from bzrlib.tests import (
34
                          adapt_modules,
35
                          default_transport,
36
                          TestLoader,
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
37
                          TestScenarioApplier,
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
38
                          TestSuite,
39
                          )
40
41
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
42
class InterRepositoryTestProviderAdapter(TestScenarioApplier):
43
    """A tool to generate a suite testing multiple inter repository formats.
44
45
    This is done by copying the test once for each interrepo provider and injecting
46
    the transport_server, transport_readonly_server, repository_format and 
47
    repository_to_format classes into each copy.
48
    Each copy is also given a new id() to make it easy to identify.
49
    """
50
51
    def __init__(self, transport_server, transport_readonly_server, formats):
52
        TestScenarioApplier.__init__(self)
53
        self._transport_server = transport_server
54
        self._transport_readonly_server = transport_readonly_server
55
        self.scenarios = self.formats_to_scenarios(formats)
56
    
57
    def formats_to_scenarios(self, formats):
58
        """Transform the input formats to a list of scenarios.
59
60
        :param formats: A list of tuples:
61
            (interrepo_class, repository_format, repository_format_to).
62
        """
63
        result = []
64
        for interrepo_class, repository_format, repository_format_to in formats:
65
            scenario = (interrepo_class.__name__,
66
                {"transport_server":self._transport_server,
67
                 "transport_readonly_server":self._transport_readonly_server,
68
                 "repository_format":repository_format,
69
                 "interrepo_class":interrepo_class,
70
                 "repository_format_to":repository_format_to,
71
                 })
72
            result.append(scenario)
73
        return result
74
    
75
    @staticmethod
76
    def default_test_list():
77
        """Generate the default list of interrepo permutations to test."""
78
        from bzrlib.repofmt import knitrepo, weaverepo
79
        result = []
80
        # test the default InterRepository between format 6 and the current 
81
        # default format.
82
        # XXX: robertc 20060220 reinstate this when there are two supported
83
        # formats which do not have an optimal code path between them.
84
        #result.append((InterRepository,
85
        #               RepositoryFormat6(),
86
        #               RepositoryFormatKnit1()))
87
        for optimiser_class in InterRepository._optimisers:
88
            format_to_test = optimiser_class._get_repo_format_to_test()
89
            if format_to_test is not None:
90
                result.append((optimiser_class,
91
                               format_to_test, format_to_test))
92
        # if there are specific combinations we want to use, we can add them 
93
        # here.
94
        result.append((InterModel1and2,
95
                       weaverepo.RepositoryFormat5(),
96
                       knitrepo.RepositoryFormatKnit3()))
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
97
        result.append((InterModel1and2,
98
                       knitrepo.RepositoryFormatKnit1(),
99
                       knitrepo.RepositoryFormatKnit3()))
2553.2.4 by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter
100
        result.append((InterKnit1and2,
101
                       knitrepo.RepositoryFormatKnit1(),
102
                       knitrepo.RepositoryFormatKnit3()))
103
        return result
104
105
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
106
def test_suite():
107
    result = TestSuite()
108
    test_interrepository_implementations = [
109
        'bzrlib.tests.interrepository_implementations.test_interrepository',
110
        ]
111
    adapter = InterRepositoryTestProviderAdapter(
112
        default_transport,
113
        # None here will cause a readonly decorator to be created
114
        # by the TestCaseWithTransport.get_readonly_transport method.
115
        None,
116
        InterRepositoryTestProviderAdapter.default_test_list()
117
        )
118
    loader = TestLoader()
119
    adapt_modules(test_interrepository_implementations, adapter, loader, result)
120
    return result