/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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:
70
            self.branch = self.make_branch('')
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:
80
            return self.branch_format.initialize(repo.bzrdir)
81
        except errors.UninitializableFormat:
82
            raise tests.TestSkipped('Uninitializable branch format')
83
3904.3.4 by Andrew Bennetts
First cut of a branch_implementations test. It fails.
84
    def make_branch_builder(self, relpath, format=None):
85
        if format is None:
86
            format = self.branch_format._matchingbzrdir
87
        return super(TestCaseWithBranch, self).make_branch_builder(
88
            relpath, format=format)
89
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
90
    def make_repository(self, relpath, shared=False, format=None):
91
        made_control = self.make_bzrdir(relpath, format=format)
92
        return made_control.create_repository(shared=shared)
93
94
    def create_tree_with_merge(self):
95
        """Create a branch with a simple ancestry.
96
97
        The graph should look like:
98
            digraph H {
99
                "rev-1" -> "rev-2" -> "rev-3";
100
                "rev-1" -> "rev-1.1.1" -> "rev-3";
101
            }
102
103
        Or in ASCII:
2418.5.14 by John Arbash Meinel
clean up ASCII revision graph art.
104
            1
105
            |\
106
            2 1.1.1
107
            |/
108
            3
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
109
        """
110
        tree = self.make_branch_and_memory_tree('tree')
111
        tree.lock_write()
112
        try:
113
            tree.add('')
114
            tree.commit('first', rev_id='rev-1')
2418.5.3 by John Arbash Meinel
Use a more straightforward implementation of generating 'tree_with_merge'
115
            tree.commit('second', rev_id='rev-1.1.1')
2418.5.10 by John Arbash Meinel
fix typo
116
            # 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
117
            tree.branch.set_last_revision_info(1, 'rev-1')
118
            tree.set_parent_ids(['rev-1'])
2418.5.3 by John Arbash Meinel
Use a more straightforward implementation of generating 'tree_with_merge'
119
            tree.commit('alt-second', rev_id='rev-2')
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
120
            tree.set_parent_ids(['rev-2', 'rev-1.1.1'])
121
            tree.commit('third', rev_id='rev-3')
122
        finally:
123
            tree.unlock()
124
125
        return tree
1534.4.23 by Robert Collins
Move branch implementations tests into a package.
126
1534.4.24 by Robert Collins
update (C) on branch_implementations/__init__.py
127
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
128
def branch_scenarios():
129
    """ """
130
    # Generate a list of branch formats and their associated bzrdir formats to
131
    # use.
132
    combinations = [(format, format._matchingbzrdir) for format in
5662.2.2 by Jelmer Vernooij
Move most format registration functions to BranchFormatRegistry.
133
         format_registry._get_all()]
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
134
    scenarios = make_scenarios(
135
        # None here will cause the default vfs transport server to be used.
136
        None,
137
        # None here will cause a readonly decorator to be created
138
        # by the TestCaseWithTransport.get_readonly_transport method.
139
        None,
140
        combinations)
141
    # Add RemoteBranch tests, which need a special server.
142
    remote_branch_format = RemoteBranchFormat()
143
    scenarios.extend(make_scenarios(
5017.3.24 by Vincent Ladeuil
selftest -s bt.test_selftest passing
144
        test_server.SmartTCPServer_for_testing,
145
        test_server.ReadonlySmartTCPServer_for_testing,
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
146
        [(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.
147
        memory.MemoryServer,
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
148
        name_suffix='-default'))
149
    # Also add tests for RemoteBranch with HPSS protocol v2 (i.e. bzr <1.6)
150
    # server.
151
    scenarios.extend(make_scenarios(
5017.3.24 by Vincent Ladeuil
selftest -s bt.test_selftest passing
152
        test_server.SmartTCPServer_for_testing_v2_only,
153
        test_server.ReadonlySmartTCPServer_for_testing_v2_only,
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
154
        [(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.
155
        memory.MemoryServer,
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
156
        name_suffix='-v2'))
157
    return scenarios
158
159
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
160
def load_tests(standard_tests, module, loader):
4523.1.5 by Vincent Ladeuil
Fixed as asked in review.
161
    per_branch_mod_names = [
162
        'bound_sftp',
163
        'branch',
164
        'break_lock',
165
        'check',
5227.1.1 by Andrew Bennetts
Add failing test for bug 430382.
166
        'config',
4523.1.5 by Vincent Ladeuil
Fixed as asked in review.
167
        'create_checkout',
168
        'create_clone',
169
        'commit',
170
        'dotted_revno_to_revision_id',
171
        'get_revision_id_to_revno_map',
172
        'hooks',
173
        'http',
174
        'iter_merge_sorted_revisions',
175
        'last_revision_info',
176
        'locking',
177
        'parent',
178
        'permissions',
179
        'pull',
180
        'push',
181
        'reconcile',
182
        'revision_history',
183
        'revision_id_to_dotted_revno',
184
        'revision_id_to_revno',
185
        'sprout',
186
        'stacking',
187
        'tags',
188
        'uncommit',
189
        'update',
1534.4.23 by Robert Collins
Move branch implementations tests into a package.
190
        ]
4523.1.5 by Vincent Ladeuil
Fixed as asked in review.
191
    sub_tests = loader.loadTestsFromModuleNames(
192
        ['bzrlib.tests.per_branch.test_' + name
193
         for name in per_branch_mod_names])
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
194
    return tests.multiply_tests(sub_tests, branch_scenarios(), standard_tests)