150
151
# This test used to know about all the possible transports and the
151
152
# order they were returned but that seems overly brittle (mbp
153
input_test = TestTransportProviderAdapter(
154
"test_adapter_sets_transport_class")
155
from bzrlib.transport import TransportTestProviderAdapter
156
suite = TransportTestProviderAdapter().adapt(input_test)
157
tests = list(iter(suite))
158
self.assertTrue(len(tests) > 6)
154
from bzrlib.tests.test_transport_implementations \
155
import TransportTestProviderAdapter
156
scenarios = TransportTestProviderAdapter().scenarios
159
157
# there are at least that many builtin transports
161
self.assertTrue(issubclass(one_test.transport_class,
158
self.assertTrue(len(scenarios) > 6)
159
one_scenario = scenarios[0]
160
self.assertIsInstance(one_scenario[0], str)
161
self.assertTrue(issubclass(one_scenario[1]["transport_class"],
162
162
bzrlib.transport.Transport))
163
self.assertTrue(issubclass(one_test.transport_server,
163
self.assertTrue(issubclass(one_scenario[1]["transport_server"],
164
164
bzrlib.transport.Server))
167
167
class TestBranchProviderAdapter(TestCase):
168
168
"""A group of tests that test the branch implementation test adapter."""
170
def test_adapted_tests(self):
170
def test_constructor(self):
171
171
# check that constructor parameters are passed through to the adapted
173
from bzrlib.branch import BranchTestProviderAdapter
174
input_test = TestBranchProviderAdapter(
175
"test_adapted_tests")
173
from bzrlib.tests.branch_implementations import BranchTestProviderAdapter
178
176
formats = [("c", "C"), ("d", "D")]
179
177
adapter = BranchTestProviderAdapter(server1, server2, formats)
180
suite = adapter.adapt(input_test)
181
tests = list(iter(suite))
182
self.assertEqual(2, len(tests))
183
self.assertEqual(tests[0].branch_format, formats[0][0])
184
self.assertEqual(tests[0].bzrdir_format, formats[0][1])
185
self.assertEqual(tests[0].transport_server, server1)
186
self.assertEqual(tests[0].transport_readonly_server, server2)
187
self.assertEqual(tests[1].branch_format, formats[1][0])
188
self.assertEqual(tests[1].bzrdir_format, formats[1][1])
189
self.assertEqual(tests[1].transport_server, server1)
190
self.assertEqual(tests[1].transport_readonly_server, server2)
178
self.assertEqual(2, len(adapter.scenarios))
181
{'branch_format': 'c',
182
'bzrdir_format': 'C',
183
'transport_readonly_server': 'b',
184
'transport_server': 'a'}),
186
{'branch_format': 'd',
187
'bzrdir_format': 'D',
188
'transport_readonly_server': 'b',
189
'transport_server': 'a'})],
193
193
class TestBzrDirProviderAdapter(TestCase):
196
196
def test_adapted_tests(self):
197
197
# check that constructor parameters are passed through to the adapted
199
from bzrlib.bzrdir import BzrDirTestProviderAdapter
200
input_test = TestBzrDirProviderAdapter(
201
"test_adapted_tests")
199
from bzrlib.tests.bzrdir_implementations import BzrDirTestProviderAdapter
202
200
vfs_factory = "v"
205
203
formats = ["c", "d"]
206
204
adapter = BzrDirTestProviderAdapter(vfs_factory,
207
205
server1, server2, formats)
208
suite = adapter.adapt(input_test)
209
tests = list(iter(suite))
210
self.assertEqual(2, len(tests))
211
self.assertEqual(tests[0].bzrdir_format, formats[0])
212
self.assertEqual(tests[0].vfs_transport_factory, vfs_factory)
213
self.assertEqual(tests[0].transport_server, server1)
214
self.assertEqual(tests[0].transport_readonly_server, server2)
215
self.assertEqual(tests[1].bzrdir_format, formats[1])
216
self.assertEqual(tests[1].vfs_transport_factory, vfs_factory)
217
self.assertEqual(tests[1].transport_server, server1)
218
self.assertEqual(tests[1].transport_readonly_server, server2)
208
{'bzrdir_format': 'c',
209
'transport_readonly_server': 'b',
210
'transport_server': 'a',
211
'vfs_transport_factory': 'v'}),
213
{'bzrdir_format': 'd',
214
'transport_readonly_server': 'b',
215
'transport_server': 'a',
216
'vfs_transport_factory': 'v'})],
221
220
class TestRepositoryProviderAdapter(TestCase):
222
221
"""A group of tests that test the repository implementation test adapter."""
224
def test_adapted_tests(self):
225
# check that constructor parameters are passed through to the adapted
227
from bzrlib.repository import RepositoryTestProviderAdapter
228
input_test = TestRepositoryProviderAdapter(
229
"test_adapted_tests")
223
def test_constructor(self):
224
# check that constructor parameters are passed through to the
226
from bzrlib.tests.repository_implementations import RepositoryTestProviderAdapter
232
229
formats = [("c", "C"), ("d", "D")]
233
230
adapter = RepositoryTestProviderAdapter(server1, server2, formats)
234
suite = adapter.adapt(input_test)
235
tests = list(iter(suite))
236
self.assertEqual(2, len(tests))
237
self.assertEqual(tests[0].bzrdir_format, formats[0][1])
238
self.assertEqual(tests[0].repository_format, formats[0][0])
239
self.assertEqual(tests[0].transport_server, server1)
240
self.assertEqual(tests[0].transport_readonly_server, server2)
241
self.assertEqual(tests[1].bzrdir_format, formats[1][1])
242
self.assertEqual(tests[1].repository_format, formats[1][0])
243
self.assertEqual(tests[1].transport_server, server1)
244
self.assertEqual(tests[1].transport_readonly_server, server2)
233
{'bzrdir_format': 'C',
234
'repository_format': 'c',
235
'transport_readonly_server': 'b',
236
'transport_server': 'a'}),
238
{'bzrdir_format': 'D',
239
'repository_format': 'd',
240
'transport_readonly_server': 'b',
241
'transport_server': 'a'})],
246
244
def test_setting_vfs_transport(self):
247
245
"""The vfs_transport_factory can be set optionally."""
248
from bzrlib.repository import RepositoryTestProviderAdapter
249
input_test = TestRepositoryProviderAdapter(
250
"test_adapted_tests")
251
formats = [("c", "C")]
246
from bzrlib.tests.repository_implementations import RepositoryTestProviderAdapter
247
formats = [("a", "b"), ("c", "d")]
252
248
adapter = RepositoryTestProviderAdapter(None, None, formats,
253
249
vfs_transport_factory="vfs")
254
suite = adapter.adapt(input_test)
255
tests = list(iter(suite))
256
self.assertEqual(1, len(tests))
257
self.assertEqual(tests[0].vfs_transport_factory, "vfs")
252
{'bzrdir_format': 'b',
253
'repository_format': 'a',
254
'transport_readonly_server': None,
255
'transport_server': None,
256
'vfs_transport_factory': 'vfs'}),
258
{'bzrdir_format': 'd',
259
'repository_format': 'c',
260
'transport_readonly_server': None,
261
'transport_server': None,
262
'vfs_transport_factory': 'vfs'})],
265
def test_formats_to_scenarios(self):
266
"""The adapter can generate all the scenarios needed."""
267
from bzrlib.tests.repository_implementations import RepositoryTestProviderAdapter
268
no_vfs_adapter = RepositoryTestProviderAdapter("server", "readonly",
270
vfs_adapter = RepositoryTestProviderAdapter("server", "readonly",
271
[], vfs_transport_factory="vfs")
272
# no_vfs generate scenarios without vfs_transport_factor
273
formats = [("c", "C"), (1, "D")]
276
{'bzrdir_format': 'C',
277
'repository_format': 'c',
278
'transport_readonly_server': 'readonly',
279
'transport_server': 'server'}),
281
{'bzrdir_format': 'D',
282
'repository_format': 1,
283
'transport_readonly_server': 'readonly',
284
'transport_server': 'server'})],
285
no_vfs_adapter.formats_to_scenarios(formats))
288
{'bzrdir_format': 'C',
289
'repository_format': 'c',
290
'transport_readonly_server': 'readonly',
291
'transport_server': 'server',
292
'vfs_transport_factory': 'vfs'}),
294
{'bzrdir_format': 'D',
295
'repository_format': 1,
296
'transport_readonly_server': 'readonly',
297
'transport_server': 'server',
298
'vfs_transport_factory': 'vfs'})],
299
vfs_adapter.formats_to_scenarios(formats))
302
class TestTestScenarioApplier(TestCase):
303
"""Tests for the test adaption facilities."""
305
def test_adapt_applies_scenarios(self):
306
from bzrlib.tests.repository_implementations import TestScenarioApplier
307
input_test = TestTestScenarioApplier("test_adapt_test_to_scenario")
308
adapter = TestScenarioApplier()
309
adapter.scenarios = [("1", "dict"), ("2", "settings")]
311
def capture_call(test, scenario):
312
calls.append((test, scenario))
314
adapter.adapt_test_to_scenario = capture_call
315
adapter.adapt(input_test)
316
self.assertEqual([(input_test, ("1", "dict")),
317
(input_test, ("2", "settings"))], calls)
319
def test_adapt_test_to_scenario(self):
320
from bzrlib.tests.repository_implementations import TestScenarioApplier
321
input_test = TestTestScenarioApplier("test_adapt_test_to_scenario")
322
adapter = TestScenarioApplier()
323
# setup two adapted tests
324
adapted_test1 = adapter.adapt_test_to_scenario(input_test,
326
{"bzrdir_format":"bzr_format",
327
"repository_format":"repo_fmt",
328
"transport_server":"transport_server",
329
"transport_readonly_server":"readonly-server"}))
330
adapted_test2 = adapter.adapt_test_to_scenario(input_test,
331
("new id 2", {"bzrdir_format":None}))
332
# input_test should have been altered.
333
self.assertRaises(AttributeError, getattr, input_test, "bzrdir_format")
334
# the new tests are mutually incompatible, ensuring it has
335
# made new ones, and unspecified elements in the scenario
336
# should not have been altered.
337
self.assertEqual("bzr_format", adapted_test1.bzrdir_format)
338
self.assertEqual("repo_fmt", adapted_test1.repository_format)
339
self.assertEqual("transport_server", adapted_test1.transport_server)
340
self.assertEqual("readonly-server",
341
adapted_test1.transport_readonly_server)
343
"bzrlib.tests.test_selftest.TestTestScenarioApplier."
344
"test_adapt_test_to_scenario(new id)",
346
self.assertEqual(None, adapted_test2.bzrdir_format)
348
"bzrlib.tests.test_selftest.TestTestScenarioApplier."
349
"test_adapt_test_to_scenario(new id 2)",
260
353
class TestInterRepositoryProviderAdapter(TestCase):
263
356
def test_adapted_tests(self):
264
357
# check that constructor parameters are passed through to the adapted
266
from bzrlib.repository import InterRepositoryTestProviderAdapter
267
input_test = TestInterRepositoryProviderAdapter(
268
"test_adapted_tests")
359
from bzrlib.tests.interrepository_implementations import \
360
InterRepositoryTestProviderAdapter
271
363
formats = [(str, "C1", "C2"), (int, "D1", "D2")]
272
364
adapter = InterRepositoryTestProviderAdapter(server1, server2, formats)
273
suite = adapter.adapt(input_test)
274
tests = list(iter(suite))
275
self.assertEqual(2, len(tests))
276
self.assertEqual(tests[0].interrepo_class, formats[0][0])
277
self.assertEqual(tests[0].repository_format, formats[0][1])
278
self.assertEqual(tests[0].repository_format_to, formats[0][2])
279
self.assertEqual(tests[0].transport_server, server1)
280
self.assertEqual(tests[0].transport_readonly_server, server2)
281
self.assertEqual(tests[1].interrepo_class, formats[1][0])
282
self.assertEqual(tests[1].repository_format, formats[1][1])
283
self.assertEqual(tests[1].repository_format_to, formats[1][2])
284
self.assertEqual(tests[1].transport_server, server1)
285
self.assertEqual(tests[1].transport_readonly_server, server2)
367
{'interrepo_class': str,
368
'repository_format': 'C1',
369
'repository_format_to': 'C2',
370
'transport_readonly_server': 'b',
371
'transport_server': 'a'}),
373
{'interrepo_class': int,
374
'repository_format': 'D1',
375
'repository_format_to': 'D2',
376
'transport_readonly_server': 'b',
377
'transport_server': 'a'})],
378
adapter.formats_to_scenarios(formats))
288
381
class TestInterVersionedFileProviderAdapter(TestCase):
289
382
"""A group of tests that test the InterVersionedFile test adapter."""
291
def test_adapted_tests(self):
384
def test_scenarios(self):
292
385
# check that constructor parameters are passed through to the adapted
294
from bzrlib.versionedfile import InterVersionedFileTestProviderAdapter
295
input_test = TestInterRepositoryProviderAdapter(
296
"test_adapted_tests")
387
from bzrlib.tests.interversionedfile_implementations \
388
import InterVersionedFileTestProviderAdapter
299
391
formats = [(str, "C1", "C2"), (int, "D1", "D2")]
300
392
adapter = InterVersionedFileTestProviderAdapter(server1, server2, formats)
301
suite = adapter.adapt(input_test)
302
tests = list(iter(suite))
303
self.assertEqual(2, len(tests))
304
self.assertEqual(tests[0].interversionedfile_class, formats[0][0])
305
self.assertEqual(tests[0].versionedfile_factory, formats[0][1])
306
self.assertEqual(tests[0].versionedfile_factory_to, formats[0][2])
307
self.assertEqual(tests[0].transport_server, server1)
308
self.assertEqual(tests[0].transport_readonly_server, server2)
309
self.assertEqual(tests[1].interversionedfile_class, formats[1][0])
310
self.assertEqual(tests[1].versionedfile_factory, formats[1][1])
311
self.assertEqual(tests[1].versionedfile_factory_to, formats[1][2])
312
self.assertEqual(tests[1].transport_server, server1)
313
self.assertEqual(tests[1].transport_readonly_server, server2)
395
{'interversionedfile_class':str,
396
'transport_readonly_server': 'b',
397
'transport_server': 'a',
398
'versionedfile_factory': 'C1',
399
'versionedfile_factory_to': 'C2'}),
401
{'interversionedfile_class': int,
402
'transport_readonly_server': 'b',
403
'transport_server': 'a',
404
'versionedfile_factory': 'D1',
405
'versionedfile_factory_to': 'D2'})],
316
409
class TestRevisionStoreProviderAdapter(TestCase):
317
410
"""A group of tests that test the RevisionStore test adapter."""
319
def test_adapted_tests(self):
412
def test_scenarios(self):
320
413
# check that constructor parameters are passed through to the adapted
322
from bzrlib.store.revision import RevisionStoreTestProviderAdapter
323
input_test = TestRevisionStoreProviderAdapter(
324
"test_adapted_tests")
415
from bzrlib.tests.revisionstore_implementations \
416
import RevisionStoreTestProviderAdapter
325
417
# revision stores need a store factory - i.e. RevisionKnit
326
418
#, a readonly and rw transport
327
419
# transport servers:
330
422
store_factories = ["c", "d"]
331
423
adapter = RevisionStoreTestProviderAdapter(server1, server2, store_factories)
332
suite = adapter.adapt(input_test)
333
tests = list(iter(suite))
334
self.assertEqual(2, len(tests))
335
self.assertEqual(tests[0].store_factory, store_factories[0][0])
336
self.assertEqual(tests[0].transport_server, server1)
337
self.assertEqual(tests[0].transport_readonly_server, server2)
338
self.assertEqual(tests[1].store_factory, store_factories[1][0])
339
self.assertEqual(tests[1].transport_server, server1)
340
self.assertEqual(tests[1].transport_readonly_server, server2)
426
{'store_factory': 'c',
427
'transport_readonly_server': 'b',
428
'transport_server': 'a'}),
430
{'store_factory': 'd',
431
'transport_readonly_server': 'b',
432
'transport_server': 'a'})],
343
436
class TestWorkingTreeProviderAdapter(TestCase):
344
437
"""A group of tests that test the workingtree implementation test adapter."""
346
def test_adapted_tests(self):
439
def test_scenarios(self):
347
440
# check that constructor parameters are passed through to the adapted
349
from bzrlib.workingtree import WorkingTreeTestProviderAdapter
350
input_test = TestWorkingTreeProviderAdapter(
351
"test_adapted_tests")
442
from bzrlib.tests.workingtree_implementations \
443
import WorkingTreeTestProviderAdapter
354
446
formats = [("c", "C"), ("d", "D")]
355
447
adapter = WorkingTreeTestProviderAdapter(server1, server2, formats)
356
suite = adapter.adapt(input_test)
357
tests = list(iter(suite))
358
self.assertEqual(2, len(tests))
359
self.assertEqual(tests[0].workingtree_format, formats[0][0])
360
self.assertEqual(tests[0].bzrdir_format, formats[0][1])
361
self.assertEqual(tests[0].transport_server, server1)
362
self.assertEqual(tests[0].transport_readonly_server, server2)
363
self.assertEqual(tests[1].workingtree_format, formats[1][0])
364
self.assertEqual(tests[1].bzrdir_format, formats[1][1])
365
self.assertEqual(tests[1].transport_server, server1)
366
self.assertEqual(tests[1].transport_readonly_server, server2)
450
{'bzrdir_format': 'C',
451
'transport_readonly_server': 'b',
452
'transport_server': 'a',
453
'workingtree_format': 'c'}),
455
{'bzrdir_format': 'D',
456
'transport_readonly_server': 'b',
457
'transport_server': 'a',
458
'workingtree_format': 'd'})],
369
462
class TestTreeProviderAdapter(TestCase):