~bzr-pqm/bzr/bzr.dev

4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
1
# Copyright (C) 2009 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
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
    memorytree,
31
    )
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
32
from bzrlib.branch import (
33
                           GenericInterBranch,
34
                           InterBranch,
35
                           )
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
36
from bzrlib.bzrdir import (
37
    BzrDirFormat,
38
    BzrDirMetaFormat1,
39
    )
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
40
from bzrlib.errors import (
41
    FileExists,
4000.5.11 by Jelmer Vernooij
Improve tests for InterBranch.pull.
42
    NotBranchError,
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
43
    UninitializableFormat,
44
    )
4211.1.6 by Jelmer Vernooij
Review from Ian.
45
from bzrlib.tests import (
46
    TestCaseWithTransport,
47
    multiply_tests,
48
    )
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
49
from bzrlib.transport import get_transport
50
51
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
52
def make_scenarios(test_list):
53
    """Transform the input test list to a list of scenarios.
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
54
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
55
    :param formats: A list of tuples:
56
        (interbranch_class, branch_format_from, branch_format_to).
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
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 = []
59
    for interbranch_class, branch_format_from, branch_format_to in test_list:
60
        id = '%s,%s,%s' % (interbranch_class.__name__,
61
                            branch_format_from.__class__.__name__,
62
                            branch_format_to.__class__.__name__)
63
        scenario = (id,
64
            {
65
             "branch_format_from": branch_format_from,
66
             "interbranch_class": interbranch_class,
67
             "branch_format_to": branch_format_to,
68
             })
69
        result.append(scenario)
70
    return result
71
72
73
def default_test_list():
74
    """Generate the default list of interbranch permutations to test."""
75
    result = []
76
    # test the default InterBranch between format 6 and the current
77
    # default format.
78
    for optimiser_class in InterBranch._optimisers:
79
        format_from_test, format_to_test = \
80
            optimiser_class._get_branch_formats_to_test()
81
        if format_to_test is not None:
82
            result.append((optimiser_class,
83
                           format_from_test, format_to_test))
84
    # if there are specific combinations we want to use, we can add them
85
    # here.
86
    return result
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
87
88
4216.7.1 by Jelmer Vernooij
Simplify interbranch test base class.
89
class TestCaseWithInterBranch(TestCaseWithTransport):
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
90
4216.7.1 by Jelmer Vernooij
Simplify interbranch test base class.
91
    def make_from_branch(self, relpath):
92
        repo = self.make_repository(relpath)
93
        return self.branch_format_from.initialize(repo.bzrdir)
94
95
    def make_from_branch_and_memory_tree(self, relpath):
96
        """Create a branch on the default transport and a MemoryTree for it."""
97
        b = self.make_from_branch(relpath)
98
        return memorytree.MemoryTree.create_on_branch(b)
99
100
    def make_from_branch_and_tree(self, relpath):
101
        """Create a branch on the default transport and a working tree for it."""
102
        b = self.make_from_branch(relpath)
103
        return b.bzrdir.create_workingtree()
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
104
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
105
    def make_from_branch_builder(self, relpath):
106
        default_format = BzrDirFormat.get_default_format()
107
        format = BzrDirMetaFormat1()
108
        format.set_branch_format(self.branch_format_from)
109
        format.repository_format = default_format.repository_format
110
        format.workingtree_format = default_format.workingtree_format
111
        return branchbuilder.BranchBuilder(self.get_transport(relpath),
112
            format=format)
113
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
114
    def make_to_branch(self, relpath):
4216.7.1 by Jelmer Vernooij
Simplify interbranch test base class.
115
        repo = self.make_repository(relpath)
116
        return self.branch_format_to.initialize(repo.bzrdir)
4000.5.11 by Jelmer Vernooij
Improve tests for InterBranch.pull.
117
118
    def make_to_branch_and_memory_tree(self, relpath):
119
        """Create a branch on the default transport and a MemoryTree for it."""
120
        b = self.make_to_branch(relpath)
121
        return memorytree.MemoryTree.create_on_branch(b)
122
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
123
    def make_to_branch_and_tree(self, relpath):
124
        """Create a branch on the default transport and a working tree for it."""
125
        b = self.make_to_branch(relpath)
126
        return b.bzrdir.create_workingtree()
127
4000.5.11 by Jelmer Vernooij
Improve tests for InterBranch.pull.
128
    def sprout_to(self, origdir, to_url):
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
129
        """Sprout a bzrdir, using to_format for the new branch."""
4000.5.11 by Jelmer Vernooij
Improve tests for InterBranch.pull.
130
        newbranch = self.make_to_branch(to_url)
4000.5.20 by Jelmer Vernooij
Fix InterBranch.pull tests.
131
        origbranch = origdir.open_branch()
132
        newbranch.repository.fetch(origbranch.repository)
133
        origbranch.copy_content_into(newbranch)
4000.5.11 by Jelmer Vernooij
Improve tests for InterBranch.pull.
134
        newbranch.bzrdir.create_workingtree()
135
        return newbranch.bzrdir
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
136
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
137
    def sprout_from(self, origdir, to_url):
138
        """Sprout a bzrdir, using from_format for the new bzrdir."""
139
        newbranch = self.make_from_branch(to_url)
140
        origbranch = origdir.open_branch()
141
        newbranch.repository.fetch(origbranch.repository)
142
        origbranch.copy_content_into(newbranch)
143
        newbranch.bzrdir.create_workingtree()
144
        return newbranch.bzrdir
145
146
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
147
def load_tests(standard_tests, module, loader):
148
    submod_tests = loader.loadTestsFromModuleNames([
4000.5.11 by Jelmer Vernooij
Improve tests for InterBranch.pull.
149
        'bzrlib.tests.per_interbranch.test_pull',
4211.1.4 by Jelmer Vernooij
add InterBranch.push() tests.
150
        'bzrlib.tests.per_interbranch.test_push',
4000.5.3 by Jelmer Vernooij
Add tests for InterBranch.
151
        'bzrlib.tests.per_interbranch.test_update_revisions',
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
152
        ])
153
    scenarios = make_scenarios(default_test_list())
154
    return multiply_tests(submod_tests, scenarios, standard_tests)