~bzr-pqm/bzr/bzr.dev

6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2009, 2010, 2011, 2016 Canonical Ltd
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
2
# -*- coding: utf-8 -*-
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
17
18
19
"""InterBranch implementation tests for bzr.
20
21
These test the conformance of all the interbranch variations to the
22
expected API including generally applicable corner cases.
4000.5.8 by Jelmer Vernooij
Fix whitespace.
23
Specific tests for individual formats are in the tests for the formats
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
24
itself rather than in tests/per_interbranch/*.py.
25
"""
26
27
4000.5.11 by Jelmer Vernooij
Improve tests for InterBranch.pull.
28
from bzrlib import (
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
29
    branchbuilder,
4000.5.11 by Jelmer Vernooij
Improve tests for InterBranch.pull.
30
    )
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
31
from bzrlib.branch import (
32
                           GenericInterBranch,
33
                           InterBranch,
34
                           )
4211.1.6 by Jelmer Vernooij
Review from Ian.
35
from bzrlib.tests import (
36
    TestCaseWithTransport,
37
    multiply_tests,
38
    )
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
39
40
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
41
def make_scenarios(test_list):
42
    """Transform the input test list to a list of scenarios.
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
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 tuples:
45
        (interbranch_class, branch_format_from, branch_format_to).
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
46
    """
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
47
    result = []
48
    for interbranch_class, branch_format_from, branch_format_to in test_list:
49
        id = '%s,%s,%s' % (interbranch_class.__name__,
50
                            branch_format_from.__class__.__name__,
51
                            branch_format_to.__class__.__name__)
52
        scenario = (id,
53
            {
54
             "branch_format_from": branch_format_from,
55
             "interbranch_class": interbranch_class,
56
             "branch_format_to": branch_format_to,
57
             })
58
        result.append(scenario)
59
    return result
60
61
62
def default_test_list():
63
    """Generate the default list of interbranch permutations to test."""
64
    result = []
65
    # test the default InterBranch between format 6 and the current
66
    # default format.
67
    for optimiser_class in InterBranch._optimisers:
5297.2.1 by Robert Collins
``bzrlib.branch.InterBranch._get_branch_formats_to_test`` now returns
68
        for format_from_test, format_to_test in \
69
            optimiser_class._get_branch_formats_to_test():
70
            result.append((optimiser_class, format_from_test, format_to_test))
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
71
    # if there are specific combinations we want to use, we can add them
72
    # here.
73
    return result
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
74
75
4216.7.1 by Jelmer Vernooij
Simplify interbranch test base class.
76
class TestCaseWithInterBranch(TestCaseWithTransport):
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
77
4216.7.1 by Jelmer Vernooij
Simplify interbranch test base class.
78
    def make_from_branch(self, relpath):
6162.5.4 by Jelmer Vernooij
Simplify a couple of methods.
79
        return self.make_branch(relpath, format=self.branch_format_from._matchingbzrdir)
4216.7.1 by Jelmer Vernooij
Simplify interbranch test base class.
80
81
    def make_from_branch_and_memory_tree(self, relpath):
82
        """Create a branch on the default transport and a MemoryTree for it."""
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
83
        self.assertEqual(
6162.5.6 by Jelmer Vernooij
double-check formats of created branches.
84
            self.branch_format_from._matchingbzrdir.get_branch_format(),
85
            self.branch_format_from)
6162.5.4 by Jelmer Vernooij
Simplify a couple of methods.
86
        return self.make_branch_and_memory_tree(
87
            relpath, format=self.branch_format_from._matchingbzrdir)
4216.7.1 by Jelmer Vernooij
Simplify interbranch test base class.
88
89
    def make_from_branch_and_tree(self, relpath):
90
        """Create a branch on the default transport and a working tree for it."""
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
91
        self.assertEqual(
6162.5.6 by Jelmer Vernooij
double-check formats of created branches.
92
            self.branch_format_from._matchingbzrdir.get_branch_format(),
93
            self.branch_format_from)
6127.1.9 by Jelmer Vernooij
Add lightweight option to _get_checkout_format().
94
        return self.make_branch_and_tree(relpath,
95
            format=self.branch_format_from._matchingbzrdir)
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
96
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
97
    def make_from_branch_builder(self, relpath):
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
98
        self.assertEqual(
6162.5.6 by Jelmer Vernooij
double-check formats of created branches.
99
            self.branch_format_from._matchingbzrdir.get_branch_format(),
100
            self.branch_format_from)
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
101
        return branchbuilder.BranchBuilder(self.get_transport(relpath),
6162.3.2 by Jelmer Vernooij
Add WorkingTreeFormat.get_controldir_for_branch().
102
            format=self.branch_format_from._matchingbzrdir)
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
103
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
104
    def make_to_branch(self, relpath):
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
105
        self.assertEqual(
6162.5.6 by Jelmer Vernooij
double-check formats of created branches.
106
            self.branch_format_to._matchingbzrdir.get_branch_format(),
107
            self.branch_format_to)
6162.5.4 by Jelmer Vernooij
Simplify a couple of methods.
108
        return self.make_branch(relpath, format=self.branch_format_to._matchingbzrdir)
4000.5.11 by Jelmer Vernooij
Improve tests for InterBranch.pull.
109
110
    def make_to_branch_and_memory_tree(self, relpath):
