/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) 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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
28
from breezy 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
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
31
from breezy.branch import (
7143.15.2 by Jelmer Vernooij
Run autopep8.
32
    GenericInterBranch,
33
    InterBranch,
34
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
35
from breezy.tests import (
4211.1.6 by Jelmer Vernooij
Review from Ian.
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__,
7143.15.2 by Jelmer Vernooij
Run autopep8.
50
                           branch_format_from.__class__.__name__,
51
                           branch_format_to.__class__.__name__)
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
52
        scenario = (id,
7143.15.2 by Jelmer Vernooij
Run autopep8.
53
                    {
54
                        "branch_format_from": branch_format_from,
55
                        "interbranch_class": interbranch_class,
56
                        "branch_format_to": branch_format_to,
57
                        })
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
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.
7490.64.2 by Jelmer Vernooij
Fix optimiser iteration.
67
    for optimiser_class in InterBranch.iter_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 \
7143.15.2 by Jelmer Vernooij
Run autopep8.
69
                optimiser_class._get_branch_formats_to_test():
5297.2.1 by Robert Collins
``bzrlib.branch.InterBranch._get_branch_formats_to_test`` now returns
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):
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
79
        return self.make_branch(relpath, format=self.branch_format_from._matchingcontroldir)
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(
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
84
            self.branch_format_from._matchingcontroldir.get_branch_format(),
6162.5.6 by Jelmer Vernooij
double-check formats of created branches.
85
            self.branch_format_from)
6162.5.4 by Jelmer Vernooij
Simplify a couple of methods.
86
        return self.make_branch_and_memory_tree(
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
87
            relpath, format=self.branch_format_from._matchingcontroldir)
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(
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
92
            self.branch_format_from._matchingcontroldir.get_branch_format(),
6162.5.6 by Jelmer Vernooij
double-check formats of created branches.
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,
7143.15.2 by Jelmer Vernooij
Run autopep8.
95
                                         format=self.branch_format_from._matchingcontroldir)
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(
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
99
            self.branch_format_from._matchingcontroldir.get_branch_format(),
6162.5.6 by Jelmer Vernooij
double-check formats of created branches.
100
            self.branch_format_from)
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
101
        return branchbuilder.BranchBuilder(self.get_transport(relpath),
7143.15.2 by Jelmer Vernooij
Run autopep8.
102
                                           format=self.branch_format_from._matchingcontroldir)
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(
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
106
            self.branch_format_to._matchingcontroldir.get_branch_format(),
6162.5.6 by Jelmer Vernooij
double-check formats of created branches.
107
            self.branch_format_to)
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
108
        return self.make_branch(relpath, format=self.branch_format_to._matchingcontroldir)
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(
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
113
            self.branch_format_to._matchingcontroldir.get_branch_format(),
6162.5.6 by Jelmer Vernooij
double-check formats of created branches.
114
            self.branch_format_to)
6162.5.4 by Jelmer Vernooij
Simplify a couple of methods.
115
        return self.make_branch_and_memory_tree(
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
116
            relpath, format=self.branch_format_to._matchingcontroldir)
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(
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
121
            self.branch_format_to._matchingcontroldir.get_branch_format(),
6162.5.6 by Jelmer Vernooij
double-check formats of created branches.
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,
7143.15.2 by Jelmer Vernooij
Run autopep8.
124
                                         format=self.branch_format_to._matchingcontroldir)
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:
7143.15.2 by Jelmer Vernooij
Run autopep8.
130
            newbranch = self.make_branch(to_url + ".branch", format=format)
6162.5.4 by Jelmer Vernooij
Simplify a couple of methods.
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:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
135
            wt = newbranch.controldir.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."""
7143.15.2 by Jelmer Vernooij
Run autopep8.
142
        wt = self._sprout(
143
            origdir, to_url, self.branch_format_to._matchingcontroldir)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
144
        self.assertEqual(wt.branch._format, self.branch_format_to)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
145
        return wt.controldir
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
146
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
147
    def sprout_from(self, origdir, to_url):
148
        """Sprout a bzrdir, using from_format for the new bzrdir."""
6162.5.6 by Jelmer Vernooij
double-check formats of created branches.
149
        wt = self._sprout(origdir, to_url,
7143.15.2 by Jelmer Vernooij
Run autopep8.
150
                          self.branch_format_from._matchingcontroldir)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
151
        self.assertEqual(wt.branch._format, self.branch_format_from)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
152
        return wt.controldir
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
153
154
5284.4.2 by Robert Collins
* ``Branch.copy_content_into`` is now a convenience method dispatching to
155
class StubWithFormat(object):
156
    """A stub object used to check that convenience methods call Inter's."""
157
158
    _format = object()
159
160
161
class StubMatchingInter(object):
162
    """An inter for tests.
163
164
    This is not a subclass of InterBranch so that missing methods are caught
165
    and added rather than actually trying to do something.
166
    """
167
168
    _uses = []
169
170
    def __init__(self, source, target):
171
        self.source = source
172
        self.target = target
173
174
    @classmethod
175
    def is_compatible(klass, source, target):
176
        return StubWithFormat._format in (source._format, target._format)
177
178
    def copy_content_into(self, *args, **kwargs):
179
        self.__class__._uses.append(
180
            (self, 'copy_content_into', args, kwargs))
181
182
6625.1.5 by Martin
Drop custom load_tests implementation and use unittest signature
183
def load_tests(loader, standard_tests, pattern):
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
184
    submod_tests = loader.loadTestsFromModuleNames([
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
185
        'breezy.tests.per_interbranch.test_fetch',
186
        'breezy.tests.per_interbranch.test_get',
187
        'breezy.tests.per_interbranch.test_copy_content_into',
188
        'breezy.tests.per_interbranch.test_pull',
189
        'breezy.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.
190
        ])
191
    scenarios = make_scenarios(default_test_list())
192
    return multiply_tests(submod_tests, scenarios, standard_tests)