~bzr-pqm/bzr/bzr.dev

5128.1.1 by Vincent Ladeuil
Uncontroversial cleanups, mostly comments
1
# Copyright (C) 2006-2010 Canonical Ltd
1534.4.24 by Robert Collins
update (C) on branch_implementations/__init__.py
2
# Authors: Robert Collins <robert.collins@canonical.com>
2220.2.17 by Martin Pool
merge up from bzr.dev to get metadir changes
3
#          and others
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
4
#
1534.4.23 by Robert Collins
Move branch implementations tests into a package.
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.4.23 by Robert Collins
Move branch implementations tests into a package.
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.4.23 by Robert Collins
Move branch implementations tests into a package.
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
4183.7.1 by Sabin Iacob
update FSF mailing address
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1534.4.23 by Robert Collins
Move branch implementations tests into a package.
18
19
20
"""Branch implementation tests for bzr.
21
22
These test the conformance of all the branch variations to the expected API.
5891.1.2 by Andrew Bennetts
Fix a bunch of docstring formatting nits, making pydoctor a bit happier.
23
Specific tests for individual formats are in the `tests/test_branch` file
24
rather than in `tests/per_branch/*.py`.
1534.4.23 by Robert Collins
Move branch implementations tests into a package.
25
"""
26
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
27
from bzrlib import (
28
    errors,
29
    tests,
30
    )
5662.2.2 by Jelmer Vernooij
Move most format registration functions to BranchFormatRegistry.
31
from bzrlib.branch import format_registry
32
from bzrlib.remote import RemoteBranchFormat
5017.3.24 by Vincent Ladeuil
selftest -s bt.test_selftest passing
33
from bzrlib.tests import test_server
5363.2.18 by Jelmer Vernooij
Rename TestCaseWithBzrDir -> TestCaseWithControlDir.
34
from bzrlib.tests.per_controldir.test_controldir import TestCaseWithControlDir
5017.3.45 by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry.
35
from bzrlib.transport import memory
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
36
37
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
38
def make_scenarios(transport_server, transport_readonly_server,
39
    formats, vfs_transport_factory=None, name_suffix=''):
40
    """Transform the input formats to a list of scenarios.
2553.2.6 by Robert Collins
And overhaul BranchTestProviderAdapter too.
41
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
42
    :param formats: A list of (branch_format, bzrdir_format).
2553.2.6 by Robert Collins
And overhaul BranchTestProviderAdapter too.
43
    """
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
44
    result = []
45
    for branch_format, bzrdir_format in formats:
46
        # some branches don't have separate format objects.
47
        # so we have a conditional here to handle them.
48
        scenario_name = getattr(branch_format, '__name__',
49
            branch_format.__class__.__name__)
50
        scenario_name += name_suffix
51
        scenario = (scenario_name, {
52
            "transport_server":transport_server,
53
            "transport_readonly_server":transport_readonly_server,
54
            "bzrdir_format":bzrdir_format,
55
            "branch_format":branch_format,
56
                })
57
        result.append(scenario)
58
    return result
2553.2.6 by Robert Collins
And overhaul BranchTestProviderAdapter too.
59
60
5363.2.18 by Jelmer Vernooij
Rename TestCaseWithBzrDir -> TestCaseWithControlDir.
61
class TestCaseWithBranch(TestCaseWithControlDir):
5128.1.1 by Vincent Ladeuil
Uncontroversial cleanups, mostly comments
62
    """This helper will be parameterised in each per_branch test."""
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
63
64
    def setUp(self):
65
        super(TestCaseWithBranch, self).setUp()
66
        self.branch = None
67
68
    def get_branch(self):
69
        if self.branch is None:
6127.1.9 by Jelmer Vernooij
Add lightweight option to _get_checkout_format().
70
            self.branch = self.make_branch('abranch')
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
71
        return self.branch
72
73
    def make_branch(self, relpath, format=None):
4617.3.1 by Robert Collins
Fix test_stacking tests for 2a as a default format. The change to 2a exposed some actual bugs, both in tests and bzrdir/branch code.
74
        if format is not None:
5363.2.18 by Jelmer Vernooij
Rename TestCaseWithBzrDir -> TestCaseWithControlDir.
75
            return TestCaseWithControlDir.make_branch(self, relpath, format)
4617.3.1 by Robert Collins
Fix test_stacking tests for 2a as a default format. The change to 2a exposed some actual bugs, both in tests and bzrdir/branch code.
76
        repo = self.make_repository(relpath)
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
77
        # fixme RBC 20060210 this isnt necessarily a fixable thing,
78
        # Skipped is the wrong exception to raise.
79
        try:
6123.9.7 by Jelmer Vernooij
Set append_revisions_only to False explicitly, for formats that have
80
            branch = self.branch_format.initialize(repo.bzrdir)
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
81
        except errors.UninitializableFormat:
82
            raise tests.TestSkipped('Uninitializable branch format')
6123.9.11 by Jelmer Vernooij
Make get_append_revisions_only public.
83
        if (branch._format.supports_set_append_revisions_only() and
84
            branch.get_append_revisions_only()):
6123.9.7 by Jelmer Vernooij
Set append_revisions_only to False explicitly, for formats that have
85
            branch.set_append_revisions_only(False)
86
        return branch
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
87
3904.3.4 by Andrew Bennetts
First cut of a branch_implementations test. It fails.
88
    def make_branch_builder(self, relpath, format=None):
