/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Matt Nordhoff
  • Date: 2009-04-04 02:50:01 UTC
  • mfrom: (4253 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4256.
  • Revision ID: mnordhoff@mattnordhoff.com-20090404025001-z1403k0tatmc8l91
Merge bzr.dev, fixing conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
 
    one_zero,
47
 
    zero_eleven,
48
 
    zero_ten,
 
46
    deprecated_function,
 
47
    deprecated_in,
 
48
    deprecated_method,
49
49
    )
50
50
from bzrlib.tests import (
51
51
                          ChrootedTestCase,
129
129
        self.failUnlessExists(filename)
130
130
 
131
131
 
132
 
class TestTransportProviderAdapter(TestCase):
 
132
class TestTransportScenarios(TestCase):
133
133
    """A group of tests that test the transport implementation adaption core.
134
134
 
135
 
    This is a meta test that the tests are applied to all available 
 
135
    This is a meta test that the tests are applied to all available
136
136
    transports.
137
137
 
138
 
    This will be generalised in the future which is why it is in this 
 
138
    This will be generalised in the future which is why it is in this
139
139
    test file even though it is specific to transport tests at the moment.
140
140
    """
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 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()))
154
153
 
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
165
164
        for module in modules:
166
165
            try:
167
 
                permutation_count += len(reduce(getattr, 
 
166
                permutation_count += len(reduce(getattr,
168
167
                    (module + ".get_test_permutations").split('.')[1:],
169
168
                     __import__(module))())
170
169
            except errors.DependencyNotPresent:
171
170
                pass
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))
177
173
 
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
 
        #
 
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
184
177
        # 20060307)
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]
195
188
                                   bzrlib.transport.Server))
196
189
 
197
190
 
198
 
class TestBranchProviderAdapter(TestCase):
199
 
    """A group of tests that test the branch implementation test adapter."""
 
191
class TestBranchScenarios(TestCase):
200
192
 
201
 
    def test_constructor(self):
 
193
    def test_scenarios(self):
202
194
        # check that constructor parameters are passed through to the adapted
203
195
        # test.
204
 
        from bzrlib.tests.branch_implementations import BranchTestProviderAdapter
 
196
        from bzrlib.tests.branch_implementations import make_scenarios
205
197
        server1 = "a"
206
198
        server2 = "b"
207
199
        formats = [("c", "C"), ("d", "D")]
208
 
        adapter = BranchTestProviderAdapter(server1, server2, formats)
209
 
        self.assertEqual(2, len(adapter.scenarios))
 
200
        scenarios = make_scenarios(server1, server2, formats)
 
201
        self.assertEqual(2, len(scenarios))
210
202
        self.assertEqual([
211
203
            ('str',
212
204
             {'branch_format': 'c',
218
210
              'bzrdir_format': 'D',
219
211
              'transport_readonly_server': 'b',
220
212
              'transport_server': 'a'})],
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):
 
213
            scenarios)
 
214
 
 
215
 
 
216
class TestBzrDirScenarios(TestCase):
 
217
 
 
218
    def test_scenarios(self):
228
219
        # check that constructor parameters are passed through to the adapted
229
220
        # test.
230
 
        from bzrlib.tests.bzrdir_implementations import BzrDirTestProviderAdapter
 
221
        from bzrlib.tests.bzrdir_implementations import make_scenarios
231
222
        vfs_factory = "v"
232
223
        server1 = "a"
233
224
        server2 = "b"
234
225
        formats = ["c", "d"]
235
 
        adapter = BzrDirTestProviderAdapter(vfs_factory,
236
 
            server1, server2, formats)
 
226
        scenarios = make_scenarios(vfs_factory, server1, server2, formats)
237
227
        self.assertEqual([
238
228
            ('str',
239
229
             {'bzrdir_format': 'c',
245
235
              'transport_readonly_server': 'b',
246
236
              'transport_server': 'a',
247
237
              'vfs_transport_factory': 'v'})],
248
 
            adapter.scenarios)
249
 
 
250
 
 
251
 
class TestRepositoryParameterisation(TestCase):
252
 
    """A group of tests that test the repository implementation test adapter."""
 
238
            scenarios)
 
239
 
 
240
 
 
241
class TestRepositoryScenarios(TestCase):
253
242
 
254
243
    def test_formats_to_scenarios(self):
