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 get_transport_test_permutations function.
144
# called by the adapter get_transport_test_permutations method.
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 get_transport_test_permutations
150
import TransportTestProviderAdapter
151
adapter = TransportTestProviderAdapter()
151
152
self.assertEqual(sample_permutation,
152
get_transport_test_permutations(MockModule()))
153
adapter.get_transport_test_permutations(MockModule()))
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.
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.
159
160
from bzrlib.tests.test_transport_implementations \
160
import transport_test_permutations
161
import TransportTestProviderAdapter
161
162
from bzrlib.transport import _get_transport_modules
162
163
modules = _get_transport_modules()
163
164
permutation_count = 0
168
169
__import__(module))())
169
170
except errors.DependencyNotPresent:
171
scenarios = transport_test_permutations()
172
self.assertEqual(permutation_count, len(scenarios))
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)))))
174
def test_scenarios_include_transport_class(self):
178
def test_adapter_sets_transport_class(self):
179
# Check that the test adapter inserts a transport and server into the
175
182
# This test used to know about all the possible transports and the
176
183
# order they were returned but that seems overly brittle (mbp
178
185
from bzrlib.tests.test_transport_implementations \
179
import transport_test_permutations
180
scenarios = transport_test_permutations()
186
import TransportTestProviderAdapter
187
scenarios = TransportTestProviderAdapter().scenarios
181
188
# there are at least that many builtin transports
182
189
self.assertTrue(len(scenarios) > 6)
183
190
one_scenario = scenarios[0]
281
class TestTestScenarioApplication(TestCase):
293
class TestTestScenarioApplier(TestCase):
282
294
"""Tests for the test adaption facilities."""
284
def test_apply_scenario(self):
285
from bzrlib.tests import apply_scenario
286
input_test = TestTestScenarioApplication("test_apply_scenario")
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()
287
314
# setup two adapted tests
288
adapted_test1 = apply_scenario(input_test,
315
adapted_test1 = adapter.adapt_test_to_scenario(input_test,
290
317
{"bzrdir_format":"bzr_format",
291
318
"repository_format":"repo_fmt",
292
319
"transport_server":"transport_server",
293
320
"transport_readonly_server":"readonly-server"}))
294
adapted_test2 = apply_scenario(input_test,
321
adapted_test2 = adapter.adapt_test_to_scenario(input_test,
295
322
("new id 2", {"bzrdir_format":None}))
296
323
# input_test should have been altered.
297
324
self.assertRaises(AttributeError, getattr, input_test, "bzrdir_format")
304
331
self.assertEqual("readonly-server",
305
332
adapted_test1.transport_readonly_server)
306
333
self.assertEqual(
307
"bzrlib.tests.test_selftest.TestTestScenarioApplication."
308
"test_apply_scenario(new id)",
334
"bzrlib.tests.test_selftest.TestTestScenarioApplier."
335
"test_adapt_test_to_scenario(new id)",
309
336
adapted_test1.id())
310
337
self.assertEqual(None, adapted_test2.bzrdir_format)
311
338
self.assertEqual(
312
"bzrlib.tests.test_selftest.TestTestScenarioApplication."
313
"test_apply_scenario(new id 2)",
339
"bzrlib.tests.test_selftest.TestTestScenarioApplier."
340
"test_adapt_test_to_scenario(new id 2)",
314
341
adapted_test2.id())
317
class TestInterRepositoryScenarios(TestCase):
344
class TestInterRepositoryProviderAdapter(TestCase):
345
"""A group of tests that test the InterRepository test adapter."""
319
def test_scenarios(self):
347
def test_adapted_tests(self):
320
348
# check that constructor parameters are passed through to the adapted
322
350
from bzrlib.tests.interrepository_implementations import \
351
InterRepositoryTestProviderAdapter
326
354
formats = [(str, "C1", "C2"), (int, "D1", "D2")]
327
scenarios = make_scenarios(server1, server2, formats)
355
adapter = InterRepositoryTestProviderAdapter(server1, server2, formats)
328
356
self.assertEqual([
330
358
{'interrepo_class': str,
364
393
'transport_readonly_server': 'b',
365
394
'transport_server': 'a',
366
395
'workingtree_format': formats[1]})],
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.
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.
380
410
from bzrlib.tests.tree_implementations import (
381
_dirstate_tree_from_workingtree,
411
TreeTestProviderAdapter,
385
412
return_parameter,
386
413
revision_tree_from_workingtree
415
input_test = TestTreeProviderAdapter(
416
"test_adapted_tests")
390
419
formats = [workingtree.WorkingTreeFormat2(),
391
420
workingtree.WorkingTreeFormat3(),]
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):
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):
450
450
"""A group of tests that test the InterTreeTestAdapter."""
452
def test_scenarios(self):
452
def test_adapted_tests(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 = TestInterTreeScenarios(
470
input_test = TestInterTreeProviderAdapter(
471
"test_adapted_tests")
474
474
format1 = WorkingTreeFormat2()
475
475
format2 = WorkingTreeFormat3()
476
476
formats = [("1", str, format1, format2, "converter1"),
477
477
("2", int, format2, format1, "converter2")]
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)
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)
505
498
class TestTestCaseInTempDir(TestCaseInTempDir):
1353
1345
class TestTestCase(TestCase):
1354
1346
"""Tests that test the core bzrlib TestCase."""
1356
def test_assertLength_matches_empty(self):
1358
self.assertLength(0, a_list)
1360
def test_assertLength_matches_nonempty(self):
1362
self.assertLength(3, a_list)
1364
def test_assertLength_fails_different(self):
1366
self.assertRaises(AssertionError, self.assertLength, 1, a_list)
1368
def test_assertLength_shows_sequence_in_failure(self):
1370
exception = self.assertRaises(AssertionError, self.assertLength, 2,
1372
self.assertEqual('Incorrect length: wanted 2, got 3 for [1, 2, 3]',
1375
def test_base_setUp_not_called_causes_failure(self):
1376
class TestCaseWithBrokenSetUp(TestCase):
1378
pass # does not call TestCase.setUp
1381
test = TestCaseWithBrokenSetUp('test_foo')
1382
result = unittest.TestResult()
1384
self.assertFalse(result.wasSuccessful())
1385
self.assertEqual(1, result.testsRun)
1387
def test_base_tearDown_not_called_causes_failure(self):
1388
class TestCaseWithBrokenTearDown(TestCase):
1390
pass # does not call TestCase.tearDown
1393
test = TestCaseWithBrokenTearDown('test_foo')
1394
result = unittest.TestResult()
1396
self.assertFalse(result.wasSuccessful())
1397
self.assertEqual(1, result.testsRun)
1399
1348
def test_debug_flags_sanitised(self):
1400
1349
"""The bzrlib debug flags should be sanitised by setUp."""
1401
1350
if 'allow_debug' in tests.selftest_debug_flags:
1697
1645
def test_applyDeprecated_not_deprecated(self):
1698
1646
sample_object = ApplyDeprecatedHelper()
1699
1647
# calling an undeprecated callable raises an assertion
1700
self.assertRaises(AssertionError, self.applyDeprecated,
1701
deprecated_in((0, 11, 0)),
1648
self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
1702
1649
sample_object.sample_normal_method)
1703
self.assertRaises(AssertionError, self.applyDeprecated,
1704
deprecated_in((0, 11, 0)),
1650
self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
1705
1651
sample_undeprecated_function, "a param value")
1706
1652
# calling a deprecated callable (function or method) with the wrong
1707
1653
# expected deprecation fails.
1708
self.assertRaises(AssertionError, self.applyDeprecated,
1709
deprecated_in((0, 10, 0)),
1654
self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
1710
1655
sample_object.sample_deprecated_method, "a param value")
1711
self.assertRaises(AssertionError, self.applyDeprecated,
1712
deprecated_in((0, 10, 0)),
1656
self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
1713
1657
sample_deprecated_function)
1714
1658
# calling a deprecated callable (function or method) with the right
1715
1659
# expected deprecation returns the functions result.
1716
self.assertEqual("a param value",
1717
self.applyDeprecated(deprecated_in((0, 11, 0)),
1660
self.assertEqual("a param value", self.applyDeprecated(zero_eleven,
1718
1661
sample_object.sample_deprecated_method, "a param value"))
1719
self.assertEqual(2, self.applyDeprecated(deprecated_in((0, 11, 0)),
1662
self.assertEqual(2, self.applyDeprecated(zero_eleven,
1720
1663
sample_deprecated_function))
1721
1664
# calling a nested deprecation with the wrong deprecation version
1722
1665
# fails even if a deeper nested function was deprecated with the
1723
1666
# supplied version.
1724
1667
self.assertRaises(AssertionError, self.applyDeprecated,
1725
deprecated_in((0, 11, 0)), sample_object.sample_nested_deprecation)
1668
zero_eleven, sample_object.sample_nested_deprecation)
1726
1669
# calling a nested deprecation with the right deprecation value
1727
1670
# returns the calls result.
1728
self.assertEqual(2, self.applyDeprecated(deprecated_in((0, 10, 0)),
1671
self.assertEqual(2, self.applyDeprecated(zero_ten,
1729
1672
sample_object.sample_nested_deprecation))
1731
1674
def test_callDeprecated(self):