~bzr-pqm/bzr/bzr.dev

5630.2.2 by John Arbash Meinel
Start fleshing out the design. Something weird is causing my tests to all fail.
1
# Copyright (C) 2006-2011 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
16
17
18
"""WorkingTree implementation tests for bzr.
19
5128.1.1 by Vincent Ladeuil
Uncontroversial cleanups, mostly comments
20
This test the conformance of all the workingtre variations to the expected API.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
21
Specific tests for individual formats are in the tests/test_workingtree file
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
22
rather than in tests/per_workingtree/*.py.
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
23
"""
24
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
25
from bzrlib import (
5409.1.2 by Vincent Ladeuil
Make make_branch_builder available to all per_workingtree tests.
26
    branchbuilder,
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
27
    tests,
6437.70.1 by John Arbash Meinel
Set up the infrastructure to start testing a lightweight checkout of a remote repository.
28
    transport,
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
29
    workingtree,
30
    )
6437.70.1 by John Arbash Meinel
Set up the infrastructure to start testing a lightweight checkout of a remote repository.
31
from bzrlib.transport import memory
32
from bzrlib.tests import (
33
    per_controldir,
34
    test_server,
35
    )
1534.5.5 by Robert Collins
Move is_control_file into WorkingTree.is_control_filename and test.
36
37
6437.70.16 by John Arbash Meinel
per_tree re-uses the per_workingtree scenarios.
38
def make_scenarios(transport_server, transport_readonly_server, formats,
39
                   remote_server=None, remote_readonly_server=None,
40
                   remote_backing_server=None):
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
41
    result = []
42
    for workingtree_format in formats:
43
        result.append((workingtree_format.__class__.__name__,
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
44
                       make_scenario(transport_server,
45
                                     transport_readonly_server,
46
                                     workingtree_format)))
6437.70.1 by John Arbash Meinel
Set up the infrastructure to start testing a lightweight checkout of a remote repository.
47
    default_wt_format = workingtree.format_registry.get_default()
6437.70.16 by John Arbash Meinel
per_tree re-uses the per_workingtree scenarios.
48
    if remote_server is None:
49
        remote_server = test_server.SmartTCPServer_for_testing
50
    if remote_readonly_server is None:
51
        remote_readonly_server = test_server.ReadonlySmartTCPServer_for_testing
52
    if remote_backing_server is None:
53
        remote_backing_server = memory.MemoryServer
54
    scenario = make_scenario(remote_server, remote_readonly_server,
55
                             default_wt_format)
6437.70.1 by John Arbash Meinel
Set up the infrastructure to start testing a lightweight checkout of a remote repository.
56
    scenario['repo_is_remote'] = True;
6437.70.16 by John Arbash Meinel
per_tree re-uses the per_workingtree scenarios.
57
    scenario['vfs_transport_factory'] = remote_backing_server
6437.70.1 by John Arbash Meinel
Set up the infrastructure to start testing a lightweight checkout of a remote repository.
58
    result.append((default_wt_format.__class__.__name__ + ',remote', scenario))
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
59
    return result
60
61
62
def make_scenario(transport_server, transport_readonly_server,
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
63
                  workingtree_format):
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
64
    return {
65
        "transport_server": transport_server,
66
        "transport_readonly_server": transport_readonly_server,
67
        "bzrdir_format": workingtree_format._matchingbzrdir,
68
        "workingtree_format": workingtree_format,
69
        }
3363.1.1 by Aaron Bentley
Refactor intertree scenario creation
70
2553.2.10 by Robert Collins
And overhaul WorkingTreeTestProviderAdapter too.
71
5865.2.1 by Vincent Ladeuil
Add an helper for per_workingtree scenarios that plugins can reuse
72
def wt_scenarios():
73
    """Returns the scenarios for all registered working trees.
74
75
    This can used by plugins that want to define tests against these working
76
    trees.
77
    """
78
    scenarios = make_scenarios(
79
        tests.default_transport,
80
        # None here will cause a readonly decorator to be created
81
        # by the TestCaseWithTransport.get_readonly_transport method.
82
        None,
83
        workingtree.format_registry._get_all()
84
        )
85
    return scenarios
86
87
5363.2.18 by Jelmer Vernooij
Rename TestCaseWithBzrDir -> TestCaseWithControlDir.
88
class TestCaseWithWorkingTree(per_controldir.TestCaseWithControlDir):
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
89
90
    def make_branch_and_tree(self, relpath, format=None):
91
        made_control = self.make_bzrdir(relpath, format=format)
1534.5.5 by Robert Collins
Move is_control_file into WorkingTree.is_control_filename and test.
92
        made_control.create_repository()
6437.70.1 by John Arbash Meinel
Set up the infrastructure to start testing a lightweight checkout of a remote repository.
93
        b = made_control.create_branch()
6437.70.17 by John Arbash Meinel
Change the attribute lookup, I missed it in the first pass.
94
        if getattr(self, 'repo_is_remote', False):
