/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.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
23
Specific tests for individual formats are in the tests/test_branch file
4523.1.1 by Martin Pool
Rename tests.branch_implementations to per_branch
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
    )
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
31
from bzrlib.branch import (BranchFormat,
32
                           _legacy_formats,
33
                           )
2418.5.11 by John Arbash Meinel
[merge] bzr.dev 2447
34
from bzrlib.remote import RemoteBranchFormat, RemoteBzrDirFormat
5017.3.24 by Vincent Ladeuil
selftest -s bt.test_selftest passing
35
from bzrlib.tests import test_server
5363.2.18 by Jelmer Vernooij
Rename TestCaseWithBzrDir -> TestCaseWithControlDir.
36
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.
37
from bzrlib.transport import memory
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
38
39
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
40
def make_scenarios(transport_server, transport_readonly_server,
41
    formats, vfs_transport_factory=None, name_suffix=''):
42
    """Transform the input formats to a list of scenarios.
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
    :param formats: A list of (branch_format, bzrdir_format).
2553.2.6 by Robert Collins
And overhaul BranchTestProviderAdapter too.
45
    """
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
46
    result = []
47
    for branch_format, bzrdir_format in formats:
48
        # some branches don't have separate format objects.
49
        # so we have a conditional here to handle them.
50
        scenario_name = getattr(branch_format, '__name__',
51
            branch_format.__class__.__name__)
52
        scenario_name += name_suffix
53
        scenario = (scenario_name, {
54
            "transport_server":transport_server,
55
            "transport_readonly_server":transport_readonly_server,
56
            "bzrdir_format":bzrdir_format,
57
            "branch_format":branch_format,
58
                })
59
        result.append(scenario)
60
    return result
2553.2.6 by Robert Collins
And overhaul BranchTestProviderAdapter too.
61
62
5363.2.18 by Jelmer Vernooij
Rename TestCaseWithBzrDir -> TestCaseWithControlDir.
63
class TestCaseWithBranch(TestCaseWithControlDir):
5128.1.1 by Vincent Ladeuil
Uncontroversial cleanups, mostly comments
64
    """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
65
66
    def setUp(self):
67
        super(TestCaseWithBranch, self).setUp()
68
        self.branch = None
69
70
    def get_branch(self):
71
        if self.branch is None:
72
            self.branch = self.make_branch('')
73
        return self.branch
74
75
    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.
76
        if format is not None:
5363.2.18 by Jelmer Vernooij
Rename TestCaseWithBzrDir -> TestCaseWithControlDir.
77
            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.
78
        repo = self.make_repository(relpath)
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
79
        # fixme RBC 20060210 this isnt necessarily a fixable thing,
80
        # Skipped is the wrong exception to raise.
81
        try:
82
            return self.branch_format.initialize(repo.bzrdir)
83
        except errors.UninitializableFormat:
84
            raise tests.TestSkipped('Uninitializable branch format')
85
3904.3.4 by Andrew Bennetts
First cut of a branch_implementations test. It fails.
86
    def make_branch_builder(self, relpath, format=None):
87
        if format is None:
88
            format = self.branch_format._matchingbzrdir
89
        return super(TestCaseWithBranch, self).make_branch_builder(
90
            relpath, format=format)
91
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
92
    def make_repository(self, relpath, shared=False, format=None):
93
        made_control = self.make_bzrdir(relpath, format=format)
94
        return made_control.create_repository(shared=shared)
95
96
    def create_tree_with_merge(self):
97
        """Create a branch with a simple ancestry.
98
99
        The graph should look like:
100
            digraph H {
101
                "rev-1" -> "rev-2" -> "rev-3";
102
                "rev-1" -> "rev-1.1.1" -> "rev-3";
103
            }
104
105
        Or in ASCII:
2418.5.14 by John Arbash Meinel
clean up ASCII revision graph art.
106
            1
107
            |\
108
            2 1.1.1
109
            |/
