72
78
test = unittest.FunctionTestCase(skipping_test)
73
79
result = runner.run(test)
74
80
self.assertTrue(result.wasSuccessful())
83
class TestTransportProviderAdapter(TestCase):
84
"""A group of tests that test the transport implementation adaption core.
86
This is a meta test that the tests are applied to all available
89
This will be generalised in the future which is why it is in this
90
test file even though it is specific to transport tests at the moment.
93
def test_get_transport_permutations(self):
94
# this checks that we the module get_test_permutations call
95
# is made by the adapter get_transport_test_permitations method.
96
class MockModule(object):
97
def get_test_permutations(self):
98
return sample_permutation
99
sample_permutation = [(1,2), (3,4)]
100
from bzrlib.transport import TransportTestProviderAdapter
101
adapter = TransportTestProviderAdapter()
102
self.assertEqual(sample_permutation,
103
adapter.get_transport_test_permutations(MockModule()))
105
def test_adapter_checks_all_modules(self):
106
# this checks that the adapter returns as many permurtations as
107
# there are in all the registered# transport modules for there
108
# - we assume if this matches its probably doing the right thing
109
# especially in combination with the tests for setting the right
111
from bzrlib.transport import (TransportTestProviderAdapter,
112
_get_transport_modules
114
modules = _get_transport_modules()
115
permutation_count = 0
116
for module in modules:
118
permutation_count += len(reduce(getattr,
119
(module + ".get_test_permutations").split('.')[1:],
120
__import__(module))())
121
except errors.DependencyNotPresent:
123
input_test = TestTransportProviderAdapter(
124
"test_adapter_sets_transport_class")
125
adapter = TransportTestProviderAdapter()
126
self.assertEqual(permutation_count,
127
len(list(iter(adapter.adapt(input_test)))))
129
def test_adapter_sets_transport_class(self):
130
# when the adapter adapts a test it needs to
131
# place one of the permutations from the transport
132
# providers in each test case copy. This checks
133
# that it does not just use the same one all the time.
134
# and that the id is set correctly so that debugging is
137
# An instance of this test is actually used as the input
138
# for adapting it to all the available transports
139
# (or i think so - ??? mbp)
140
from bzrlib.transport.local import (LocalTransport,
146
from bzrlib.transport.sftp import (SFTPTransport,
149
SFTPSiblingAbsoluteServer,
151
except errors.ParamikoNotPresent, e:
152
warnings.warn(str(e))
156
from bzrlib.transport.http import (HttpTransportBase,
159
from bzrlib.transport.ftp import FtpTransport
160
from bzrlib.transport.memory import (MemoryTransport,
163
from bzrlib.transport import TransportTestProviderAdapter
164
# FIXME. What we want is a factory for the things
165
# needed to test the implementation. I.e. for transport we want:
166
# the class that connections should get; a local server factory
167
# so we would want the following permutations:
168
# LocalTransport relpath-factory
169
# LocalTransport abspath-factory
170
# LocalTransport file://-factory
171
# SFTPTransport homedir-factory
172
# SFTPTransport abssolute-factory
173
# HTTPTransport http-factory
174
# HTTPTransport https-factory
175
# etc, but we are currently lacking in this, so print out that
176
# this should be fixed.
177
input_test = TestTransportProviderAdapter(
178
"test_adapter_sets_transport_class")
179
suite = TransportTestProviderAdapter().adapt(input_test)
180
# tests are generated in collation order.
181
# XXX: but i'm not sure the order should really be part of the
182
# contract of the adapter, should it -- mbp 20060201
183
test_iter = iter(suite)
184
http_test = test_iter.next()
185
local_relpath_test = test_iter.next()
186
local_abspath_test = test_iter.next()
187
local_urlpath_test = test_iter.next()
188
memory_test = test_iter.next()
189
readonly_test = test_iter.next()
191
sftp_abs_test = test_iter.next()
192
sftp_homedir_test = test_iter.next()
193
sftp_sibling_abs_test = test_iter.next()
194
# ftp_test = test_iter.next()
195
# should now be at the end of the test
196
self.assertRaises(StopIteration, test_iter.next)
197
self.assertEqual(LocalTransport, local_relpath_test.transport_class)
198
self.assertEqual(LocalRelpathServer, local_relpath_test.transport_server)
200
self.assertEqual(LocalTransport, local_abspath_test.transport_class)
201
self.assertEqual(LocalAbspathServer, local_abspath_test.transport_server)
203
self.assertEqual(LocalTransport, local_urlpath_test.transport_class)
204
self.assertEqual(LocalURLServer, local_urlpath_test.transport_server)
207
self.assertEqual(SFTPTransport, sftp_abs_test.transport_class)
208
self.assertEqual(SFTPAbsoluteServer, sftp_abs_test.transport_server)
209
self.assertEqual(SFTPTransport, sftp_homedir_test.transport_class)
210
self.assertEqual(SFTPHomeDirServer, sftp_homedir_test.transport_server)
211
self.assertEqual(SFTPTransport, sftp_sibling_abs_test.transport_class)
212
self.assertEqual(SFTPSiblingAbsoluteServer,
213
sftp_sibling_abs_test.transport_server)
215
self.assertTrue(issubclass(http_test.transport_class, HttpTransportBase))
216
self.assertEqual(HttpServer, http_test.transport_server)
217
# self.assertEqual(FtpTransport, ftp_test.transport_class)
219
self.assertEqual(MemoryTransport, memory_test.transport_class)
220
self.assertEqual(MemoryServer, memory_test.transport_server)
222
# we could test all of them for .id, but two is probably sufficient.
223
self.assertEqual("bzrlib.tests.test_selftest."
224
"TestTransportProviderAdapter."
225
"test_adapter_sets_transport_class(MemoryServer)",
227
self.assertEqual("bzrlib.tests.test_selftest."
228
"TestTransportProviderAdapter."
229
"test_adapter_sets_transport_class(LocalRelpathServer)",
230
local_relpath_test.id())
233
class TestBranchProviderAdapter(TestCase):
234
"""A group of tests that test the branch implementation test adapter."""
236
def test_adapted_tests(self):
237
# check that constructor parameters are passed through to the adapted
239
from bzrlib.branch import BranchTestProviderAdapter
240
input_test = TestBranchProviderAdapter(
241
"test_adapted_tests")
245
adapter = BranchTestProviderAdapter(server1, server2, formats)
246
suite = adapter.adapt(input_test)
247
tests = list(iter(suite))
248
self.assertEqual(2, len(tests))
249
self.assertEqual(tests[0].branch_format, formats[0])
250
self.assertEqual(tests[0].transport_server, server1)
251
self.assertEqual(tests[0].transport_readonly_server, server2)
252
self.assertEqual(tests[1].branch_format, formats[1])
253
self.assertEqual(tests[1].transport_server, server1)
254
self.assertEqual(tests[1].transport_readonly_server, server2)
257
class TestTestCaseWithTransport(TestCaseWithTransport):
258
"""Tests for the convenience functions TestCaseWithTransport introduces."""
260
def test_get_readonly_url_none(self):
261
from bzrlib.transport import get_transport
262
from bzrlib.transport.memory import MemoryServer
263
from bzrlib.transport.readonly import ReadonlyTransportDecorator
264
self.transport_server = MemoryServer
265
self.transport_readonly_server = None
266
# calling get_readonly_transport() constructs a decorator on the url
268
url = self.get_readonly_url()
269
url2 = self.get_readonly_url('foo/bar')
270
t = get_transport(url)
271
t2 = get_transport(url2)
272
self.failUnless(isinstance(t, ReadonlyTransportDecorator))
273
self.failUnless(isinstance(t2, ReadonlyTransportDecorator))
274
self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
276
def test_get_readonly_url_http(self):
277
from bzrlib.transport import get_transport
278
from bzrlib.transport.local import LocalRelpathServer
279
from bzrlib.transport.http import HttpServer, HttpTransportBase
280
self.transport_server = LocalRelpathServer
281
self.transport_readonly_server = HttpServer
282
# calling get_readonly_transport() gives us a HTTP server instance.
283
url = self.get_readonly_url()
284
url2 = self.get_readonly_url('foo/bar')
285
# the transport returned may be any HttpTransportBase subclass
286
t = get_transport(url)
287
t2 = get_transport(url2)
288
self.failUnless(isinstance(t, HttpTransportBase))
289
self.failUnless(isinstance(t2, HttpTransportBase))
290
self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
293
class TestChrootedTest(ChrootedTestCase):
295
def test_root_is_root(self):
296
from bzrlib.transport import get_transport
297
t = get_transport(self.get_readonly_url())
299
self.assertEqual(url, t.clone('..').base)