~bzr-pqm/bzr/bzr.dev

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