89
        if format is None:
90
            format = self.branch_format._matchingbzrdir
91
        return super(TestCaseWithBranch, self).make_branch_builder(
92
            relpath, format=format)
93
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
94
    def make_repository(self, relpath, shared=False, format=None):
95
        made_control = self.make_bzrdir(relpath, format=format)
96
        return made_control.create_repository(shared=shared)
97
98
    def create_tree_with_merge(self):
99
        """Create a branch with a simple ancestry.
100
101
        The graph should look like:
102
            digraph H {
103
                "rev-1" -> "rev-2" -> "rev-3";
104
                "rev-1" -> "rev-1.1.1" -> "rev-3";
105
            }
106
107
        Or in ASCII:
2418.5.14 by John Arbash Meinel
clean up ASCII revision graph art.
108
            1
109
            |\
110
            2 1.1.1
111
            |/
112
            3
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
113
        """
114
        tree = self.make_branch_and_memory_tree('tree')
115
        tree.lock_write()
116
        try:
117
            tree.add('')
118
            tree.commit('first', rev_id='rev-1')
2418.5.3 by John Arbash Meinel
Use a more straightforward implementation of generating 'tree_with_merge'
119
            tree.commit('second', rev_id='rev-1.1.1')
2418.5.10 by John Arbash Meinel
fix typo
120
            # Uncommit that last commit and switch to the other line
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
121
            tree.branch.set_last_revision_info(1, 'rev-1')
122
            tree.set_parent_ids(['rev-1'])
2418.5.3 by John Arbash Meinel
Use a more straightforward implementation of generating 'tree_with_merge'
123
            tree.commit('alt-second', rev_id='rev-2')
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
124
            tree.set_parent_ids(['rev-2', 'rev-1.1.1'])
125
            tree.commit('third', rev_id='rev-3')
126
        finally:
127
            tree.unlock()
128
129
        return tree
1534.4.23 by Robert Collins
Move branch implementations tests into a package.
130
1534.4.24 by Robert Collins
update (C) on branch_implementations/__init__.py
131
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
132
def branch_scenarios():
133
    """ """
134
    # Generate a list of branch formats and their associated bzrdir formats to
135
    # use.
136
    combinations = [(format, format._matchingbzrdir) for format in
5662.2.2 by Jelmer Vernooij
Move most format registration functions to BranchFormatRegistry.
137
         format_registry._get_all()]
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
138
    scenarios = make_scenarios(
139
        # None here will cause the default vfs transport server to be used.
140
        None,
141
        # None here will cause a readonly decorator to be created
142
        # by the TestCaseWithTransport.get_readonly_transport method.
143
        None,
144
        combinations)
145
    # Add RemoteBranch tests, which need a special server.
146
    remote_branch_format = RemoteBranchFormat()
147
    scenarios.extend(make_scenarios(
5017.3.24 by Vincent Ladeuil
selftest -s bt.test_selftest passing
148
        test_server.SmartTCPServer_for_testing,
149
        test_server.ReadonlySmartTCPServer_for_testing,
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
150
        [(remote_branch_format, remote_branch_format._matchingbzrdir)],
5017.3.45 by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry.
151
        memory.MemoryServer,
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
152
        name_suffix='-default'))
153
    # Also add tests for RemoteBranch with HPSS protocol v2 (i.e. bzr <1.6)
154
    # server.
155
    scenarios.extend(make_scenarios(
5017.3.24 by Vincent Ladeuil
selftest -s bt.test_selftest passing
156
        test_server.SmartTCPServer_for_testing_v2_only,
157
        test_server.ReadonlySmartTCPServer_for_testing_v2_only,
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
158
        [(remote_branch_format, remote_branch_format._matchingbzrdir)],
5017.3.45 by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry.
159
        memory.MemoryServer,
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
160
        name_suffix='-v2'))
161
    return scenarios
162
163
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
164
def load_tests(standard_tests, module, loader):
4523.1.5 by Vincent Ladeuil
Fixed as asked in review.
165
    per_branch_mod_names = [
166
        'bound_sftp',
167
        'branch',
168
        'break_lock',
169
        'check',
5227.1.1 by Andrew Bennetts
Add failing test for bug 430382.
170
        'config',
4523.1.5 by Vincent Ladeuil
Fixed as asked in review.
171
        'create_checkout',
172
        'create_clone',
173
        'commit',
174
        'dotted_revno_to_revision_id',
175
        'get_revision_id_to_revno_map',
176
        'hooks',
177
        'http',
178
        'iter_merge_sorted_revisions',
179
        'last_revision_info',
180
        'locking',
181
        'parent',
182
        'permissions',
183
        'pull',
184
        'push',
185
        'reconcile',
186
        'revision_history',
187
        'revision_id_to_dotted_revno',
188
        'revision_id_to_revno',
189
        'sprout',
190
        'stacking',
191
        'tags',
192
        'uncommit',
193
        'update',
1534.4.23 by Robert Collins
Move branch implementations tests into a package.
194
        ]
4523.1.5 by Vincent Ladeuil
Fixed as asked in review.
195
    sub_tests = loader.loadTestsFromModuleNames(
196
        ['bzrlib.tests.per_branch.test_' + name
197
         for name in per_branch_mod_names])
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
198
    return tests.multiply_tests(sub_tests, branch_scenarios(), standard_tests)