/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
27
from breezy import (
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
28
    errors,
29
    tests,
30
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
31
from breezy.branch import format_registry
6670.4.14 by Jelmer Vernooij
Move remote to breezy.bzr.
32
from breezy.bzr.remote import RemoteBranchFormat
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
33
from breezy.tests import test_server
34
from breezy.tests.per_controldir.test_controldir import TestCaseWithControlDir
35
from breezy.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,
7143.15.2 by Jelmer Vernooij
Run autopep8.
39
                   formats, vfs_transport_factory=None, name_suffix=''):
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
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__',
7143.15.2 by Jelmer Vernooij
Run autopep8.
49
                                branch_format.__class__.__name__)
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
50
        scenario_name += name_suffix
51
        scenario = (scenario_name, {
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
52
            "transport_server": transport_server,
53
            "transport_readonly_server": transport_readonly_server,
54
            "bzrdir_format": bzrdir_format,
55
            "branch_format": branch_format,
7143.15.2 by Jelmer Vernooij
Run autopep8.
56
            })
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
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 {
6747.4.2 by Jelmer Vernooij
Avoid setting revision ids in a few more places.
89
                "1" -> "2" -> "3";
90
                "1" -> "1.1.1" -> "3";
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
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
        """
6747.4.2 by Jelmer Vernooij
Avoid setting revision ids in a few more places.
100
        revmap = {}
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
101
        tree = self.make_branch_and_memory_tree('tree')
6973.10.6 by Jelmer Vernooij
Fix tests.
102
        with tree.lock_write():
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
103
            tree.add('')
6747.4.2 by Jelmer Vernooij
Avoid setting revision ids in a few more places.
104
            revmap['1'] = tree.commit('first')
105
            revmap['1.1.1'] = tree.commit('second')
2418.5.10 by John Arbash Meinel
fix typo
106
            # Uncommit that last commit and switch to the other line
6747.4.2 by Jelmer Vernooij
Avoid setting revision ids in a few more places.
107
            tree.branch.set_last_revision_info(1, revmap['1'])
108
            tree.set_parent_ids([revmap['1']])
109
            revmap['2'] = tree.commit('alt-second')
110
            tree.set_parent_ids([revmap['2'], revmap['1.1.1']])
111
            revmap['3'] = tree.commit('third')
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
112
6747.4.2 by Jelmer Vernooij
Avoid setting revision ids in a few more places.
113
        return tree, revmap
1534.4.23 by Robert Collins
Move branch implementations tests into a package.
114
1534.4.24 by Robert Collins
update (C) on branch_implementations/__init__.py
115
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
116
def branch_scenarios():
117
    """ """
118
    # Generate a list of branch formats and their associated bzrdir formats to
119
    # use.
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
120
    combinations = [(format, format._matchingcontroldir) for format in
7143.15.2 by Jelmer Vernooij
Run autopep8.
121
                    format_registry._get_all()]
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
122
    scenarios = make_scenarios(
123
        # None here will cause the default vfs transport server to be used.
124
        None,
125
        # None here will cause a readonly decorator to be created
126
        # by the TestCaseWithTransport.get_readonly_transport method.
127
        None,
128
        combinations)
129
    # Add RemoteBranch tests, which need a special server.
130
    remote_branch_format = RemoteBranchFormat()
131
    scenarios.extend(make_scenarios(
5017.3.24 by Vincent Ladeuil
selftest -s bt.test_selftest passing
132
        test_server.SmartTCPServer_for_testing,
133
        test_server.ReadonlySmartTCPServer_for_testing,
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
134
        [(remote_branch_format, remote_branch_format._matchingcontroldir)],
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.
135
        memory.MemoryServer,
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
136
        name_suffix='-default'))
137
    # Also add tests for RemoteBranch with HPSS protocol v2 (i.e. bzr <1.6)
138
    # server.
139
    scenarios.extend(make_scenarios(
5017.3.24 by Vincent Ladeuil
selftest -s bt.test_selftest passing
140
        test_server.SmartTCPServer_for_testing_v2_only,
141
        test_server.ReadonlySmartTCPServer_for_testing_v2_only,
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
142
        [(remote_branch_format, remote_branch_format._matchingcontroldir)],
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.
143
        memory.MemoryServer,
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
144
        name_suffix='-v2'))
145
    return scenarios
146
147
6625.1.5 by Martin
Drop custom load_tests implementation and use unittest signature
148
def load_tests(loader, standard_tests, pattern):
4523.1.5 by Vincent Ladeuil
Fixed as asked in review.
149
    per_branch_mod_names = [
150
        'branch',
151
        'break_lock',
152
        'check',
5227.1.1 by Andrew Bennetts
Add failing test for bug 430382.
153
        'config',
4523.1.5 by Vincent Ladeuil
Fixed as asked in review.
154
        'create_checkout',
155
        'create_clone',
156
        'commit',
157
        'dotted_revno_to_revision_id',
7290.19.1 by Jelmer Vernooij
Add tests for get_rev_id and get_rev_id_for_revno.
158
        'get_rev_id',
4523.1.5 by Vincent Ladeuil
Fixed as asked in review.
159
        'get_revision_id_to_revno_map',
160
        'hooks',
161
        'http',
162
        'iter_merge_sorted_revisions',
163
        'last_revision_info',
164
        'locking',
165
        'parent',
166
        'permissions',
167
        'pull',
168
        'push',
169
        'reconcile',
170
        'revision_id_to_dotted_revno',
171
        'revision_id_to_revno',
172
        'sprout',
173
        'stacking',
174
        'tags',
175
        'uncommit',
176
        'update',
1534.4.23 by Robert Collins
Move branch implementations tests into a package.
177
        ]
4523.1.5 by Vincent Ladeuil
Fixed as asked in review.
178
    sub_tests = loader.loadTestsFromModuleNames(
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
179
        ['breezy.tests.per_branch.test_' + name
4523.1.5 by Vincent Ladeuil
Fixed as asked in review.
180
         for name in per_branch_mod_names])
4108.2.1 by Michael Hudson
Factor branch scenario generation out of branch test loading.
181
    return tests.multiply_tests(sub_tests, branch_scenarios(), standard_tests)