255
 
        """The adapter can generate all the scenarios needed."""
256
244
        from bzrlib.tests.per_repository import formats_to_scenarios
257
245
        formats = [("(c)", remote.RemoteRepositoryFormat()),
258
246
                   ("(d)", repository.format_registry.get(
290
278
            vfs_scenarios)
291
279
 
292
280
 
293
 
class TestTestScenarioApplier(TestCase):
 
281
class TestTestScenarioApplication(TestCase):
294
282
    """Tests for the test adaption facilities."""
295
283
 
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()
 
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,
316
289
            ("new id",
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")
325
 
        # the new tests are mutually incompatible, ensuring it has 
 
298
        # the new tests are mutually incompatible, ensuring it has
326
299
        # made new ones, and unspecified elements in the scenario
327
300
        # should not have been altered.
328
301
        self.assertEqual("bzr_format", adapted_test1.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())
342
315
 
343
316
 
344
 
class TestInterRepositoryProviderAdapter(TestCase):
345
 
    """A group of tests that test the InterRepository test adapter."""
 
317
class TestInterRepositoryScenarios(TestCase):
346
318
 
347
 
    def test_adapted_tests(self):
 
319
    def test_scenarios(self):
348
320
        # check that constructor parameters are passed through to the adapted
349
321
        # test.
350
322
        from bzrlib.tests.interrepository_implementations import \
351
 
            InterRepositoryTestProviderAdapter
 
323
            make_scenarios
352
324
        server1 = "a"
353
325
        server2 = "b"
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([
357
329
            ('str,str,str',
358
330
             {'interrepo_class': str,
366
338
              'repository_format_to': 'D2',
367
339
              'transport_readonly_server': 'b',
368
340
              'transport_server': 'a'})],
369
 
            adapter.formats_to_scenarios(formats))
370
 
 
371
 
 
372
 
class TestWorkingTreeProviderAdapter(TestCase):
373
 
    """A group of tests that test the workingtree implementation test adapter."""
 
341
            scenarios)
 
342
 
 
343
 
 
344
class TestWorkingTreeScenarios(TestCase):
374
345
 
375
346
    def test_scenarios(self):
376
347
        # check that constructor parameters are passed through to the adapted
377
348
        # test.
378
349
        from bzrlib.tests.workingtree_implementations \
379
 
            import WorkingTreeTestProviderAdapter
 
350
            import make_scenarios
380
351
        server1 = "a"
381
352
        server2 = "b"
382
353
        formats = [workingtree.WorkingTreeFormat2(),
383
354
                   workingtree.WorkingTreeFormat3(),]
384
 
        adapter = WorkingTreeTestProviderAdapter(server1, server2, formats)
 
355
        scenarios = make_scenarios(server1, server2, formats)
385
356
        self.assertEqual([
386
357
            ('WorkingTreeFormat2',
387
358
             {'bzrdir_format': formats[0]._matchingbzrdir,
393
364
              'transport_readonly_server': 'b',
394
365
              'transport_server': 'a',
395
366
              'workingtree_format': formats[1]})],
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.
 
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.
409
379
 
410
380
        from bzrlib.tests.tree_implementations import (
411
 
            TreeTestProviderAdapter,
 
381
            _dirstate_tree_from_workingtree,
 
382
            make_scenarios,
 
383
            preview_tree_pre,
 
384
            preview_tree_post,
412
385
            return_parameter,
413
386
            revision_tree_from_workingtree
414
387
            )
415
 
        input_test = TestTreeProviderAdapter(
416
 
            "test_adapted_tests")
417
388
        server1 = "a"
418
389
        server2 = "b"
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
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):
 
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):
450
450
    """A group of tests that test the InterTreeTestAdapter."""
451
451
 
452
 
    def test_adapted_tests(self):
 
452
    def test_scenarios(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
 
            InterTreeTestProviderAdapter,
 
467
            make_scenarios,
468
468
            )
469
469
        from bzrlib.workingtree import WorkingTreeFormat2, WorkingTreeFormat3
470
 
        input_test = TestInterTreeProviderAdapter(
471
 
            "test_adapted_tests")
 
470
        input_test = TestInterTreeScenarios(
 
471
            "test_scenarios")
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
 
        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 = [
 
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)
496
503
 
497
504
 
498
505
class TestTestCaseInTempDir(TestCaseInTempDir):
523
530
        """The test_home_dir for TestCaseWithMemoryTransport is missing.
524
531
 
525
532
        This is because TestCaseWithMemoryTransport is for tests that do not
526
 
        need any disk resources: they should be hooked into bzrlib in such a 
527
 
        way that no global settings are being changed by the test (only a 
 
533
        need any disk resources: they should be hooked into bzrlib in such a
 
534
        way that no global settings are being changed by the test (only a
528
535
        few tests should need to do that), and having a missing dir as home is
529
536
        an effective way to ensure that this is the case.
530
537
        """
532
539
            self.TEST_ROOT + "/MemoryTransportMissingHomeDir",
533
540
            self.test_home_dir)