111
        """Create a branch on the default transport and a MemoryTree for it."""
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
112
        self.assertEqual(
6162.5.6 by Jelmer Vernooij
double-check formats of created branches.
113
            self.branch_format_to._matchingbzrdir.get_branch_format(),
114
            self.branch_format_to)
6162.5.4 by Jelmer Vernooij
Simplify a couple of methods.
115
        return self.make_branch_and_memory_tree(
116
            relpath, format=self.branch_format_to._matchingbzrdir)
4000.5.11 by Jelmer Vernooij
Improve tests for InterBranch.pull.
117
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
118
    def make_to_branch_and_tree(self, relpath):
119
        """Create a branch on the default transport and a working tree for it."""
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
120
        self.assertEqual(
6162.5.6 by Jelmer Vernooij
double-check formats of created branches.
121
            self.branch_format_to._matchingbzrdir.get_branch_format(),
122
            self.branch_format_to)
6127.1.9 by Jelmer Vernooij
Add lightweight option to _get_checkout_format().
123
        return self.make_branch_and_tree(relpath,
124
            format=self.branch_format_to._matchingbzrdir)
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
125
6162.5.5 by Jelmer Vernooij
Review feedback from John.
126
    def _sprout(self, origdir, to_url, format):
127
        if format.supports_workingtrees:
128
            newbranch = self.make_branch(to_url, format=format)
129
        else:
6162.5.4 by Jelmer Vernooij
Simplify a couple of methods.
130
            newbranch = self.make_branch(to_url+".branch", format=format)
131
        origbranch = origdir.open_branch()
132
        newbranch.repository.fetch(origbranch.repository)
133
        origbranch.copy_content_into(newbranch)
6162.5.5 by Jelmer Vernooij
Review feedback from John.
134
        if format.supports_workingtrees:
135
            wt = newbranch.bzrdir.create_workingtree()
6162.5.4 by Jelmer Vernooij
Simplify a couple of methods.
136
        else:
6162.5.5 by Jelmer Vernooij
Review feedback from John.
137
            wt = newbranch.create_checkout(to_url, lightweight=True)
6162.5.6 by Jelmer Vernooij
double-check formats of created branches.
138
        return wt
6162.5.4 by Jelmer Vernooij
Simplify a couple of methods.
139
4000.5.11 by Jelmer Vernooij
Improve tests for InterBranch.pull.
140
    def sprout_to(self, origdir, to_url):
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
141
        """Sprout a bzrdir, using to_format for the new branch."""
6162.5.6 by Jelmer Vernooij
double-check formats of created branches.
142
        wt = self._sprout(origdir, to_url, self.branch_format_to._matchingbzrdir)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
143
        self.assertEqual(wt.branch._format, self.branch_format_to)
6162.5.6 by Jelmer Vernooij
double-check formats of created branches.
144
        return wt.bzrdir
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
145
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
146
    def sprout_from(self, origdir, to_url):
147
        """Sprout a bzrdir, using from_format for the new bzrdir."""
6162.5.6 by Jelmer Vernooij
double-check formats of created branches.
148
        wt = self._sprout(origdir, to_url,
6162.5.5 by Jelmer Vernooij
Review feedback from John.
149
            self.branch_format_from._matchingbzrdir)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
150
        self.assertEqual(wt.branch._format, self.branch_format_from)
6162.5.6 by Jelmer Vernooij
double-check formats of created branches.
151
        return wt.bzrdir
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
152
153
5284.4.2 by Robert Collins
* ``Branch.copy_content_into`` is now a convenience method dispatching to
154
class StubWithFormat(object):
155
    """A stub object used to check that convenience methods call Inter's."""
156
157
    _format = object()
158
159
160
class StubMatchingInter(object):
161
    """An inter for tests.
162
163
    This is not a subclass of InterBranch so that missing methods are caught
164
    and added rather than actually trying to do something.
165
    """
166
167
    _uses = []
168
169
    def __init__(self, source, target):
170
        self.source = source
171
        self.target = target
172
173
    @classmethod
174
    def is_compatible(klass, source, target):
175
        return StubWithFormat._format in (source._format, target._format)
176
177
    def copy_content_into(self, *args, **kwargs):
178
        self.__class__._uses.append(
179
            (self, 'copy_content_into', args, kwargs))
180
181
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
182
def load_tests(standard_tests, module, loader):
183
    submod_tests = loader.loadTestsFromModuleNames([
5741.1.3 by Jelmer Vernooij
Move fetch tests.
184
        'bzrlib.tests.per_interbranch.test_fetch',
5284.4.1 by Robert Collins
* Fetching was slightly confused about the best code to use and was
185
        'bzrlib.tests.per_interbranch.test_get',
5284.4.2 by Robert Collins
* ``Branch.copy_content_into`` is now a convenience method dispatching to
186
        'bzrlib.tests.per_interbranch.test_copy_content_into',
4000.5.11 by Jelmer Vernooij
Improve tests for InterBranch.pull.
187
        'bzrlib.tests.per_interbranch.test_pull',
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
188
        'bzrlib.tests.per_interbranch.test_push',
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
189
        ])
190
    scenarios = make_scenarios(default_test_list())
191
    return multiply_tests(submod_tests, scenarios, standard_tests)