~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-03-06 06:48:25 UTC
  • mfrom: (4070.8.6 debug-config)
  • Revision ID: pqm@pqm.ubuntu.com-20090306064825-kbpwggw21dygeix6
(mbp) debug_flags configuration option

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Tests for the test framework."""
18
18
 
43
43
    weaverepo,
44
44
    )
45
45
from bzrlib.symbol_versioning import (
46
 
    deprecated_function,
47
 
    deprecated_in,
48
 
    deprecated_method,
 
46
    one_zero,
 
47
    zero_eleven,
 
48
    zero_ten,
49
49
    )
50
50
from bzrlib.tests import (
51
51
                          ChrootedTestCase,
129
129
        self.failUnlessExists(filename)
130
130
 
131
131
 
132
 
class TestTransportScenarios(TestCase):
 
132
class TestTransportProviderAdapter(TestCase):
133
133
    """A group of tests that test the transport implementation adaption core.
134
134
 
135
135
    This is a meta test that the tests are applied to all available
141
141
 
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()))
153
154
 
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:
170
171
                pass
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)))))
173
177
 
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
 
180
        # generated test.
 
181
        #
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
177
184
        # 20060307)
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]
188
195
                                   bzrlib.transport.Server))
189
196
 
190
197
 
191
 
class TestBranchScenarios(TestCase):
 
198
class TestBranchProviderAdapter(TestCase):
 
199
    """A group of tests that test the branch implementation test adapter."""
192
200
 
193
 
    def test_scenarios(self):
 
201
    def test_constructor(self):
194
202
        # check that constructor parameters are passed through to the adapted
195
203
        # test.
196
 
        from bzrlib.tests.branch_implementations import make_scenarios
 
204
        from bzrlib.tests.branch_implementations import BranchTestProviderAdapter
197
205
        server1 = "a"
198
206
        server2 = "b"
199
207
        formats = [("c", "C"), ("d", "D")]
200
 
        scenarios = make_scenarios(server1, server2, formats)
201
 
        self.assertEqual(2, len(scenarios))
 
208
        adapter = BranchTestProviderAdapter(server1, server2, formats)
 
209
        self.assertEqual(2, len(adapter.scenarios))
202
210
        self.assertEqual([
203
211
            ('str',
204
212
             {'branch_format': 'c',
210
218
              'bzrdir_format': 'D',
211
219
              'transport_readonly_server': 'b',
212
220
              'transport_server': 'a'})],
213
 
            scenarios)
214
 
 
215
 
 
216
 
class TestBzrDirScenarios(TestCase):
217
 
 
218
 
    def test_scenarios(self):
 
221
            adapter.scenarios)
 
222
 
 
223
 
 
224
class TestBzrDirProviderAdapter(TestCase):
 
225
    """A group of tests that test the bzr dir implementation test adapter."""
 
226
 
 
227
    def test_adapted_tests(self):
219
228
        # check that constructor parameters are passed through to the adapted
220
229
        # test.
221
 
        from bzrlib.tests.bzrdir_implementations import make_scenarios
 
230
        from bzrlib.tests.bzrdir_implementations import BzrDirTestProviderAdapter
222
231
        vfs_factory = "v"
223
232
        server1 = "a"
224
233
        server2 = "b"
225
234
        formats = ["c", "d"]
226
 
        scenarios = make_scenarios(vfs_factory, server1, server2, formats)
 
235
        adapter = BzrDirTestProviderAdapter(vfs_factory,
 
236
            server1, server2, formats)
227
237
        self.assertEqual([
228
238
            ('str',
229
239
             {'bzrdir_format': 'c',
235
245
              'transport_readonly_server': 'b',
236
246
              'transport_server': 'a',
237
247
              'vfs_transport_factory': 'v'})],
238
 
            scenarios)
239
 
 
240
 
 
241
 
class TestRepositoryScenarios(TestCase):
 
248
            adapter.scenarios)
 
249
 
 
250
 
 
251
class TestRepositoryParameterisation(TestCase):
 
252
    """A group of tests that test the repository implementation test adapter."""
242
253
 
243
254
    def test_formats_to_scenarios(self):
 
255
        """The adapter can generate all the scenarios needed."""
244
256
        from bzrlib.tests.per_repository import formats_to_scenarios