6437.70.1 by John Arbash Meinel
Set up the infrastructure to start testing a lightweight checkout of a remote repository.
95
            # If the repo is remote, then we just create a local lightweight
96
            # checkout
97
            # XXX: This duplicates a lot of Branch.create_checkout, but we know
98
            #      we want a) lightweight, and b) a specific WT format. We also
99
            #      know that nothing should already exist, etc.
100
            t = transport.get_transport(relpath)
101
            t.ensure_base()
102
            bzrdir_format = self.workingtree_format.get_controldir_for_branch()
103
            wt_dir = bzrdir_format.initialize_on_transport(t)
104
            branch_ref = wt_dir.set_branch_reference(b)
105
            wt = wt_dir.create_workingtree(None, from_branch=branch_ref)
106
        else:
107
            wt = self.workingtree_format.initialize(made_control)
108
        return wt
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
109
5409.1.2 by Vincent Ladeuil
Make make_branch_builder available to all per_workingtree tests.
110
    def make_branch_builder(self, relpath, format=None):
111
        if format is None:
6162.3.2 by Jelmer Vernooij
Add WorkingTreeFormat.get_controldir_for_branch().
112
            format = self.workingtree_format.get_controldir_for_branch()
5516.1.1 by Vincent Ladeuil
TestCaseWithWorkingTree.make_branch_builder respects its relpath parameter.
113
        builder = branchbuilder.BranchBuilder(self.get_transport(relpath),
5409.1.2 by Vincent Ladeuil
Make make_branch_builder available to all per_workingtree tests.
114
                                              format=format)
115
        return builder
116
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
117
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
118
def load_tests(standard_tests, module, loader):
4332.3.2 by Robert Collins
Extract repository access in WorkingTree._check to be data driven, adding a new _get_check_refs method to support this.
119
    test_names = [
120
        'add_reference',
121
        'add',
4523.1.5 by Vincent Ladeuil
Fixed as asked in review.
122
        'annotate_iter',
4332.3.2 by Robert Collins
Extract repository access in WorkingTree._check to be data driven, adding a new _get_check_refs method to support this.
123
        'basis_inventory',
124
        'basis_tree',
125
        'break_lock',
126
        'changes_from',
127
        'check',
5630.2.2 by John Arbash Meinel
Start fleshing out the design. Something weird is causing my tests to all fail.
128
        'check_state',
4332.3.2 by Robert Collins
Extract repository access in WorkingTree._check to be data driven, adding a new _get_check_refs method to support this.
129
        'content_filters',
130
        'commit',
131
        'eol_conversion',
132
        'executable',
133
        'flush',
134
        'get_file_mtime',
135
        'get_parent_ids',
136
        'inv',
137
        'is_control_filename',
138
        'is_ignored',
139
        'locking',
140
        'merge_from_branch',
141
        'mkdir',
142
        'move',
143
        'nested_specifics',
144
        'parents',
145
        'paths2ids',
146
        'pull',
147
        'put_file',
148
        'readonly',
149
        'read_working_inventory',
150
        'remove',
151
        'rename_one',
152
        'revision_tree',
153
        'set_root_id',
154
        'smart_add',
4634.157.4 by Martin Pool
Add a basic (already passing) test for smart_add of a symlink
155
        'symlinks',
4332.3.2 by Robert Collins
Extract repository access in WorkingTree._check to be data driven, adding a new _get_check_refs method to support this.
156
        'uncommit',
157
        'unversion',
158
        'views',
159
        'walkdirs',
160
        'workingtree',
161
        ]
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
162
    test_workingtree_implementations = [
4332.3.32 by Robert Collins
Merge bzr.dev.
163
        'bzrlib.tests.per_workingtree.test_' + name for
4332.3.2 by Robert Collins
Extract repository access in WorkingTree._check to be data driven, adding a new _get_check_refs method to support this.
164
        name in test_names]
3302.9.16 by Vincent Ladeuil
bzrlib.tests.workingtree_implementations switched from
165
5865.2.1 by Vincent Ladeuil
Add an helper for per_workingtree scenarios that plugins can reuse
166
    scenarios = wt_scenarios()
3302.9.16 by Vincent Ladeuil
bzrlib.tests.workingtree_implementations switched from
167
3302.9.27 by Vincent Ladeuil
Fixed as per Ian's review.
168
    # add the tests for the sub modules
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
169
    return tests.multiply_tests(
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
170
        loader.loadTestsFromModuleNames(test_workingtree_implementations),
171
        scenarios, standard_tests)
5865.2.2 by Vincent Ladeuil
Add a smoke test to avoid accidental deletion of the helper in the future.
172
173
174
class TestWtScenarios(tests.TestCase):
175
176
    def test_protect_wt_scenarios(self):
177
        # Just make sure we don't accidentally delete the helper again
178
        scenarios = wt_scenarios()