~debian-bazaar/debian/sid/bzr/experimental

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_interbranch/__init__.py

  • Committer: Jelmer Vernooij
  • Date: 2019-02-23 22:23:54 UTC
  • Revision ID: jelmer@jelmer.uk-20190223222354-np2qpunfi10llrex
Add transitional packages to brz.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010, 2011, 2016 Canonical Ltd
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
16
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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.
23
 
Specific tests for individual formats are in the tests for the formats
24
 
itself rather than in tests/per_interbranch/*.py.
25
 
"""
26
 
 
27
 
 
28
 
from bzrlib import (
29
 
    branchbuilder,
30
 
    )
31
 
from bzrlib.branch import (
32
 
                           GenericInterBranch,
33
 
                           InterBranch,
34
 
                           )
35
 
from bzrlib.tests import (
36
 
    TestCaseWithTransport,
37
 
    multiply_tests,
38
 
    )
39
 
 
40
 
 
41
 
def make_scenarios(test_list):
42
 
    """Transform the input test list to a list of scenarios.
43
 
 
44
 
    :param formats: A list of tuples:
45
 
        (interbranch_class, branch_format_from, branch_format_to).
46
 
    """
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:
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))
71
 
    # if there are specific combinations we want to use, we can add them
72
 
    # here.
73
 
    return result
74
 
 
75
 
 
76
 
class TestCaseWithInterBranch(TestCaseWithTransport):
77
 
 
78
 
    def make_from_branch(self, relpath):
79
 
        return self.make_branch(relpath, format=self.branch_format_from._matchingbzrdir)
80
 
 
81
 
    def make_from_branch_and_memory_tree(self, relpath):
82
 
        """Create a branch on the default transport and a MemoryTree for it."""
83
 
        self.assertEqual(
84
 
            self.branch_format_from._matchingbzrdir.get_branch_format(),
85
 
            self.branch_format_from)
86
 
        return self.make_branch_and_memory_tree(
87
 
            relpath, format=self.branch_format_from._matchingbzrdir)
88
 
 
89
 
    def make_from_branch_and_tree(self, relpath):
90
 
        """Create a branch on the default transport and a working tree for it."""
91
 
        self.assertEqual(
92
 
            self.branch_format_from._matchingbzrdir.get_branch_format(),
93
 
            self.branch_format_from)
94
 
        return self.make_branch_and_tree(relpath,
95
 
            format=self.branch_format_from._matchingbzrdir)
96
 
 
97
 
    def make_from_branch_builder(self, relpath):
98
 
        self.assertEqual(
99
 
            self.branch_format_from._matchingbzrdir.get_branch_format(),
100
 
            self.branch_format_from)
101
 
        return branchbuilder.BranchBuilder(self.get_transport(relpath),
102
 
            format=self.branch_format_from._matchingbzrdir)
103
 
 
104
 
    def make_to_branch(self, relpath):
105
 
        self.assertEqual(
106
 
            self.branch_format_to._matchingbzrdir.get_branch_format(),
107
 
            self.branch_format_to)
108
 
        return self.make_branch(relpath, format=self.branch_format_to._matchingbzrdir)
109
 
 
110
 
    def make_to_branch_and_memory_tree(self, relpath):
111
 
        """Create a branch on the default transport and a MemoryTree for it."""
112
 
        self.assertEqual(
113
 
            self.branch_format_to._matchingbzrdir.get_branch_format(),
114
 
            self.branch_format_to)
115
 
        return self.make_branch_and_memory_tree(
116
 
            relpath, format=self.branch_format_to._matchingbzrdir)
117
 
 
118
 
    def make_to_branch_and_tree(self, relpath):
119
 
        """Create a branch on the default transport and a working tree for it."""
120
 
        self.assertEqual(
121
 
            self.branch_format_to._matchingbzrdir.get_branch_format(),
122
 
            self.branch_format_to)
123
 
        return self.make_branch_and_tree(relpath,
124
 
            format=self.branch_format_to._matchingbzrdir)
125
 
 
126
 
    def _sprout(self, origdir, to_url, format):
127
 
        if format.supports_workingtrees:
128
 
            newbranch = self.make_branch(to_url, format=format)
129
 
        else:
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)
134
 
        if format.supports_workingtrees:
135
 
            wt = newbranch.bzrdir.create_workingtree()
136
 
        else:
137
 
            wt = newbranch.create_checkout(to_url, lightweight=True)
138
 
        return wt
139
 
 
140
 
    def sprout_to(self, origdir, to_url):
141
 
        """Sprout a bzrdir, using to_format for the new branch."""
142
 
        wt = self._sprout(origdir, to_url, self.branch_format_to._matchingbzrdir)
143
 
        self.assertEqual(wt.branch._format, self.branch_format_to)
144
 
        return wt.bzrdir
145
 
 
146
 
    def sprout_from(self, origdir, to_url):
147
 
        """Sprout a bzrdir, using from_format for the new bzrdir."""
148
 
        wt = self._sprout(origdir, to_url,
149
 
            self.branch_format_from._matchingbzrdir)
150
 
        self.assertEqual(wt.branch._format, self.branch_format_from)
151
 
        return wt.bzrdir
152
 
 
153
 
 
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
 
 
182
 
def load_tests(standard_tests, module, loader):
183
 
    submod_tests = loader.loadTestsFromModuleNames([
184
 
        'bzrlib.tests.per_interbranch.test_fetch',
185
 
        'bzrlib.tests.per_interbranch.test_get',
186
 
        'bzrlib.tests.per_interbranch.test_copy_content_into',
187
 
        'bzrlib.tests.per_interbranch.test_pull',
188
 
        'bzrlib.tests.per_interbranch.test_push',
189
 
        ])
190
 
    scenarios = make_scenarios(default_test_list())
191
 
    return multiply_tests(submod_tests, scenarios, standard_tests)