bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
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
|
|
16 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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.
|
|
|
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 |
||
28 |
from bzrlib.branch import ( |
|
29 |
GenericInterBranch, |
|
30 |
InterBranch, |
|
31 |
)
|
|
32 |
from bzrlib.errors import ( |
|
33 |
FileExists, |
|
34 |
UninitializableFormat, |
|
35 |
)
|
|
36 |
from bzrlib.tests import ( |
|
37 |
adapt_modules, |
|
38 |
TestScenarioApplier, |
|
39 |
)
|
|
40 |
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir |
|
41 |
from bzrlib.transport import get_transport |
|
42 |
||
43 |
||
44 |
class InterBranchTestProviderAdapter(TestScenarioApplier): |
|
45 |
"""A tool to generate a suite testing multiple inter branch formats. |
|
46 |
||
|
4000.5.8
by Jelmer Vernooij
Fix whitespace. |
47 |
This is done by copying the test once for each interbranch provider and
|
48 |
injecting the branch_format_from and branch_to_format classes into each
|
|
|
4000.5.6
by Jelmer Vernooij
Remove unused transport settings. |
49 |
copy. Each copy is also given a new id() to make it easy to identify.
|
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
50 |
"""
|
51 |
||
|
4000.5.6
by Jelmer Vernooij
Remove unused transport settings. |
52 |
def __init__(self, formats): |
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
53 |
TestScenarioApplier.__init__(self) |
54 |
self.scenarios = self.formats_to_scenarios(formats) |
|
55 |
||
56 |
def formats_to_scenarios(self, formats): |
|
57 |
"""Transform the input formats to a list of scenarios. |
|
58 |
||
59 |
:param formats: A list of tuples:
|
|
|
4000.5.5
by Jelmer Vernooij
Allow InterBranch implementations to set different from and to Branch formats for testing. |
60 |
(interbranch_class, branch_format_from, branch_format_to).
|
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
61 |
"""
|
62 |
result = [] |
|
|
4000.5.5
by Jelmer Vernooij
Allow InterBranch implementations to set different from and to Branch formats for testing. |
63 |
for interbranch_class, branch_format_from, branch_format_to in formats: |
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
64 |
id = '%s,%s,%s' % (interbranch_class.__name__, |
|
4000.5.5
by Jelmer Vernooij
Allow InterBranch implementations to set different from and to Branch formats for testing. |
65 |
branch_format_from.__class__.__name__, |
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
66 |
branch_format_to.__class__.__name__) |
67 |
scenario = (id, |
|
|
4000.5.6
by Jelmer Vernooij
Remove unused transport settings. |
68 |
{
|
|
4000.5.5
by Jelmer Vernooij
Allow InterBranch implementations to set different from and to Branch formats for testing. |
69 |
"branch_format_from":branch_format_from, |
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
70 |
"interbranch_class":interbranch_class, |
71 |
"branch_format_to":branch_format_to, |
|
72 |
})
|
|
73 |
result.append(scenario) |
|
74 |
return result |
|
75 |
||
76 |
@staticmethod
|
|
77 |
def default_test_list(): |
|
78 |
"""Generate the default list of interbranch permutations to test.""" |
|
79 |
result = [] |
|
80 |
# test the default InterBranch between format 6 and the current
|
|
81 |
# default format.
|
|
82 |
for optimiser_class in InterBranch._optimisers: |
|
|
4000.5.5
by Jelmer Vernooij
Allow InterBranch implementations to set different from and to Branch formats for testing. |
83 |
format_from_test, format_to_test = \ |
84 |
optimiser_class._get_branch_formats_to_test() |
|
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
85 |
if format_to_test is not None: |
86 |
result.append((optimiser_class, |
|
|
4000.5.5
by Jelmer Vernooij
Allow InterBranch implementations to set different from and to Branch formats for testing. |
87 |
format_from_test, format_to_test)) |
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
88 |
# if there are specific combinations we want to use, we can add them
|
89 |
# here.
|
|
90 |
return result |
|
91 |
||
92 |
||
93 |
class TestCaseWithInterBranch(TestCaseWithBzrDir): |
|
94 |
||
95 |
def setUp(self): |
|
96 |
super(TestCaseWithInterBranch, self).setUp() |
|
97 |
||
98 |
def make_branch(self, relpath, format=None): |
|
99 |
repo = self.make_repository(relpath, format=format) |
|
100 |
return repo.bzrdir.create_branch() |
|
101 |
||
102 |
def make_bzrdir(self, relpath, format=None): |
|
103 |
try: |
|
104 |
url = self.get_url(relpath) |
|
105 |
segments = url.split('/') |
|
106 |
if segments and segments[-1] not in ('', '.'): |
|
107 |
parent = '/'.join(segments[:-1]) |
|
108 |
t = get_transport(parent) |
|
109 |
try: |
|
110 |
t.mkdir(segments[-1]) |
|
111 |
except FileExists: |
|
112 |
pass
|
|
113 |
if format is None: |
|
|
4000.5.5
by Jelmer Vernooij
Allow InterBranch implementations to set different from and to Branch formats for testing. |
114 |
format = self.branch_format_from._matchingbzrdir |
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
115 |
return format.initialize(url) |
116 |
except UninitializableFormat: |
|
117 |
raise TestSkipped("Format %s is not initializable." % format) |
|
118 |
||
119 |
def make_repository(self, relpath, format=None): |
|
120 |
made_control = self.make_bzrdir(relpath, format=format) |
|
121 |
return made_control.create_repository() |
|
122 |
||
123 |
def make_to_bzrdir(self, relpath): |
|
124 |
return self.make_bzrdir(relpath, |
|
125 |
self.branch_format_to._matchingbzrdir) |
|
126 |
||
127 |
def make_to_branch(self, relpath): |
|
128 |
made_control = self.make_to_bzrdir(relpath) |
|
129 |
return self.branch_format_to.initialize(made_control) |
|
130 |
||
131 |
||
132 |
def load_tests(basic_tests, module, loader): |
|
133 |
result = loader.suiteClass() |
|
134 |
# add the tests for this module
|
|
135 |
result.addTests(basic_tests) |
|
136 |
||
137 |
test_interbranch_implementations = [ |
|
138 |
'bzrlib.tests.per_interbranch.test_update_revisions', |
|
139 |
]
|
|
140 |
adapter = InterBranchTestProviderAdapter( |
|
141 |
InterBranchTestProviderAdapter.default_test_list() |
|
142 |
)
|
|
143 |
# add the tests for the sub modules
|
|
144 |
adapt_modules(test_interbranch_implementations, adapter, loader, result) |
|
145 |
return result |