534
541
        self.assertIsSameRealPath(self.test_home_dir, os.environ['HOME'])
535
 
        
 
542
 
536
543
    def test_cwd_is_TEST_ROOT(self):
537
544
        self.assertIsSameRealPath(self.test_dir, self.TEST_ROOT)
538
545
        cwd = osutils.getcwd()
679
686
    def test_make_bzrdir_preserves_transport(self):
680
687
        t = self.get_transport()
681
688
        result_bzrdir = self.make_bzrdir('subdir')
682
 
        self.assertIsInstance(result_bzrdir.transport, 
 
689
        self.assertIsInstance(result_bzrdir.transport,
683
690
                              MemoryTransport)
684
691
        # should not be on disk, should only be in memory
685
692
        self.failIfExists('subdir')
747
754
                time.sleep(0.003)
748
755
        self.check_timing(ShortDelayTestCase('test_short_delay'),
749
756
                          r"^ +[0-9]+ms$")
750
 
        
 
757
 
751
758
    def test_assigned_benchmark_file_stores_date(self):
752
759
        output = StringIO()
753
760
        result = bzrlib.tests.TextTestResult(self._log_file,
780
787
        self.assertContainsRe(lines[1],
781
788
            " *[0-9]+ms bzrlib.tests.test_selftest.TestTestResult"
782
789
            "._time_hello_world_encoding")
783
 
 
 
790
 
784
791
    def _time_hello_world_encoding(self):
785
792
        """Profile two sleep calls
786
 
        
 
793
 
787
794
        This is used to exercise the test framework.
788
795
        """
789
796
        self.time(unicode, 'hello', errors='replace')
807
814
        # execute the test, which should succeed and record profiles
808
815
        example_test_case.run(result)
809
816
        # lsprofile_something()
810
 
        # if this worked we want 
 
817
        # if this worked we want
811
818
        # LSProf output for <built in function unicode> (['hello'], {'errors': 'replace'})
812
819
        #    CallCount    Recursive    Total(ms)   Inline(ms) module:lineno(function)
813
820
        # (the lsprof header)
814
821
        # ... an arbitrary number of lines
815
822
        # and the function call which is time.sleep.
816
 
        #           1        0            ???         ???       ???(sleep) 
 
823
        #           1        0            ???         ???       ???(sleep)
817
824
        # and then repeated but with 'world', rather than 'hello'.
818
825
        # this should appear in the output stream of our test result.
819
826
        output = result_stream.getvalue()
954
961
        output = result_stream.getvalue()[prefix:]
955
962
        lines = output.splitlines()
956
963
        self.assertEqual(lines, ['NODEP                   0ms', "    The feature 'Feature' is not available."])
957
 
    
 
964
 
958
965
    def test_text_report_unsupported(self):
959
966
        # text test output formatting
960
967
        pb = MockProgress()
983
990
            ('update', '[2 in 0s, 2 missing] passing_test', None, None),
984
991
            ],
985
992
            pb.calls[1:])
986
 
    
 
993
 
987
994
    def test_unavailable_exception(self):
988
995
        """An UnavailableFeature being raised should invoke addNotSupported."""
989
996
        class InstrumentedTestResult(ExtendedTestResult):
1012
1019
        result.addNotSupported(test, feature)
1013
1020
        self.assertFalse(result.wasStrictlySuccessful())
1014
1021
        self.assertEqual(None, result._extractBenchmarkTime(test))
1015
 
 
 
1022
 
1016
1023
    def test_strict_with_known_failure(self):
1017
1024
        result = bzrlib.tests.TextTestResult(self._log_file, descriptions=0,
1018
1025
                                             verbosity=1)