245
257
        formats = [("(c)", remote.RemoteRepositoryFormat()),
246
258
                   ("(d)", repository.format_registry.get(
278
290
            vfs_scenarios)
279
291
 
280
292
 
281
 
class TestTestScenarioApplication(TestCase):
 
293
class TestTestScenarioApplier(TestCase):
282
294
    """Tests for the test adaption facilities."""
283
295
 
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")]
 
301
        calls = []
 
302
        def capture_call(test, scenario):
 
303
            calls.append((test, scenario))
 
304
            return test
 
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)
 
309
 
 
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,
289
316
            ("new id",
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())
315
342
 
316
343
 
317
 
class TestInterRepositoryScenarios(TestCase):
 
344
class TestInterRepositoryProviderAdapter(TestCase):
 
345
    """A group of tests that test the InterRepository test adapter."""
318
346
 
319
 
    def test_scenarios(self):
 
347
    def test_adapted_tests(self):
320
348
        # check that constructor parameters are passed through to the adapted
321
349
        # test.
322
350
        from bzrlib.tests.interrepository_implementations import \
323
 
            make_scenarios
 
351
            InterRepositoryTestProviderAdapter
324
352
        server1 = "a"
325
353
        server2 = "b"
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([
329
357
            ('str,str,str',
330
358
             {'interrepo_class': str,
338
366
              'repository_format_to': 'D2',
339
367
              'transport_readonly_server': 'b',
340
368
              'transport_server': 'a'})],
341
 
            scenarios)
342
 
 
343
 
 
344
 
class TestWorkingTreeScenarios(TestCase):
 
369
            adapter.formats_to_scenarios(formats))
 
370
 
 
371
 
 
372
class TestWorkingTreeProviderAdapter(TestCase):
 
373
    """A group of tests that test the workingtree implementation test adapter."""
345
374
 
346
375
    def test_scenarios(self):
347
376
        # check that constructor parameters are passed through to the adapted
348
377
        # test.
349
378
        from bzrlib.tests.workingtree_implementations \
350
 
            import make_scenarios
 
379
            import WorkingTreeTestProviderAdapter
351
380
        server1 = "a"
352
381
        server2 = "b"
353
382
        formats = [workingtree.WorkingTreeFormat2(),
354
383
                   workingtree.WorkingTreeFormat3(),]
355
 
        scenarios = make_scenarios(server1, server2, formats)
 
384
        adapter = WorkingTreeTestProviderAdapter(server1, server2, formats)
356
385
        self.assertEqual([
357
386
            ('WorkingTreeFormat2',
358
387
             {'bzrdir_format': formats[0]._matchingbzrdir,
364
393
              'transport_readonly_server': 'b',
365
394
              'transport_server': 'a',
366
395
              'workingtree_format': formats[1]})],
367
 
            scenarios)
368
 
 
369
 
 
370
 
class TestTreeScenarios(TestCase):
371
 
 
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.
 
396
            adapter.scenarios)
 
397
 
 
398
 
 
399
class TestTreeProviderAdapter(TestCase):
 
400
    """Test the setup of tree_implementation tests."""
 
401
 
 
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.
379
409
 
380
410
        from bzrlib.tests.tree_implementations import (
381
 
            _dirstate_tree_from_workingtree,
382
 
            make_scenarios,
383
 
            preview_tree_pre,
384
 
            preview_tree_post,
 
411
            TreeTestProviderAdapter,
385
412
            return_parameter,
386
413
            revision_tree_from_workingtree
387
414
            )
 
415
        input_test = TestTreeProviderAdapter(
 
416
            "test_adapted_tests")
388
417
        server1 = "a"
389
418
        server2 = "b"
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,
404
 
              }),
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,
411
 
             }),
412
 
            ('RevisionTree',
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,
418
 
             }),
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,
425
 
             }),
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,
432
 
             }),
433
 
            ('PreviewTree',
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}),
439
 
            ('PreviewTreePost',
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}),
445
 
             ]
446
 
        self.assertEqual(expected_scenarios, scenarios)
447
 
 
448
 
 
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
 
425
        # abentley 20080412
 
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)
 
447
 
 
448
 
 
449
class TestInterTreeProviderAdapter(TestCase):
450
450
    """A group of tests that test the InterTreeTestAdapter."""
451
451
 
452
 
    def test_scenarios(self):
 
452
    def test_adapted_tests(self):
453
453
        # check that constructor parameters are passed through to the adapted
454
454
        # test.
455
455
        # for InterTree tests we want the machinery to bring up two trees in
464
464
            revision_tree_from_workingtree
465
465
            )
466
466
        from bzrlib.tests.intertree_implementations import (
467
 
            make_scenarios,
 
467
            InterTreeTestProviderAdapter,
468
468
            )
469
469
        from bzrlib.workingtree import WorkingTreeFormat2, WorkingTreeFormat3
470
 
        input_test = TestInterTreeScenarios(
471
 
            "test_scenarios")
 
470
        input_test = TestInterTreeProviderAdapter(
 
471
            "test_adapted_tests")
