13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
"""WorkingTree implementation tests for bzr.
20
This test the conformance of all the workingtre variations to the expected API.
21
Specific tests for individual formats are in the tests/test_workingtree file
22
rather than in tests/per_workingtree/*.py.
20
These test the conformance of all the workingtre variations to the expected API.
21
Specific tests for individual formats are in the tests/test_workingtree file
22
rather than in tests/workingtree_implementations/*.py.
31
from bzrlib.transport import memory
25
import bzrlib.errors as errors
26
from bzrlib.transport import get_transport
32
27
from bzrlib.tests import (
38
def make_scenarios(transport_server, transport_readonly_server, formats,
39
remote_server=None, remote_readonly_server=None,
40
remote_backing_server=None):
42
for workingtree_format in formats:
43
result.append((workingtree_format.__class__.__name__,
44
make_scenario(transport_server,
45
transport_readonly_server,
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,
56
scenario['repo_is_remote'] = True;
57
scenario['vfs_transport_factory'] = remote_backing_server
58
result.append((default_wt_format.__class__.__name__ + ',remote', scenario))
62
def make_scenario(transport_server, transport_readonly_server,
65
"transport_server": transport_server,
66
"transport_readonly_server": transport_readonly_server,
67
"bzrdir_format": workingtree_format._matchingbzrdir,
68
"workingtree_format": workingtree_format,
73
"""Returns the scenarios for all registered working trees.
75
This can used by plugins that want to define tests against these working
32
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
33
from bzrlib.workingtree import (WorkingTreeFormat,
38
class WorkingTreeTestProviderAdapter(TestScenarioApplier):
39
"""A tool to generate a suite testing multiple workingtree formats at once.
41
This is done by copying the test once for each transport and injecting
42
the transport_server, transport_readonly_server, and workingtree_format
43
classes into each copy. Each copy is also given a new id() to make it
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.
83
workingtree.format_registry._get_all()
88
class TestCaseWithWorkingTree(per_controldir.TestCaseWithControlDir):
47
def __init__(self, transport_server, transport_readonly_server, formats):
48
self._transport_server = transport_server
49
self._transport_readonly_server = transport_readonly_server
50
self.scenarios = self.formats_to_scenarios(formats)
52
def formats_to_scenarios(self, formats):
53
"""Transform the input formats to a list of scenarios.
55
:param formats: A list [workingtree_format].
59
for workingtree_format in formats:
60
result.append(self.create_scenario(workingtree_format))
63
def create_scenario(self, workingtree_format):
64
"""Create a scenario for the specified converter
66
:param workingtree_format: The particular workingtree format to test.
67
:param bzrdir_format: The bzrdir format to test.
68
:return: a (name, options) tuple, where options is a dict of values
69
to be used as members of the TestCase.
72
"transport_server": self._transport_server,
73
"transport_readonly_server": self._transport_readonly_server,
74
"bzrdir_format": workingtree_format._matchingbzrdir,
75
"workingtree_format": workingtree_format,
77
return workingtree_format.__class__.__name__, scenario_options
80
class TestCaseWithWorkingTree(TestCaseWithBzrDir):
90
82
def make_branch_and_tree(self, relpath, format=None):
91
83
made_control = self.make_bzrdir(relpath, format=format)
92
84
made_control.create_repository()
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
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)
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)
107
wt = self.workingtree_format.initialize(made_control)
110
def make_branch_builder(self, relpath, format=None):
112
format = self.workingtree_format.get_controldir_for_branch()
113
builder = branchbuilder.BranchBuilder(self.get_transport(relpath),
118
def load_tests(standard_tests, module, loader):
137
'is_control_filename',
149
'read_working_inventory',
85
made_control.create_branch()
86
return self.workingtree_format.initialize(made_control)
89
def load_tests(basic_tests, module, loader):
90
result = loader.suiteClass()
91
# add the tests for this module
92
result.addTests(basic_tests)
94
test_workingtree_implementations = [
95
'bzrlib.tests.workingtree_implementations.test_add_reference',
96
'bzrlib.tests.workingtree_implementations.test_add',
97
'bzrlib.tests.workingtree_implementations.test_basis_inventory',
98
'bzrlib.tests.workingtree_implementations.test_basis_tree',
99
'bzrlib.tests.workingtree_implementations.test_break_lock',
100
'bzrlib.tests.workingtree_implementations.test_changes_from',
101
'bzrlib.tests.workingtree_implementations.test_commit',
102
'bzrlib.tests.workingtree_implementations.test_executable',
103
'bzrlib.tests.workingtree_implementations.test_flush',
104
'bzrlib.tests.workingtree_implementations.test_get_file_mtime',
105
'bzrlib.tests.workingtree_implementations.test_get_parent_ids',
106
'bzrlib.tests.workingtree_implementations.test_inv',
107
'bzrlib.tests.workingtree_implementations.test_is_control_filename',
108
'bzrlib.tests.workingtree_implementations.test_is_ignored',
109
'bzrlib.tests.workingtree_implementations.test_locking',
110
'bzrlib.tests.workingtree_implementations.test_merge_from_branch',
111
'bzrlib.tests.workingtree_implementations.test_mkdir',
112
'bzrlib.tests.workingtree_implementations.test_move',
113
'bzrlib.tests.workingtree_implementations.test_nested_specifics',
114
'bzrlib.tests.workingtree_implementations.test_parents',
115
'bzrlib.tests.workingtree_implementations.test_paths2ids',
116
'bzrlib.tests.workingtree_implementations.test_pull',
117
'bzrlib.tests.workingtree_implementations.test_put_file',
118
'bzrlib.tests.workingtree_implementations.test_readonly',
119
'bzrlib.tests.workingtree_implementations.test_read_working_inventory',
120
'bzrlib.tests.workingtree_implementations.test_remove',
121
'bzrlib.tests.workingtree_implementations.test_rename_one',
122
'bzrlib.tests.workingtree_implementations.test_revision_tree',
123
'bzrlib.tests.workingtree_implementations.test_set_root_id',
124
'bzrlib.tests.workingtree_implementations.test_smart_add',
125
'bzrlib.tests.workingtree_implementations.test_uncommit',
126
'bzrlib.tests.workingtree_implementations.test_unversion',
127
'bzrlib.tests.workingtree_implementations.test_walkdirs',
128
'bzrlib.tests.workingtree_implementations.test_workingtree',
162
test_workingtree_implementations = [
163
'bzrlib.tests.per_workingtree.test_' + name for
166
scenarios = wt_scenarios()
131
adapter = WorkingTreeTestProviderAdapter(
133
# None here will cause a readonly decorator to be created
134
# by the TestCaseWithTransport.get_readonly_transport method.
136
WorkingTreeFormat._formats.values() + _legacy_formats)
168
138
# add the tests for the sub modules
169
return tests.multiply_tests(
170
loader.loadTestsFromModuleNames(test_workingtree_implementations),
171
scenarios, standard_tests)
174
class TestWtScenarios(tests.TestCase):
176
def test_protect_wt_scenarios(self):
177
# Just make sure we don't accidentally delete the helper again
178
scenarios = wt_scenarios()
139
adapt_modules(test_workingtree_implementations, adapter, loader, result)