1050
1057
 
1051
1058
        This current saves and restores:
1052
1059
        TestCaseInTempDir.TEST_ROOT
1053
 
        
 
1060
 
1054
1061
        There should be no tests in this file that use bzrlib.tests.TextTestRunner
1055
1062
        without using this convenience method, because of our use of global state.
1056
1063
        """
1108
1115
        # run a test that is skipped, and check the suite as a whole still
1109
1116
        # succeeds.
1110
1117
        # skipping_test must be hidden in here so it's not run as a real test
1111
 
        def skipping_test():
1112
 
            raise TestSkipped('test intentionally skipped')
1113
 
 
 
1118
        class SkippingTest(TestCase):
 
1119
            def skipping_test(self):
 
1120
                raise TestSkipped('test intentionally skipped')
1114
1121
        runner = TextTestRunner(stream=self._log_file)
1115
 
        test = unittest.FunctionTestCase(skipping_test)
 
1122
        test = SkippingTest("skipping_test")
1116
1123
        result = self.run_test_runner(runner, test)
1117
1124
        self.assertTrue(result.wasSuccessful())
1118
1125
 
1143
1150
        class SkippedTest(TestCase):
1144
1151
 
1145
1152
            def setUp(self):
 
1153
                TestCase.setUp(self)
1146
1154
                calls.append('setUp')
1147
1155
                self.addCleanup(self.cleanup)
1148
1156
 
1345
1353
class TestTestCase(TestCase):
1346
1354
    """Tests that test the core bzrlib TestCase."""
1347
1355
 
 
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
 
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:
1359
1410
        orig_selftest_flags = tests.selftest_debug_flags
1360
1411
        self.addCleanup(self._restore_selftest_debug_flags, orig_selftest_flags)
1361
1412
        tests.selftest_debug_flags = set(new_flags)
1362
 
        
 
1413
 
1363
1414
    def _restore_selftest_debug_flags(self, flags):
1364
1415
        tests.selftest_debug_flags = flags
1365
1416
 
1412
1463
        # should setup a new log, log content to it, setup a child case (B),
1413
1464
        # which should log independently, then case (A) should log a trailer
1414
1465
        # and return.
1415
 
        # we do two nested children so that we can verify the state of the 
 
1466
        # we do two nested children so that we can verify the state of the
1416
1467
        # logs after the outer child finishes is correct, which a bad clean
1417
1468
        # up routine in tearDown might trigger a fault in our test with only
1418
1469
        # one child, we should instead see the bad result inside our test with
1457
1508
 
1458
1509
    def test__gather_lsprof_in_benchmarks(self):
1459
1510
        """When _gather_lsprof_in_benchmarks is on, accumulate profile data.
1460
 
        
 
1511
 
1461
1512
        Each self.time() call is individually and separately profiled.
