/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
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
4183.7.1 by Sabin Iacob
update FSF mailing address
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
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.
4000.5.8 by Jelmer Vernooij
Fix whitespace.
23
Specific tests for individual formats are in the tests for the formats
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
24
itself rather than in tests/per_interbranch/*.py.
25
"""
26
27
4000.5.11 by Jelmer Vernooij
Improve tests for InterBranch.pull.
28
from bzrlib import (
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
29
    branchbuilder,
4000.5.11 by Jelmer Vernooij
Improve tests for InterBranch.pull.
30
    memorytree,
31
    )
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
32
from bzrlib.branch import (
33
                           GenericInterBranch,
34
                           InterBranch,
35
                           )
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
36
from bzrlib.bzrdir import (
37
    BzrDirFormat,
38
    BzrDirMetaFormat1,
39
    )
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
40
from bzrlib.errors import (
41
    FileExists,
4000.5.11 by Jelmer Vernooij
Improve tests for InterBranch.pull.
42
    NotBranchError,
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
43
    UninitializableFormat,
44
    )
4211.1.6 by Jelmer Vernooij
Review from Ian.
45
from bzrlib.tests import (
46
    TestCaseWithTransport,
47
    multiply_tests,
48
    )
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
49
from bzrlib.transport import get_transport
50
51
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
52
def make_scenarios(test_list):
53
    """Transform the input test list to a list of scenarios.
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
54
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
55
    :param formats: A list of tuples:
56
        (interbranch_class, branch_format_from, branch_format_to).
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
57
    """
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
58
    result = []
59
    for interbranch_class, branch_format_from, branch_format_to in test_list:
60
        id = '%s,%s,%s' % (interbranch_class.__name__,
61
                            branch_format_from.__class__.__name__,
62
                            branch_format_to.__class__.__name__)
63
        scenario = (id,
64
            {
65
             "branch_format_from": branch_format_from,
66
             "interbranch_class": interbranch_class,
67
             "branch_format_to": branch_format_to,
68
             })
69
        result.append(scenario)
70
    return result
71
72
73
def default_test_list():
74
    """Generate the default list of interbranch permutations to test."""
75
    result = []
76
    # test the default InterBranch between format 6 and the current
77
    # default format.
78
    for optimiser_class in InterBranch._optimisers:
5297.2.1 by Robert Collins
``bzrlib.branch.InterBranch._get_branch_formats_to_test`` now returns
79
        for format_from_test, format_to_test in \
80
            optimiser_class._get_branch_formats_to_test():
81
            result.append((optimiser_class, format_from_test, format_to_test))
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
82
    # if there are specific combinations we want to use, we can add them
83
    # here.
84
    return result
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
85
86
4216.7.1 by Jelmer Vernooij
Simplify interbranch test base class.
87
class TestCaseWithInterBranch(TestCaseWithTransport):
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
88
4216.7.1 by Jelmer Vernooij
Simplify interbranch test base class.
89
    def make_from_branch(self, relpath):
90
        repo = self.make_repository(relpath)
91
        return self.branch_format_from.initialize(repo.bzrdir)
92
93
    def make_from_branch_and_memory_tree(self, relpath):
94
        """Create a branch on the default transport and a MemoryTree for it."""
95
        b = self.make_from_branch(relpath)
96
        return memorytree.MemoryTree.create_on_branch(b)
97
98
    def make_from_branch_and_tree(self, relpath):
99
        """Create a branch on the default transport and a working tree for it."""
100
        b = self.make_from_branch(relpath)
101
        return b.bzrdir.create_workingtree()
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
102
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
103
    def make_from_branch_builder(self, relpath):
104
        default_format = BzrDirFormat.get_default_format()
105
        format = BzrDirMetaFormat1()
106
        format.set_branch_format(self.branch_format_from)
107
        format.repository_format = default_format.repository_format
108
        format.workingtree_format = default_format.workingtree_format
109
        return branchbuilder.BranchBuilder(self.get_transport(relpath),
110
            format=format)
111
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
112
    def make_to_branch(self, relpath):
4216.7.1 by Jelmer Vernooij
Simplify interbranch test base class.
113
        repo = self.make_repository(relpath)
114
        return self.branch_format_to.initialize(repo.bzrdir)
4000.5.11 by Jelmer Vernooij
Improve tests for InterBranch.pull.
115
116
    def make_to_branch_and_memory_tree(self, relpath):
117
        """Create a branch on the default transport and a MemoryTree for it."""
118
        b = self.make_to_branch(relpath)
119
        return memorytree.MemoryTree.create_on_branch(b)
120
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
121
    def make_to_branch_and_tree(self, relpath):
122
        """Create a branch on the default transport and a working tree for it."""
123
        b = self.make_to_branch(relpath)
124
        return b.bzrdir.create_workingtree()
125
4000.5.11 by Jelmer Vernooij
Improve tests for InterBranch.pull.
126
    def sprout_to(self, origdir, to_url):
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
127
        """Sprout a bzrdir, using to_format for the new branch."""
4000.5.11 by Jelmer Vernooij
Improve tests for InterBranch.pull.
128
        newbranch = self.make_to_branch(to_url)
4000.5.20 by Jelmer Vernooij
Fix InterBranch.pull tests.
129
        origbranch = origdir.open_branch()
130
        newbranch.repository.fetch(origbranch.repository)
131
        origbranch.copy_content_into(newbranch)
4000.5.11 by Jelmer Vernooij
Improve tests for InterBranch.pull.
132
        newbranch.bzrdir.create_workingtree()
133
        return newbranch.bzrdir
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
134
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
135
    def sprout_from(self, origdir, to_url):
136
        """Sprout a bzrdir, using from_format for the new bzrdir."""
137
        newbranch = self.make_from_branch(to_url)
138
        origbranch = origdir.open_branch()
139
        newbranch.repository.fetch(origbranch.repository)
140
        origbranch.copy_content_into(newbranch)
141
        newbranch.bzrdir.create_workingtree()
142
        return newbranch.bzrdir
143
144
5284.4.2 by Robert Collins
* ``Branch.copy_content_into`` is now a convenience method dispatching to
145
class StubWithFormat(object):
146
    """A stub object used to check that convenience methods call Inter's."""
147
148
    _format = object()
149
150
151
class StubMatchingInter(object):
152
    """An inter for tests.
153
154
    This is not a subclass of InterBranch so that missing methods are caught
155
    and added rather than actually trying to do something.
156
    """
157
158
    _uses = []
159
160
    def __init__(self, source, target):
161
        self.source = source
162
        self.target = target
163
164
    @classmethod
165
    def is_compatible(klass, source, target):
166
        return StubWithFormat._format in (source._format, target._format)
167
168
    def copy_content_into(self, *args, **kwargs):
169
        self.__class__._uses.append(
170
            (self, 'copy_content_into', args, kwargs))
171
172
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
173
def load_tests(standard_tests, module, loader):
174
    submod_tests = loader.loadTestsFromModuleNames([
5284.4.1 by Robert Collins
* Fetching was slightly confused about the best code to use and was
175
        'bzrlib.tests.per_interbranch.test_get',
5284.4.2 by Robert Collins
* ``Branch.copy_content_into`` is now a convenience method dispatching to
176
        'bzrlib.tests.per_interbranch.test_copy_content_into',
4000.5.11 by Jelmer Vernooij
Improve tests for InterBranch.pull.
177
        'bzrlib.tests.per_interbranch.test_pull',
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
178
        'bzrlib.tests.per_interbranch.test_push',
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
179
        'bzrlib.tests.per_interbranch.test_update_revisions',
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
180
        ])
181
    scenarios = make_scenarios(default_test_list())
182
    return multiply_tests(submod_tests, scenarios, standard_tests)