/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_interbranch/__init__.py

  • Committer: Martin Pool
  • Date: 2009-03-13 07:54:48 UTC
  • mfrom: (4144 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4189.
  • Revision ID: mbp@sourcefrog.net-20090313075448-jlz1t7baz7gzipqn
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009 Canonical Ltd
 
2
# -*- coding: utf-8 -*-
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 
 
18
 
 
19
"""InterBranch implementation tests for bzr.
 
20
 
 
21
These test the conformance of all the interbranch variations to the
 
22
expected API including generally applicable corner cases.
 
23
Specific tests for individual formats are in the tests for the formats
 
24
itself rather than in tests/per_interbranch/*.py.
 
25
"""
 
26
 
 
27
 
 
28
from bzrlib.branch import (
 
29
                           GenericInterBranch,
 
30
                           InterBranch,
 
31
                           )
 
32
from bzrlib.errors import (
 
33
    FileExists,
 
34
    UninitializableFormat,
 
35
    )
 
36
from bzrlib.tests import multiply_tests
 
37
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
 
38
from bzrlib.transport import get_transport
 
39
 
 
40
 
 
41
def make_scenarios(test_list):
 
42
    """Transform the input test list to a list of scenarios.
 
43
 
 
44
    :param formats: A list of tuples:
 
45
        (interbranch_class, branch_format_from, branch_format_to).
 
46
    """
 
47
    result = []
 
48
    for interbranch_class, branch_format_from, branch_format_to in test_list:
 
49
        id = '%s,%s,%s' % (interbranch_class.__name__,
 
50
                            branch_format_from.__class__.__name__,
 
51
                            branch_format_to.__class__.__name__)
 
52
        scenario = (id,
 
53
            {
 
54
             "branch_format_from": branch_format_from,
 
55
             "interbranch_class": interbranch_class,
 
56
             "branch_format_to": branch_format_to,
 
57
             })
 
58
        result.append(scenario)
 
59
    return result
 
60
 
 
61
 
 
62
def default_test_list():
 
63
    """Generate the default list of interbranch permutations to test."""
 
64
    result = []
 
65
    # test the default InterBranch between format 6 and the current
 
66
    # default format.
 
67
    for optimiser_class in InterBranch._optimisers:
 
68
        format_from_test, format_to_test = \
 
69
            optimiser_class._get_branch_formats_to_test()
 
70
        if format_to_test is not None:
 
71
            result.append((optimiser_class,
 
72
                           format_from_test, format_to_test))
 
73
    # if there are specific combinations we want to use, we can add them
 
74
    # here.
 
75
    return result
 
76
 
 
77
 
 
78
class TestCaseWithInterBranch(TestCaseWithBzrDir):
 
79
 
 
80
    def setUp(self):
 
81
        super(TestCaseWithInterBranch, self).setUp()
 
82
 
 
83
    def make_branch(self, relpath, format=None):
 
84
        repo = self.make_repository(relpath, format=format)
 
85
        return repo.bzrdir.create_branch()
 
86
 
 
87
    def make_bzrdir(self, relpath, format=None):
 
88
        try:
 
89
            url = self.get_url(relpath)
 
90
            segments = url.split('/')
 
91
            if segments and segments[-1] not in ('', '.'):
 
92
                parent = '/'.join(segments[:-1])
 
93
                t = get_transport(parent)
 
94
                try:
 
95
                    t.mkdir(segments[-1])
 
96
                except FileExists:
 
97
                    pass
 
98
            if format is None:
 
99
                format = self.branch_format_from._matchingbzrdir
 
100
            return format.initialize(url)
 
101
        except UninitializableFormat:
 
102
            raise TestSkipped("Format %s is not initializable." % format)
 
103
 
 
104
    def make_repository(self, relpath, format=None):
 
105
        made_control = self.make_bzrdir(relpath, format=format)
 
106
        return made_control.create_repository()
 
107
 
 
108
    def make_to_bzrdir(self, relpath):
 
109
        return self.make_bzrdir(relpath,
 
110
            self.branch_format_to._matchingbzrdir)
 
111
 
 
112
    def make_to_branch(self, relpath):
 
113
        made_control = self.make_to_bzrdir(relpath)
 
114
        return self.branch_format_to.initialize(made_control)
 
115
 
 
116
 
 
117
def load_tests(standard_tests, module, loader):
 
118
    submod_tests = loader.loadTestsFromModuleNames([
 
119
        'bzrlib.tests.per_interbranch.test_update_revisions',
 
120
        ])
 
121
    scenarios = make_scenarios(default_test_list())
 
122
    return multiply_tests(submod_tests, scenarios, standard_tests)