1462
1513
        """
1463
1514
        self.requireFeature(test_lsprof.LSProfFeature)
1464
 
        # overrides the class member with an instance member so no cleanup 
 
1515
        # overrides the class member with an instance member so no cleanup
1465
1516
        # needed.
1466
1517
        self._gather_lsprof_in_benchmarks = True
1467
1518
        self.time(time.sleep, 0.000)
1493
1544
    def test_run_no_parameters(self):
1494
1545
        test = SampleTestCase('_test_pass')
1495
1546
        test.run()
1496
 
    
 
1547
 
1497
1548
    def test_run_enabled_unittest_result(self):
1498
1549
        """Test we revert to regular behaviour when the test is enabled."""
1499
1550
        test = SampleTestCase('_test_pass')
1603
1654
            self.assertListRaises, _TestException, success_generator)
1604
1655
 
1605
1656
 
1606
 
@symbol_versioning.deprecated_function(zero_eleven)
 
1657
# NB: Don't delete this; it's not actually from 0.11!
 
1658
@deprecated_function(deprecated_in((0, 11, 0)))
1607
1659
def sample_deprecated_function():
1608
1660
    """A deprecated function to test applyDeprecated with."""
1609
1661
    return 2
1616
1668
class ApplyDeprecatedHelper(object):
1617
1669
    """A helper class for ApplyDeprecated tests."""
1618
1670
 
1619
 
    @symbol_versioning.deprecated_method(zero_eleven)
 
1671
    @deprecated_method(deprecated_in((0, 11, 0)))
1620
1672
    def sample_deprecated_method(self, param_one):
1621
1673
        """A deprecated method for testing with."""
1622
1674
        return param_one
1624
1676
    def sample_normal_method(self):
1625
1677
        """A undeprecated method."""
1626
1678
 
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()
1630
1682
 
1645
1697
    def test_applyDeprecated_not_deprecated(self):
1646
1698
        sample_object = ApplyDeprecatedHelper()
1647
1699
        # calling an undeprecated callable raises an assertion
1648
 
        self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
 
1700
        self.assertRaises(AssertionError, self.applyDeprecated,
 
1701
            deprecated_in((0, 11, 0)),
1649
1702
            sample_object.sample_normal_method)
1650
 
        self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
 
1703
        self.assertRaises(AssertionError, self.applyDeprecated,
 
1704
            deprecated_in((0, 11, 0)),
1651
1705
            sample_undeprecated_function, "a param value")
1652
1706
        # calling a deprecated callable (function or method) with the wrong
1653
1707
        # expected deprecation fails.
1654
 
        self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
 
1708
        self.assertRaises(AssertionError, self.applyDeprecated,
 
1709
            deprecated_in((0, 10, 0)),
1655
1710
            sample_object.sample_deprecated_method, "a param value")
1656
 
        self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
 
1711
        self.assertRaises(AssertionError, self.applyDeprecated,
 
1712
            deprecated_in((0, 10, 0)),
1657
1713
            sample_deprecated_function)
1658
1714
        # calling a deprecated callable (function or method) with the right
1659
1715
        # expected deprecation returns the functions result.
1660
 
        self.assertEqual("a param value", self.applyDeprecated(zero_eleven,
 
1716
        self.assertEqual("a param value",
 
1717
            self.applyDeprecated(deprecated_in((0, 11, 0)),
1661
1718
            sample_object.sample_deprecated_method, "a param value"))
1662
 
        self.assertEqual(2, self.applyDeprecated(zero_eleven,
 
1719
        self.assertEqual(2, self.applyDeprecated(deprecated_in((0, 11, 0)),
1663
1720
            sample_deprecated_function))
1664
1721
        # calling a nested deprecation with the wrong deprecation version
1665
 
        # fails even if a deeper nested function was deprecated with the 
 
1722
        # fails even if a deeper nested function was deprecated with the
1666
1723
        # supplied version.
1667
1724
        self.assertRaises(AssertionError, self.applyDeprecated,
1668
 
            zero_eleven, sample_object.sample_nested_deprecation)
 
1725
            deprecated_in((0, 11, 0)), sample_object.sample_nested_deprecation)
1669
1726
        # calling a nested deprecation with the right deprecation value
1670
1727
        # returns the calls result.
1671
 
        self.assertEqual(2, self.applyDeprecated(zero_ten,
 
1728
        self.assertEqual(2, self.applyDeprecated(deprecated_in((0, 10, 0)),
1672
1729
            sample_object.sample_nested_deprecation))
1673
1730
 
1674
1731
    def test_callDeprecated(self):
1675
1732
        def testfunc(be_deprecated, result=None):
1676
1733
            if be_deprecated is True:
1677
 
                symbol_versioning.warn('i am deprecated', DeprecationWarning, 
 
1734
                symbol_versioning.warn('i am deprecated', DeprecationWarning,
1678
1735
                                       stacklevel=1)
1679
1736
            return result
1680
1737
        result = self.callDeprecated(['i am deprecated'], testfunc, True)
1745
1802
            return TestSuite()
1746
1803
        out = StringIO()
1747
1804
        err = StringIO()
1748
 
        self.apply_redirected(out, err, None, bzrlib.tests.selftest, 
 
1805
        self.apply_redirected(out, err, None, bzrlib.tests.selftest,
1749
1806
            test_suite_factory=factory)
1750
1807
        self.assertEqual([True], factory_called)
1751
1808
 
1816
1873
class TestSelftestFiltering(TestCase):
1817
1874
 
1818
1875
    def setUp(self):
 
1876
        TestCase.setUp(self)
1819
1877
        self.suite = TestUtil.TestSuite()
1820
1878
        self.loader = TestUtil.TestLoader()
1821
1879
        self.suite.addTest(self.loader.loadTestsFromModuleNames([