127
127
len(list(iter(adapter.adapt(input_test)))))
129
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 (HttpTransport,
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.
130
# Check that the test adapter inserts a transport and server into the
133
# This test used to know about all the possible transports and the
134
# order they were returned but that seems overly brittle (mbp
177
136
input_test = TestTransportProviderAdapter(
178
137
"test_adapter_sets_transport_class")
138
from bzrlib.transport import TransportTestProviderAdapter
179
139
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.assertEqual(HttpTransport, http_test.transport_class)
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())
140
tests = list(iter(suite))
141
self.assertTrue(len(tests) > 6)
142
# there are at least that many builtin transports
144
self.assertTrue(issubclass(one_test.transport_class,
145
bzrlib.transport.Transport))
146
self.assertTrue(issubclass(one_test.transport_server,
147
bzrlib.transport.Server))
233
150
class TestBranchProviderAdapter(TestCase):
437
354
def test_get_readonly_url_http(self):
438
355
from bzrlib.transport import get_transport
439
356
from bzrlib.transport.local import LocalRelpathServer
440
from bzrlib.transport.http import HttpServer, HttpTransport
357
from bzrlib.transport.http import HttpServer, HttpTransportBase
441
358
self.transport_server = LocalRelpathServer
442
359
self.transport_readonly_server = HttpServer
443
360
# calling get_readonly_transport() gives us a HTTP server instance.
444
361
url = self.get_readonly_url()
445
362
url2 = self.get_readonly_url('foo/bar')
363
# the transport returned may be any HttpTransportBase subclass
446
364
t = get_transport(url)
447
365
t2 = get_transport(url2)
448
self.failUnless(isinstance(t, HttpTransport))
449
self.failUnless(isinstance(t2, HttpTransport))
366
self.failUnless(isinstance(t, HttpTransportBase))
367
self.failUnless(isinstance(t2, HttpTransportBase))
450
368
self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
452
370
def test_is_directory(self):
464
383
t = get_transport(self.get_readonly_url())
466
385
self.assertEqual(url, t.clone('..').base)
388
class TestExtraAssertions(TestCase):
389
"""Tests for new test assertions in bzrlib test suite"""
391
def test_assert_isinstance(self):
392
self.assertIsInstance(2, int)
393
self.assertIsInstance(u'', basestring)
394
self.assertRaises(AssertionError, self.assertIsInstance, None, int)
395
self.assertRaises(AssertionError, self.assertIsInstance, 23.3, int)
398
class TestConvenienceMakers(TestCaseWithTransport):
399
"""Test for the make_* convenience functions."""
401
def test_make_branch_and_tree_with_format(self):
402
# we should be able to supply a format to make_branch_and_tree
403
self.make_branch_and_tree('a', format=bzrlib.bzrdir.BzrDirMetaFormat1())
404
self.make_branch_and_tree('b', format=bzrlib.bzrdir.BzrDirFormat6())
405
self.assertIsInstance(bzrlib.bzrdir.BzrDir.open('a')._format,
406
bzrlib.bzrdir.BzrDirMetaFormat1)
407
self.assertIsInstance(bzrlib.bzrdir.BzrDir.open('b')._format,
408
bzrlib.bzrdir.BzrDirFormat6)