142
142
def test_get_transport_permutations(self):
143
143
# this checks that get_test_permutations defined by the module is
144
# called by the adapter get_transport_test_permutations method.
144
# called by the get_transport_test_permutations function.
145
145
class MockModule(object):
146
146
def get_test_permutations(self):
147
147
return sample_permutation
148
148
sample_permutation = [(1,2), (3,4)]
149
149
from bzrlib.tests.test_transport_implementations \
150
import TransportTestProviderAdapter
151
adapter = TransportTestProviderAdapter()
150
import get_transport_test_permutations
152
151
self.assertEqual(sample_permutation,
153
adapter.get_transport_test_permutations(MockModule()))
152
get_transport_test_permutations(MockModule()))
155
def test_adapter_checks_all_modules(self):
156
# this checks that the adapter returns as many permutations as there
157
# are in all the registered transport modules - we assume if this
158
# matches its probably doing the right thing especially in combination
159
# with the tests for setting the right classes below.
154
def test_scenarios_invlude_all_modules(self):
155
# this checks that the scenario generator returns as many permutations
156
# as there are in all the registered transport modules - we assume if
157
# this matches its probably doing the right thing especially in
158
# combination with the tests for setting the right classes below.
160
159
from bzrlib.tests.test_transport_implementations \
161
import TransportTestProviderAdapter
160
import transport_test_permutations
162
161
from bzrlib.transport import _get_transport_modules
163
162
modules = _get_transport_modules()
164
163
permutation_count = 0
169
168
__import__(module))())
170
169
except errors.DependencyNotPresent:
172
input_test = TestTransportProviderAdapter(
173
"test_adapter_sets_transport_class")
174
adapter = TransportTestProviderAdapter()
175
self.assertEqual(permutation_count,
176
len(list(iter(adapter.adapt(input_test)))))
171
scenarios = transport_test_permutations()
172
self.assertEqual(permutation_count, len(scenarios))
178
def test_adapter_sets_transport_class(self):
179
# Check that the test adapter inserts a transport and server into the
174
def test_scenarios_include_transport_class(self):
182
175
# This test used to know about all the possible transports and the
183
176
# order they were returned but that seems overly brittle (mbp
185
178
from bzrlib.tests.test_transport_implementations \
186
import TransportTestProviderAdapter
187
scenarios = TransportTestProviderAdapter().scenarios
179
import transport_test_permutations
180
scenarios = transport_test_permutations()
188
181
# there are at least that many builtin transports
189
182
self.assertTrue(len(scenarios) > 6)
190
183
one_scenario = scenarios[0]
293
class TestTestScenarioApplier(TestCase):
281
class TestTestScenarioApplication(TestCase):
294
282
"""Tests for the test adaption facilities."""
296
def test_adapt_applies_scenarios(self):
297
from bzrlib.tests.per_repository import TestScenarioApplier
298
input_test = TestTestScenarioApplier("test_adapt_test_to_scenario")
299
adapter = TestScenarioApplier()
300
adapter.scenarios = [("1", "dict"), ("2", "settings")]
302
def capture_call(test, scenario):
303
calls.append((test, scenario))
305
adapter.adapt_test_to_scenario = capture_call
306
adapter.adapt(input_test)
307
self.assertEqual([(input_test, ("1", "dict")),
308
(input_test, ("2", "settings"))], calls)
310
def test_adapt_test_to_scenario(self):
311
from bzrlib.tests.per_repository import TestScenarioApplier
312
input_test = TestTestScenarioApplier("test_adapt_test_to_scenario")
313
adapter = TestScenarioApplier()
284
def test_apply_scenario(self):
285
from bzrlib.tests import apply_scenario
286
input_test = TestTestScenarioApplication("test_apply_scenario")
314
287
# setup two adapted tests
315
adapted_test1 = adapter.adapt_test_to_scenario(input_test,
288
adapted_test1 = apply_scenario(input_test,
317
290
{"bzrdir_format":"bzr_format",
318
291
"repository_format":"repo_fmt",
319
292
"transport_server":"transport_server",
320
293
"transport_readonly_server":"readonly-server"}))
321
adapted_test2 = adapter.adapt_test_to_scenario(input_test,
294
adapted_test2 = apply_scenario(input_test,
322
295
("new id 2", {"bzrdir_format":None}))
323
296
# input_test should have been altered.
324
297
self.assertRaises(AttributeError, getattr, input_test, "bzrdir_format")
331
304
self.assertEqual("readonly-server",
332
305
adapted_test1.transport_readonly_server)
333
306
self.assertEqual(
334
"bzrlib.tests.test_selftest.TestTestScenarioApplier."
335
"test_adapt_test_to_scenario(new id)",
307
"bzrlib.tests.test_selftest.TestTestScenarioApplication."
308
"test_apply_scenario(new id)",
336
309
adapted_test1.id())
337
310
self.assertEqual(None, adapted_test2.bzrdir_format)
338
311
self.assertEqual(
339
"bzrlib.tests.test_selftest.TestTestScenarioApplier."
340
"test_adapt_test_to_scenario(new id 2)",
312
"bzrlib.tests.test_selftest.TestTestScenarioApplication."
313
"test_apply_scenario(new id 2)",
341
314
adapted_test2.id())
344
class TestInterRepositoryProviderAdapter(TestCase):
345
"""A group of tests that test the InterRepository test adapter."""
317
class TestInterRepositoryScenarios(TestCase):
347
def test_adapted_tests(self):
319
def test_scenarios(self):
348
320
# check that constructor parameters are passed through to the adapted
350
322
from bzrlib.tests.interrepository_implementations import \
351
InterRepositoryTestProviderAdapter
354
326
formats = [(str, "C1", "C2"), (int, "D1", "D2")]
355
adapter = InterRepositoryTestProviderAdapter(server1, server2, formats)
327
scenarios = make_scenarios(server1, server2, formats)
356
328
self.assertEqual([
358
330
{'interrepo_class': str,
393
364
'transport_readonly_server': 'b',
394
365
'transport_server': 'a',
395
366
'workingtree_format': formats[1]})],
399
class TestTreeProviderAdapter(TestCase):
400
"""Test the setup of tree_implementation tests."""
402
def test_adapted_tests(self):
403
# the tree implementation adapter is meant to setup one instance for
404
# each working tree format, and one additional instance that will
405
# use the default wt format, but create a revision tree for the tests.
406
# this means that the wt ones should have the workingtree_to_test_tree
407
# attribute set to 'return_parameter' and the revision one set to
408
# revision_tree_from_workingtree.
370
class TestTreeScenarios(TestCase):
372
def test_scenarios(self):
373
# the tree implementation scenario generator is meant to setup one
374
# instance for each working tree format, and one additional instance
375
# that will use the default wt format, but create a revision tree for
376
# the tests. this means that the wt ones should have the
377
# workingtree_to_test_tree attribute set to 'return_parameter' and the
378
# revision one set to revision_tree_from_workingtree.
410
380
from bzrlib.tests.tree_implementations import (
411
TreeTestProviderAdapter,
381
_dirstate_tree_from_workingtree,
412
385
return_parameter,
413
386
revision_tree_from_workingtree
415
input_test = TestTreeProviderAdapter(
416
"test_adapted_tests")
419
390
formats = [workingtree.WorkingTreeFormat2(),
420
391
workingtree.WorkingTreeFormat3(),]
421
adapter = TreeTestProviderAdapter(server1, server2, formats)
422
suite = adapter.adapt(input_test)
423
tests = list(iter(suite))
424
# XXX We should not have tests fail as we add more scenarios
426
self.assertEqual(7, len(tests))
427
# this must match the default format setp up in
428
# TreeTestProviderAdapter.adapt
429
default_format = workingtree.WorkingTreeFormat3
430
self.assertEqual(tests[0].workingtree_format, formats[0])
431
self.assertEqual(tests[0].bzrdir_format, formats[0]._matchingbzrdir)
432
self.assertEqual(tests[0].transport_server, server1)
433
self.assertEqual(tests[0].transport_readonly_server, server2)
434
self.assertEqual(tests[0]._workingtree_to_test_tree, return_parameter)
435
self.assertEqual(tests[1].workingtree_format, formats[1])
436
self.assertEqual(tests[1].bzrdir_format, formats[1]._matchingbzrdir)
437
self.assertEqual(tests[1].transport_server, server1)
438
self.assertEqual(tests[1].transport_readonly_server, server2)
439
self.assertEqual(tests[1]._workingtree_to_test_tree, return_parameter)
440
self.assertIsInstance(tests[2].workingtree_format, default_format)
441
#self.assertEqual(tests[2].bzrdir_format,
442
# default_format._matchingbzrdir)
443
self.assertEqual(tests[2].transport_server, server1)
444
self.assertEqual(tests[2].transport_readonly_server, server2)
445
self.assertEqual(tests[2]._workingtree_to_test_tree,
446
revision_tree_from_workingtree)
449
class TestInterTreeProviderAdapter(TestCase):
392
scenarios = make_scenarios(server1, server2, formats)
393
self.assertEqual(7, len(scenarios))
394
default_wt_format = workingtree.WorkingTreeFormat4._default_format
395
wt4_format = workingtree.WorkingTreeFormat4()
396
wt5_format = workingtree.WorkingTreeFormat5()
397
expected_scenarios = [
398
('WorkingTreeFormat2',
399
{'bzrdir_format': formats[0]._matchingbzrdir,
400
'transport_readonly_server': 'b',
401
'transport_server': 'a',
402
'workingtree_format': formats[0],
403
'_workingtree_to_test_tree': return_parameter,
405
('WorkingTreeFormat3',
406
{'bzrdir_format': formats[1]._matchingbzrdir,
407
'transport_readonly_server': 'b',
408
'transport_server': 'a',
409
'workingtree_format': formats[1],
410
'_workingtree_to_test_tree': return_parameter,
413
{'_workingtree_to_test_tree': revision_tree_from_workingtree,
414
'bzrdir_format': default_wt_format._matchingbzrdir,
415
'transport_readonly_server': 'b',
416
'transport_server': 'a',
417
'workingtree_format': default_wt_format,
419
('DirStateRevisionTree,WT4',
420
{'_workingtree_to_test_tree': _dirstate_tree_from_workingtree,
421
'bzrdir_format': wt4_format._matchingbzrdir,
422
'transport_readonly_server': 'b',
423
'transport_server': 'a',
424
'workingtree_format': wt4_format,
426
('DirStateRevisionTree,WT5',
427
{'_workingtree_to_test_tree': _dirstate_tree_from_workingtree,
428
'bzrdir_format': wt5_format._matchingbzrdir,
429
'transport_readonly_server': 'b',
430
'transport_server': 'a',
431
'workingtree_format': wt5_format,
434
{'_workingtree_to_test_tree': preview_tree_pre,
435
'bzrdir_format': default_wt_format._matchingbzrdir,
436
'transport_readonly_server': 'b',
437
'transport_server': 'a',
438
'workingtree_format': default_wt_format}),
440
{'_workingtree_to_test_tree': preview_tree_post,
441
'bzrdir_format': default_wt_format._matchingbzrdir,
442
'transport_readonly_server': 'b',
443
'transport_server': 'a',
444
'workingtree_format': default_wt_format}),
446
self.assertEqual(expected_scenarios, scenarios)
449
class TestInterTreeScenarios(TestCase):
450
450
"""A group of tests that test the InterTreeTestAdapter."""
452
def test_adapted_tests(self):
452
def test_scenarios(self):
453
453
# check that constructor parameters are passed through to the adapted
455
455
# for InterTree tests we want the machinery to bring up two trees in
464
464
revision_tree_from_workingtree
466
466
from bzrlib.tests.intertree_implementations import (
467
InterTreeTestProviderAdapter,
469
469
from bzrlib.workingtree import WorkingTreeFormat2, WorkingTreeFormat3
470
input_test = TestInterTreeProviderAdapter(
471
"test_adapted_tests")
470
input_test = TestInterTreeScenarios(
474
474
format1 = WorkingTreeFormat2()
475
475
format2 = WorkingTreeFormat3()
476
476
formats = [("1", str, format1, format2, "converter1"),
477
477
("2", int, format2, format1, "converter2")]
478
adapter = InterTreeTestProviderAdapter(server1, server2, formats)
479
suite = adapter.adapt(input_test)
480
tests = list(iter(suite))
481
self.assertEqual(2, len(tests))
482
self.assertEqual(tests[0].intertree_class, formats[0][1])
483
self.assertEqual(tests[0].workingtree_format, formats[0][2])
484
self.assertEqual(tests[0].workingtree_format_to, formats[0][3])
485
self.assertEqual(tests[0].mutable_trees_to_test_trees, formats[0][4])
486
self.assertEqual(tests[0]._workingtree_to_test_tree, return_parameter)
487
self.assertEqual(tests[0].transport_server, server1)
488
self.assertEqual(tests[0].transport_readonly_server, server2)
489
self.assertEqual(tests[1].intertree_class, formats[1][1])
490
self.assertEqual(tests[1].workingtree_format, formats[1][2])
491
self.assertEqual(tests[1].workingtree_format_to, formats[1][3])
492
self.assertEqual(tests[1].mutable_trees_to_test_trees, formats[1][4])
493
self.assertEqual(tests[1]._workingtree_to_test_tree, return_parameter)
494
self.assertEqual(tests[1].transport_server, server1)
495
self.assertEqual(tests[1].transport_readonly_server, server2)
478
scenarios = make_scenarios(server1, server2, formats)
479
self.assertEqual(2, len(scenarios))
480
expected_scenarios = [
482
"bzrdir_format": format1._matchingbzrdir,
483
"intertree_class": formats[0][1],
484
"workingtree_format": formats[0][2],
485
"workingtree_format_to": formats[0][3],
486
"mutable_trees_to_test_trees": formats[0][4],
487
"_workingtree_to_test_tree": return_parameter,
488
"transport_server": server1,
489
"transport_readonly_server": server2,
492
"bzrdir_format": format2._matchingbzrdir,
493
"intertree_class": formats[1][1],
494
"workingtree_format": formats[1][2],
495
"workingtree_format_to": formats[1][3],
496
"mutable_trees_to_test_trees": formats[1][4],
497
"_workingtree_to_test_tree": return_parameter,
498
"transport_server": server1,
499
"transport_readonly_server": server2,
502
self.assertEqual(scenarios, expected_scenarios)
498
505
class TestTestCaseInTempDir(TestCaseInTempDir):