142
116
def test_get_transport_permutations(self):
143
117
# this checks that get_test_permutations defined by the module is
144
# called by the adapter get_transport_test_permutations method.
118
# called by the get_transport_test_permutations function.
145
119
class MockModule(object):
146
120
def get_test_permutations(self):
147
121
return sample_permutation
148
122
sample_permutation = [(1,2), (3,4)]
149
from bzrlib.tests.test_transport_implementations \
150
import TransportTestProviderAdapter
151
adapter = TransportTestProviderAdapter()
123
from bzrlib.tests.per_transport import get_transport_test_permutations
152
124
self.assertEqual(sample_permutation,
153
adapter.get_transport_test_permutations(MockModule()))
125
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.
160
from bzrlib.tests.test_transport_implementations \
161
import TransportTestProviderAdapter
127
def test_scenarios_invlude_all_modules(self):
128
# this checks that the scenario generator returns as many permutations
129
# as there are in all the registered transport modules - we assume if
130
# this matches its probably doing the right thing especially in
131
# combination with the tests for setting the right classes below.
132
from bzrlib.tests.per_transport import transport_test_permutations
162
133
from bzrlib.transport import _get_transport_modules
163
134
modules = _get_transport_modules()
164
135
permutation_count = 0
169
140
__import__(module))())
170
141
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)))))
143
scenarios = transport_test_permutations()
144
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
146
def test_scenarios_include_transport_class(self):
182
147
# This test used to know about all the possible transports and the
183
148
# order they were returned but that seems overly brittle (mbp
185
from bzrlib.tests.test_transport_implementations \
186
import TransportTestProviderAdapter
187
scenarios = TransportTestProviderAdapter().scenarios
150
from bzrlib.tests.per_transport import transport_test_permutations
151
scenarios = transport_test_permutations()
188
152
# there are at least that many builtin transports
189
153
self.assertTrue(len(scenarios) > 6)
190
154
one_scenario = scenarios[0]
293
class TestTestScenarioApplier(TestCase):
252
class TestTestScenarioApplication(tests.TestCase):
294
253
"""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()
255
def test_apply_scenario(self):
256
from bzrlib.tests import apply_scenario
257
input_test = TestTestScenarioApplication("test_apply_scenario")
314
258
# setup two adapted tests
315
adapted_test1 = adapter.adapt_test_to_scenario(input_test,
259
adapted_test1 = apply_scenario(input_test,
317
261
{"bzrdir_format":"bzr_format",
318
262
"repository_format":"repo_fmt",
319
263
"transport_server":"transport_server",
320
264
"transport_readonly_server":"readonly-server"}))
321
adapted_test2 = adapter.adapt_test_to_scenario(input_test,
265
adapted_test2 = apply_scenario(input_test,
322
266
("new id 2", {"bzrdir_format":None}))
323
267
# input_test should have been altered.
324
268
self.assertRaises(AttributeError, getattr, input_test, "bzrdir_format")
331
275
self.assertEqual("readonly-server",
332
276
adapted_test1.transport_readonly_server)
333
277
self.assertEqual(
334
"bzrlib.tests.test_selftest.TestTestScenarioApplier."
335
"test_adapt_test_to_scenario(new id)",
278
"bzrlib.tests.test_selftest.TestTestScenarioApplication."
279
"test_apply_scenario(new id)",
336
280
adapted_test1.id())
337
281
self.assertEqual(None, adapted_test2.bzrdir_format)
338
282
self.assertEqual(
339
"bzrlib.tests.test_selftest.TestTestScenarioApplier."
340
"test_adapt_test_to_scenario(new id 2)",
283
"bzrlib.tests.test_selftest.TestTestScenarioApplication."
284
"test_apply_scenario(new id 2)",
341
285
adapted_test2.id())
344
class TestInterRepositoryProviderAdapter(TestCase):
345
"""A group of tests that test the InterRepository test adapter."""
288
class TestInterRepositoryScenarios(tests.TestCase):
347
def test_adapted_tests(self):
290
def test_scenarios(self):
348
291
# check that constructor parameters are passed through to the adapted
350
from bzrlib.tests.interrepository_implementations import \
351
InterRepositoryTestProviderAdapter
293
from bzrlib.tests.per_interrepository import make_scenarios
354
296
formats = [(str, "C1", "C2"), (int, "D1", "D2")]
355
adapter = InterRepositoryTestProviderAdapter(server1, server2, formats)
297
scenarios = make_scenarios(server1, server2, formats)
356
298
self.assertEqual([
358
300
{'interrepo_class': str,
366
308
'repository_format_to': 'D2',
367
309
'transport_readonly_server': 'b',
368
310
'transport_server': 'a'})],
369
adapter.formats_to_scenarios(formats))
372
class TestWorkingTreeProviderAdapter(TestCase):
373
"""A group of tests that test the workingtree implementation test adapter."""
314
class TestWorkingTreeScenarios(tests.TestCase):
375
316
def test_scenarios(self):
376
317
# check that constructor parameters are passed through to the adapted
378
from bzrlib.tests.workingtree_implementations \
379
import WorkingTreeTestProviderAdapter
319
from bzrlib.tests.per_workingtree import make_scenarios
382
322
formats = [workingtree.WorkingTreeFormat2(),
383
323
workingtree.WorkingTreeFormat3(),]
384
adapter = WorkingTreeTestProviderAdapter(server1, server2, formats)
324
scenarios = make_scenarios(server1, server2, formats)
385
325
self.assertEqual([
386
326
('WorkingTreeFormat2',
387
327
{'bzrdir_format': formats[0]._matchingbzrdir,
393
333
'transport_readonly_server': 'b',
394
334
'transport_server': 'a',
395
335
'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.
410
from bzrlib.tests.tree_implementations import (
411
TreeTestProviderAdapter,
339
class TestTreeScenarios(tests.TestCase):
341
def test_scenarios(self):
342
# the tree implementation scenario generator is meant to setup one
343
# instance for each working tree format, and one additional instance
344
# that will use the default wt format, but create a revision tree for
345
# the tests. this means that the wt ones should have the
346
# workingtree_to_test_tree attribute set to 'return_parameter' and the
347
# revision one set to revision_tree_from_workingtree.
349
from bzrlib.tests.per_tree import (
350
_dirstate_tree_from_workingtree,
412
354
return_parameter,
413
355
revision_tree_from_workingtree
415
input_test = TestTreeProviderAdapter(
416
"test_adapted_tests")
419
359
formats = [workingtree.WorkingTreeFormat2(),
420
360
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):
361
scenarios = make_scenarios(server1, server2, formats)
362
self.assertEqual(7, len(scenarios))
363
default_wt_format = workingtree.WorkingTreeFormat4._default_format
364
wt4_format = workingtree.WorkingTreeFormat4()
365
wt5_format = workingtree.WorkingTreeFormat5()
366
expected_scenarios = [
367
('WorkingTreeFormat2',
368
{'bzrdir_format': formats[0]._matchingbzrdir,
369
'transport_readonly_server': 'b',
370
'transport_server': 'a',
371
'workingtree_format': formats[0],
372
'_workingtree_to_test_tree': return_parameter,
374
('WorkingTreeFormat3',
375
{'bzrdir_format': formats[1]._matchingbzrdir,
376
'transport_readonly_server': 'b',
377
'transport_server': 'a',
378
'workingtree_format': formats[1],
379
'_workingtree_to_test_tree': return_parameter,
382
{'_workingtree_to_test_tree': revision_tree_from_workingtree,
383
'bzrdir_format': default_wt_format._matchingbzrdir,
384
'transport_readonly_server': 'b',
385
'transport_server': 'a',
386
'workingtree_format': default_wt_format,
388
('DirStateRevisionTree,WT4',
389
{'_workingtree_to_test_tree': _dirstate_tree_from_workingtree,
390
'bzrdir_format': wt4_format._matchingbzrdir,
391
'transport_readonly_server': 'b',
392
'transport_server': 'a',
393
'workingtree_format': wt4_format,
395
('DirStateRevisionTree,WT5',
396
{'_workingtree_to_test_tree': _dirstate_tree_from_workingtree,
397
'bzrdir_format': wt5_format._matchingbzrdir,
398
'transport_readonly_server': 'b',
399
'transport_server': 'a',
400
'workingtree_format': wt5_format,
403
{'_workingtree_to_test_tree': preview_tree_pre,
404
'bzrdir_format': default_wt_format._matchingbzrdir,
405
'transport_readonly_server': 'b',
406
'transport_server': 'a',
407
'workingtree_format': default_wt_format}),
409
{'_workingtree_to_test_tree': preview_tree_post,
410
'bzrdir_format': default_wt_format._matchingbzrdir,
411
'transport_readonly_server': 'b',
412
'transport_server': 'a',
413
'workingtree_format': default_wt_format}),
415
self.assertEqual(expected_scenarios, scenarios)
418
class TestInterTreeScenarios(tests.TestCase):
450
419
"""A group of tests that test the InterTreeTestAdapter."""
452
def test_adapted_tests(self):
421
def test_scenarios(self):
453
422
# check that constructor parameters are passed through to the adapted
455
424
# for InterTree tests we want the machinery to bring up two trees in
459
428
# unlike the TestProviderAdapter we dont want to automatically add a
460
429
# parameterized one for WorkingTree - the optimisers will tell us what
462
from bzrlib.tests.tree_implementations import (
431
from bzrlib.tests.per_tree import (
463
432
return_parameter,
464
433
revision_tree_from_workingtree
466
from bzrlib.tests.intertree_implementations import (
467
InterTreeTestProviderAdapter,
435
from bzrlib.tests.per_intertree import (
469
438
from bzrlib.workingtree import WorkingTreeFormat2, WorkingTreeFormat3
470
input_test = TestInterTreeProviderAdapter(
471
"test_adapted_tests")
439
input_test = TestInterTreeScenarios(
474
443
format1 = WorkingTreeFormat2()
475
444
format2 = WorkingTreeFormat3()
476
445
formats = [("1", str, format1, format2, "converter1"),
477
446
("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)
498
class TestTestCaseInTempDir(TestCaseInTempDir):
447
scenarios = make_scenarios(server1, server2, formats)
448
self.assertEqual(2, len(scenarios))
449
expected_scenarios = [
451
"bzrdir_format": format1._matchingbzrdir,
452
"intertree_class": formats[0][1],
453
"workingtree_format": formats[0][2],
454
"workingtree_format_to": formats[0][3],
455
"mutable_trees_to_test_trees": formats[0][4],
456
"_workingtree_to_test_tree": return_parameter,
457
"transport_server": server1,
458
"transport_readonly_server": server2,
461
"bzrdir_format": format2._matchingbzrdir,
462
"intertree_class": formats[1][1],
463
"workingtree_format": formats[1][2],
464
"workingtree_format_to": formats[1][3],
465
"mutable_trees_to_test_trees": formats[1][4],
466
"_workingtree_to_test_tree": return_parameter,
467
"transport_server": server1,
468
"transport_readonly_server": server2,
471
self.assertEqual(scenarios, expected_scenarios)
474
class TestTestCaseInTempDir(tests.TestCaseInTempDir):
500
476
def test_home_is_not_working(self):
501
477
self.assertNotEqual(self.test_dir, self.test_home_dir)
829
817
def test_known_failure(self):
830
818
"""A KnownFailure being raised should trigger several result actions."""
831
class InstrumentedTestResult(ExtendedTestResult):
819
class InstrumentedTestResult(tests.ExtendedTestResult):
821
def startTests(self): pass
833
822
def report_test_start(self, test): pass
834
823
def report_known_failure(self, test, err):
835
824
self._call = test, err
836
825
result = InstrumentedTestResult(None, None, None, None)
837
826
def test_function():
838
raise KnownFailure('failed!')
827
raise tests.KnownFailure('failed!')
839
828
test = unittest.FunctionTestCase(test_function)
841
830
# it should invoke 'report_known_failure'.
842
831
self.assertEqual(2, len(result._call))
843
832
self.assertEqual(test, result._call[0])
844
self.assertEqual(KnownFailure, result._call[1][0])
845
self.assertIsInstance(result._call[1][1], KnownFailure)
833
self.assertEqual(tests.KnownFailure, result._call[1][0])
834
self.assertIsInstance(result._call[1][1], tests.KnownFailure)
846
835
# we dont introspec the traceback, if the rest is ok, it would be
847
836
# exceptional for it not to be.
848
837
# it should update the known_failure_count on the object.
1051
1057
This current saves and restores:
1052
1058
TestCaseInTempDir.TEST_ROOT
1054
There should be no tests in this file that use bzrlib.tests.TextTestRunner
1055
without using this convenience method, because of our use of global state.
1060
There should be no tests in this file that use
1061
bzrlib.tests.TextTestRunner without using this convenience method,
1062
because of our use of global state.
1057
old_root = TestCaseInTempDir.TEST_ROOT
1064
old_root = tests.TestCaseInTempDir.TEST_ROOT
1059
TestCaseInTempDir.TEST_ROOT = None
1066
tests.TestCaseInTempDir.TEST_ROOT = None
1060
1067
return testrunner.run(test)
1062
TestCaseInTempDir.TEST_ROOT = old_root
1069
tests.TestCaseInTempDir.TEST_ROOT = old_root
1064
1071
def test_known_failure_failed_run(self):
1065
1072
# run a test that generates a known failure which should be printed in
1066
1073
# the final output when real failures occur.
1067
1074
def known_failure_test():
1068
raise KnownFailure('failed')
1075
raise tests.KnownFailure('failed')
1069
1076
test = unittest.TestSuite()
1070
1077
test.addTest(unittest.FunctionTestCase(known_failure_test))
1071
1078
def failing_test():
1072
1079
raise AssertionError('foo')
1073
1080
test.addTest(unittest.FunctionTestCase(failing_test))
1074
1081
stream = StringIO()
1075
runner = TextTestRunner(stream=stream)
1082
runner = tests.TextTestRunner(stream=stream)
1076
1083
result = self.run_test_runner(runner, test)
1077
1084
lines = stream.getvalue().splitlines()
1078
1085
self.assertEqual([
1342
1350
class _TestException(Exception):
1345
class TestTestCase(TestCase):
1353
class TestTestCase(tests.TestCase):
1346
1354
"""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(tests.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(tests.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)
1348
1399
def test_debug_flags_sanitised(self):
1349
1400
"""The bzrlib debug flags should be sanitised by setUp."""
1350
1401
if 'allow_debug' in tests.selftest_debug_flags:
1351
raise TestNotApplicable(
1402
raise tests.TestNotApplicable(
1352
1403
'-Eallow_debug option prevents debug flag sanitisation')
1353
1404
# we could set something and run a test that will check
1354
1405
# it gets santised, but this is probably sufficient for now:
1475
1525
def test_knownFailure(self):
1476
1526
"""Self.knownFailure() should raise a KnownFailure exception."""
1477
self.assertRaises(KnownFailure, self.knownFailure, "A Failure")
1527
self.assertRaises(tests.KnownFailure, self.knownFailure, "A Failure")
1479
1529
def test_requireFeature_available(self):
1480
1530
"""self.requireFeature(available) is a no-op."""
1481
class Available(Feature):
1531
class Available(tests.Feature):
1482
1532
def _probe(self):return True
1483
1533
feature = Available()
1484
1534
self.requireFeature(feature)
1486
1536
def test_requireFeature_unavailable(self):
1487
1537
"""self.requireFeature(unavailable) raises UnavailableFeature."""
1488
class Unavailable(Feature):
1538
class Unavailable(tests.Feature):
1489
1539
def _probe(self):return False
1490
1540
feature = Unavailable()
1491
self.assertRaises(UnavailableFeature, self.requireFeature, feature)
1541
self.assertRaises(tests.UnavailableFeature,
1542
self.requireFeature, feature)
1493
1544
def test_run_no_parameters(self):
1494
1545
test = SampleTestCase('_test_pass')
1624
1676
def sample_normal_method(self):
1625
1677
"""A undeprecated method."""
1627
@symbol_versioning.deprecated_method(zero_ten)
1679
@deprecated_method(deprecated_in((0, 10, 0)))
1628
1680
def sample_nested_deprecation(self):
1629
1681
return sample_deprecated_function()
1632
class TestExtraAssertions(TestCase):
1684
class TestExtraAssertions(tests.TestCase):
1633
1685
"""Tests for new test assertions in bzrlib test suite"""
1635
1687
def test_assert_isinstance(self):
1636
1688
self.assertIsInstance(2, int)
1637
1689
self.assertIsInstance(u'', basestring)
1638
self.assertRaises(AssertionError, self.assertIsInstance, None, int)
1690
e = self.assertRaises(AssertionError, self.assertIsInstance, None, int)
1691
self.assertEquals(str(e),
1692
"None is an instance of <type 'NoneType'> rather than <type 'int'>")
1639
1693
self.assertRaises(AssertionError, self.assertIsInstance, 23.3, int)
1694
e = self.assertRaises(AssertionError,
1695
self.assertIsInstance, None, int, "it's just not")
1696
self.assertEquals(str(e),
1697
"None is an instance of <type 'NoneType'> rather than <type 'int'>"
1641
1700
def test_assertEndsWith(self):
1642
1701
self.assertEndsWith('foo', 'oo')
1645
1704
def test_applyDeprecated_not_deprecated(self):
1646
1705
sample_object = ApplyDeprecatedHelper()
1647
1706
# calling an undeprecated callable raises an assertion
1648
self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
1707
self.assertRaises(AssertionError, self.applyDeprecated,
1708
deprecated_in((0, 11, 0)),
1649
1709
sample_object.sample_normal_method)
1650
self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
1710
self.assertRaises(AssertionError, self.applyDeprecated,
1711
deprecated_in((0, 11, 0)),
1651
1712
sample_undeprecated_function, "a param value")
1652
1713
# calling a deprecated callable (function or method) with the wrong
1653
1714
# expected deprecation fails.
1654
self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
1715
self.assertRaises(AssertionError, self.applyDeprecated,
1716
deprecated_in((0, 10, 0)),
1655
1717
sample_object.sample_deprecated_method, "a param value")
1656
self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
1718
self.assertRaises(AssertionError, self.applyDeprecated,
1719
deprecated_in((0, 10, 0)),
1657
1720
sample_deprecated_function)
1658
1721
# calling a deprecated callable (function or method) with the right
1659
1722
# expected deprecation returns the functions result.
1660
self.assertEqual("a param value", self.applyDeprecated(zero_eleven,
1723
self.assertEqual("a param value",
1724
self.applyDeprecated(deprecated_in((0, 11, 0)),
1661
1725
sample_object.sample_deprecated_method, "a param value"))
1662
self.assertEqual(2, self.applyDeprecated(zero_eleven,
1726
self.assertEqual(2, self.applyDeprecated(deprecated_in((0, 11, 0)),
1663
1727
sample_deprecated_function))
1664
1728
# calling a nested deprecation with the wrong deprecation version
1665
1729
# fails even if a deeper nested function was deprecated with the
1666
1730
# supplied version.
1667
1731
self.assertRaises(AssertionError, self.applyDeprecated,
1668
zero_eleven, sample_object.sample_nested_deprecation)
1732
deprecated_in((0, 11, 0)), sample_object.sample_nested_deprecation)
1669
1733
# calling a nested deprecation with the right deprecation value
1670
1734
# returns the calls result.
1671
self.assertEqual(2, self.applyDeprecated(zero_ten,
1735
self.assertEqual(2, self.applyDeprecated(deprecated_in((0, 10, 0)),
1672
1736
sample_object.sample_nested_deprecation))
1674
1738
def test_callDeprecated(self):
1825
1890
def test_condition_id_re(self):
1826
1891
test_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1827
1892
'test_condition_id_re')
1828
filtered_suite = filter_suite_by_condition(self.suite,
1829
condition_id_re('test_condition_id_re'))
1893
filtered_suite = tests.filter_suite_by_condition(
1894
self.suite, tests.condition_id_re('test_condition_id_re'))
1830
1895
self.assertEqual([test_name], _test_ids(filtered_suite))
1832
1897
def test_condition_id_in_list(self):
1833
1898
test_names = ['bzrlib.tests.test_selftest.TestSelftestFiltering.'
1834
1899
'test_condition_id_in_list']
1835
1900
id_list = tests.TestIdList(test_names)
1836
filtered_suite = filter_suite_by_condition(
1901
filtered_suite = tests.filter_suite_by_condition(
1837
1902
self.suite, tests.condition_id_in_list(id_list))
1838
1903
my_pattern = 'TestSelftestFiltering.*test_condition_id_in_list'
1839
re_filtered = filter_suite_by_re(self.suite, my_pattern)
1904
re_filtered = tests.filter_suite_by_re(self.suite, my_pattern)
1840
1905
self.assertEqual(_test_ids(re_filtered), _test_ids(filtered_suite))
1842
1907
def test_condition_id_startswith(self):
1846
1911
test_names = [ klass + 'test_condition_id_in_list',
1847
1912
klass + 'test_condition_id_startswith',
1849
filtered_suite = filter_suite_by_condition(
1914
filtered_suite = tests.filter_suite_by_condition(
1850
1915
self.suite, tests.condition_id_startswith([start1, start2]))
1851
1916
self.assertEqual(test_names, _test_ids(filtered_suite))
1853
1918
def test_condition_isinstance(self):
1854
filtered_suite = filter_suite_by_condition(self.suite,
1855
condition_isinstance(self.__class__))
1919
filtered_suite = tests.filter_suite_by_condition(
1920
self.suite, tests.condition_isinstance(self.__class__))
1856
1921
class_pattern = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
1857
re_filtered = filter_suite_by_re(self.suite, class_pattern)
1922
re_filtered = tests.filter_suite_by_re(self.suite, class_pattern)
1858
1923
self.assertEqual(_test_ids(re_filtered), _test_ids(filtered_suite))
1860
1925
def test_exclude_tests_by_condition(self):
1861
1926
excluded_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1862
1927
'test_exclude_tests_by_condition')
1863
filtered_suite = exclude_tests_by_condition(self.suite,
1928
filtered_suite = tests.exclude_tests_by_condition(self.suite,
1864
1929
lambda x:x.id() == excluded_name)
1865
1930
self.assertEqual(len(self.all_names) - 1,
1866
1931
filtered_suite.countTestCases())
2201
class TestTestSuite(tests.TestCase):
2203
def test_test_suite(self):
2204
# This test is slow, so we do a single test with one test in each
2208
'bzrlib.tests.blackbox.test_branch.TestBranch.test_branch',
2209
('bzrlib.tests.per_transport.TransportTests'
2210
'.test_abspath(LocalURLServer)'),
2211
'bzrlib.tests.test_selftest.TestTestSuite.test_test_suite',
2212
# modules_to_doctest
2213
'bzrlib.timestamp.format_highres_date',
2214
# plugins can't be tested that way since selftest may be run with
2217
suite = tests.test_suite(test_list)
2218
self.assertEquals(test_list, _test_ids(suite))
2220
def test_test_suite_list_and_start(self):
2221
test_list = ['bzrlib.tests.test_selftest.TestTestSuite.test_test_suite']
2222
suite = tests.test_suite(test_list,
2223
['bzrlib.tests.test_selftest.TestTestSuite'])
2224
# test_test_suite_list_and_start is not included
2225
self.assertEquals(test_list, _test_ids(suite))
2151
2228
class TestLoadTestIdList(tests.TestCaseInTempDir):
2153
2230
def _create_test_list_file(self, file_name, content):
2276
2353
self.assertEquals('bzrlib.plugins', tpr.resolve_alias('bp'))
2279
class TestRunSuite(TestCase):
2356
class TestRunSuite(tests.TestCase):
2281
2358
def test_runner_class(self):
2282
2359
"""run_suite accepts and uses a runner_class keyword argument."""
2283
class Stub(TestCase):
2360
class Stub(tests.TestCase):
2284
2361
def test_foo(self):
2286
2363
suite = Stub("test_foo")
2288
class MyRunner(TextTestRunner):
2365
class MyRunner(tests.TextTestRunner):
2289
2366
def run(self, test):
2290
2367
calls.append(test)
2291
return ExtendedTestResult(self.stream, self.descriptions,
2293
run_suite(suite, runner_class=MyRunner)
2368
return tests.ExtendedTestResult(self.stream, self.descriptions,
2370
tests.run_suite(suite, runner_class=MyRunner, stream=StringIO())
2294
2371
self.assertEqual(calls, [suite])
2373
def test_done(self):
2374
"""run_suite should call result.done()"""
2376
def one_more_call(): self.calls += 1
2377
def test_function():
2379
test = unittest.FunctionTestCase(test_function)
2380
class InstrumentedTestResult(tests.ExtendedTestResult):
2381
def done(self): one_more_call()
2382
class MyRunner(tests.TextTestRunner):
2383
def run(self, test):
2384
return InstrumentedTestResult(self.stream, self.descriptions,
2386
tests.run_suite(test, runner_class=MyRunner, stream=StringIO())
2387
self.assertEquals(1, self.calls)