472
472
        server1 = "a"
473
473
        server2 = "b"
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 = [
481
 
            ("1", {
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,
490
 
                }),
491
 
            ("2", {
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,
500
 
                }),
501
 
            ]
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)
503
496
 
504
497
 
505
498
class TestTestCaseInTempDir(TestCaseInTempDir):
1150
1143
        class SkippedTest(TestCase):
1151
1144
 
1152
1145
            def setUp(self):
1153
 
                TestCase.setUp(self)
1154
1146
                calls.append('setUp')
1155
1147
                self.addCleanup(self.cleanup)
1156
1148
 
1353
1345
class TestTestCase(TestCase):
1354
1346
    """Tests that test the core bzrlib TestCase."""
1355
1347
 
1356
 
    def test_assertLength_matches_empty(self):
1357
 
        a_list = []
1358
 
        self.assertLength(0, a_list)
1359
 
 
1360
 
    def test_assertLength_matches_nonempty(self):
1361
 
        a_list = [1, 2, 3]
1362
 
        self.assertLength(3, a_list)
1363
 
 
1364
 
    def test_assertLength_fails_different(self):
1365
 
        a_list = []
1366
 
        self.assertRaises(AssertionError, self.assertLength, 1, a_list)
1367
 
 
1368
 
    def test_assertLength_shows_sequence_in_failure(self):
1369
 
        a_list = [1, 2, 3]
1370
 
        exception = self.assertRaises(AssertionError, self.assertLength, 2,
1371
 
            a_list)
1372
 
        self.assertEqual('Incorrect length: wanted 2, got 3 for [1, 2, 3]',
1373
 
            exception.args[0])
1374
 
 
1375
 
    def test_base_setUp_not_called_causes_failure(self):
1376
 
        class TestCaseWithBrokenSetUp(TestCase):
1377
 
            def setUp(self):
1378
 
                pass # does not call TestCase.setUp
1379
 
            def test_foo(self):
1380
 
                pass
1381
 
        test = TestCaseWithBrokenSetUp('test_foo')
1382
 
        result = unittest.TestResult()
1383
 
        test.run(result)
1384
 
        self.assertFalse(result.wasSuccessful())
1385
 
        self.assertEqual(1, result.testsRun)
1386
 
 
1387
 
    def test_base_tearDown_not_called_causes_failure(self):
1388
 
        class TestCaseWithBrokenTearDown(TestCase):
1389
 
            def tearDown(self):
1390
 
                pass # does not call TestCase.tearDown
1391
 
            def test_foo(self):
1392
 
                pass
1393
 
        test = TestCaseWithBrokenTearDown('test_foo')
1394
 
        result = unittest.TestResult()
1395
 
        test.run(result)
1396
 
        self.assertFalse(result.wasSuccessful())
1397
 
        self.assertEqual(1, result.testsRun)
1398
 
 
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:
1654
1603
            self.assertListRaises, _TestException, success_generator)
1655
1604
 
1656
1605
 
1657
 
# NB: Don't delete this; it's not actually from 0.11!
1658
 
@deprecated_function(deprecated_in((0, 11, 0)))
 
1606
@symbol_versioning.deprecated_function(zero_eleven)
1659
1607
def sample_deprecated_function():
1660
1608
    """A deprecated function to test applyDeprecated with."""
1661
1609
    return 2
1668
1616
class ApplyDeprecatedHelper(object):
1669
1617
    """A helper class for ApplyDeprecated tests."""
1670
1618
 
1671
 
    @deprecated_method(deprecated_in((0, 11, 0)))
 
1619
    @symbol_versioning.deprecated_method(zero_eleven)
1672
1620
    def sample_deprecated_method(self, param_one):
1673
1621
        """A deprecated method for testing with."""
1674
1622
        return param_one
1676
1624
    def sample_normal_method(self):
1677
1625
        """A undeprecated method."""
1678
1626
 
1679
 
    @deprecated_method(deprecated_in((0, 10, 0)))
 
1627
    @symbol_versioning.deprecated_method(zero_ten)
1680
1628
    def sample_nested_deprecation(self):
1681
1629
        return sample_deprecated_function()
1682
1630
 
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))
1730
1673
 
1731
1674
    def test_callDeprecated(self):
1873
1816
class TestSelftestFiltering(TestCase):
1874
1817
 
1875
1818
    def setUp(self):
1876
 
        TestCase.setUp(self)
1877
1819
        self.suite = TestUtil.TestSuite()
1878
1820
        self.loader = TestUtil.TestLoader()
1879
1821
        self.suite.addTest(self.loader.loadTestsFromModuleNames([