110
            3
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
111
        """
112
        tree = self.make_branch_and_memory_tree('tree')
113
        tree.lock_write()
114
        try:
115
            tree.add('')
116
            tree.commit('first', rev_id='rev-1')
2418.5.3 by John Arbash Meinel
Use a more straightforward implementation of generating 'tree_with_merge'
117
            tree.commit('second', rev_id='rev-1.1.1')
2418.5.10 by John Arbash Meinel
fix typo
118
            # 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
119
            tree.branch.set_last_revision_info(1, 'rev-1')
120
            tree.set_parent_ids(['rev-1'])
2418.5.3 by John Arbash Meinel
Use a more straightforward implementation of generating 'tree_with_merge'
121
            tree.commit('alt-second', rev_id='rev-2')
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
122
            tree.set_parent_ids(['rev-2', 'rev-1.1.1'])
123
            tree.commit('third', rev_id='rev-3')
124
        finally:
125
            tree.unlock()
126
127
        return tree
1534.4.23 by Robert Collins
Move branch implementations tests into a package.
128
1534.4.24 by Robert Collins
update (C) on branch_implementations/__init__.py
129
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
130
def branch_scenarios():
131
    """ """
132
    # Generate a list of branch formats and their associated bzrdir formats to
133
    # use.
134
    combinations = [(format, format._matchingbzrdir) for format in
5305.1.1 by Robert Collins
``Branch`` formats can now be loaded lazily by registering a
135
         BranchFormat.get_formats() + _legacy_formats]
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
136
    scenarios = make_scenarios(
137
        # None here will cause the default vfs transport server to be used.
138
        None,
139
        # None here will cause a readonly decorator to be created
140
        # by the TestCaseWithTransport.get_readonly_transport method.
141
        None,
142
        combinations)
143
    # Add RemoteBranch tests, which need a special server.
144
    remote_branch_format = RemoteBranchFormat()
145
    scenarios.extend(make_scenarios(
5017.3.24 by Vincent Ladeuil
selftest -s bt.test_selftest passing
146
        test_server.SmartTCPServer_for_testing,
147
        test_server.ReadonlySmartTCPServer_for_testing,
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
148
        [(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.
149
        memory.MemoryServer,
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
150
        name_suffix='-default'))
151
    # Also add tests for RemoteBranch with HPSS protocol v2 (i.e. bzr <1.6)
152
    # server.
153
    scenarios.extend(make_scenarios(
5017.3.24 by Vincent Ladeuil
selftest -s bt.test_selftest passing
154
        test_server.SmartTCPServer_for_testing_v2_only,
155
        test_server.ReadonlySmartTCPServer_for_testing_v2_only,
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
156
        [(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.
157
        memory.MemoryServer,
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
158
        name_suffix='-v2'))
159
    return scenarios
160
161
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
162
def load_tests(standard_tests, module, loader):
4523.1.5 by Vincent Ladeuil
Fixed as asked in review.
163
    per_branch_mod_names = [
164
        'bound_sftp',
165
        'branch',
166
        'break_lock',
167
        'check',
5227.1.1 by Andrew Bennetts
Add failing test for bug 430382.
168
        'config',
4523.1.5 by Vincent Ladeuil
Fixed as asked in review.
169
        'create_checkout',
170
        'create_clone',
171
        'commit',
172
        'dotted_revno_to_revision_id',
173
        'get_revision_id_to_revno_map',
174
        'hooks',
175
        'http',
176
        'iter_merge_sorted_revisions',
177
        'last_revision_info',
178
        'locking',
179
        'parent',
180
        'permissions',
181
        'pull',
182
        'push',
183
        'reconcile',
184
        'revision_history',
185
        'revision_id_to_dotted_revno',
186
        'revision_id_to_revno',
187
        'sprout',
188
        'stacking',
189
        'tags',
190
        'uncommit',
191
        'update',
1534.4.23 by Robert Collins
Move branch implementations tests into a package.
192
        ]
4523.1.5 by Vincent Ladeuil
Fixed as asked in review.
193
    sub_tests = loader.loadTestsFromModuleNames(
194
        ['bzrlib.tests.per_branch.test_' + name
195
         for name in per_branch_mod_names])
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
196
    return tests.multiply_tests(sub_tests, branch_scenarios(), standard_tests)