~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
23
23
"""
24
24
 
25
25
from bzrlib import (
26
 
    errors,
 
26
    branchbuilder,
27
27
    tests,
 
28
    transport,
28
29
    workingtree,
29
30
    )
30
 
from bzrlib.tests import per_controldir
31
 
 
32
 
 
33
 
def make_scenarios(transport_server, transport_readonly_server, formats):
 
31
from bzrlib.transport import memory
 
32
from bzrlib.tests import (
 
33
    per_controldir,
 
34
    test_server,
 
35
    )
 
36
 
 
37
 
 
38
def make_scenarios(transport_server, transport_readonly_server, formats,
 
39
                   remote_server=None, remote_readonly_server=None,
 
40
                   remote_backing_server=None):
34
41
    result = []
35
42
    for workingtree_format in formats:
36
43
        result.append((workingtree_format.__class__.__name__,
37
44
                       make_scenario(transport_server,
38
45
                                     transport_readonly_server,
39
46
                                     workingtree_format)))
 
47
    default_wt_format = workingtree.format_registry.get_default()
 
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)
 
56
    scenario['repo_is_remote'] = True;
 
57
    scenario['vfs_transport_factory'] = remote_backing_server
 
58
    result.append((default_wt_format.__class__.__name__ + ',remote', scenario))
40
59
    return result
41
60
 
42
61
 
50
69
        }
51
70
 
52
71
 
 
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
 
53
88
class TestCaseWithWorkingTree(per_controldir.TestCaseWithControlDir):
54
89
 
55
90
    def make_branch_and_tree(self, relpath, format=None):
56
91
        made_control = self.make_bzrdir(relpath, format=format)
57
92
        made_control.create_repository()
58
 
        made_control.create_branch()
59
 
        return self.workingtree_format.initialize(made_control)
60
 
 
61
 
 
62
 
def workingtree_formats():
63
 
    """The known working tree formats."""
64
 
    return (workingtree.WorkingTreeFormat._formats.values() +
65
 
        workingtree._legacy_formats)
 
93
        b = made_control.create_branch()
 
94
        if getattr(self, 'repo_is_remote', False):
 
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
 
109
 
 
110
    def make_branch_builder(self, relpath, format=None):
 
111
        if format is None:
 
112
            format = self.workingtree_format.get_controldir_for_branch()
 
113
        builder = branchbuilder.BranchBuilder(self.get_transport(relpath),
 
114
                                              format=format)
 
115
        return builder
66
116
 
67
117
 
68
118
def load_tests(standard_tests, module, loader):
75
125
        'break_lock',
76
126
        'changes_from',
77
127
        'check',
 
128
        'check_state',
78
129
        'content_filters',
79
130
        'commit',
80
131
        'eol_conversion',
112
163
        'bzrlib.tests.per_workingtree.test_' + name for
113
164
        name in test_names]
114
165
 
115
 
    scenarios = make_scenarios(
116
 
        tests.default_transport,
117
 
        # None here will cause a readonly decorator to be created
118
 
        # by the TestCaseWithTransport.get_readonly_transport method.
119
 
        None,
120
 
        workingtree_formats()
121
 
        )
 
166
    scenarios = wt_scenarios()
122
167
 
123
168
    # add the tests for the sub modules
124
169
    return tests.multiply_tests(
125
170
        loader.loadTestsFromModuleNames(test_workingtree_implementations),
126
171
        scenarios, standard_tests)
 
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()